Comparing version 2.3.0 to 2.3.1
@@ -21,2 +21,6 @@ import { ErrorHandler } from "./ErrorHandler"; | ||
/** | ||
* JSON object with default headers sent by HTTP request. | ||
*/ | ||
getComposedHttpRequestHeaders(): object; | ||
/** | ||
* Process http request with sending body - data. | ||
@@ -61,2 +65,13 @@ * | ||
/** | ||
* Handle http request to return it as Promise. | ||
* | ||
* @param method - Which type of http request will be executed. | ||
* @param path - API URL endpoint. | ||
* @param queryParameters - Querystring parameters used for http request. | ||
* @param body - Data sent with http request. | ||
* | ||
* @returns A promise that will complete when the API responds. | ||
*/ | ||
private promisifiedHttpRequest; | ||
/** | ||
* Process callback function for HTTP request. | ||
@@ -77,20 +92,5 @@ * | ||
private httpRequest; | ||
/** | ||
* Handle http request to return it as Promise. | ||
* | ||
* @param method - Which type of http request will be executed. | ||
* @param path - API URL endpoint. | ||
* @param queryParameters - Querystring parameters used for http request. | ||
* @param body - Data sent with http request. | ||
* | ||
* @returns A promise that will complete when the API responds. | ||
*/ | ||
private promisifiedHttpRequest; | ||
private getRequestTimeoutInSeconds; | ||
private getHttpRequestURL; | ||
/** | ||
* JSON object with default headers sent by HTTP request. | ||
*/ | ||
private getComposedHttpRequestHeaders; | ||
/** | ||
* Token can't be empty. | ||
@@ -97,0 +97,0 @@ * |
@@ -29,2 +29,13 @@ "use strict"; | ||
/** | ||
* JSON object with default headers sent by HTTP request. | ||
*/ | ||
BaseClient.prototype.getComposedHttpRequestHeaders = function () { | ||
var _a; | ||
return _a = {}, | ||
_a[this.authHeader] = this.token, | ||
_a["Accept"] = "application/json", | ||
_a["User-Agent"] = "Postmark.JS - " + this.clientVersion, | ||
_a; | ||
}; | ||
/** | ||
* Process http request with sending body - data. | ||
@@ -90,2 +101,30 @@ * | ||
/** | ||
* Handle http request to return it as Promise. | ||
* | ||
* @param method - Which type of http request will be executed. | ||
* @param path - API URL endpoint. | ||
* @param queryParameters - Querystring parameters used for http request. | ||
* @param body - Data sent with http request. | ||
* | ||
* @returns A promise that will complete when the API responds. | ||
*/ | ||
BaseClient.prototype.promisifiedHttpRequest = function (method, path, queryParameters, body) { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { | ||
_this.httpRequest(method, path, queryParameters, body, function (error, response) { | ||
if (error) { | ||
reject(error); | ||
} | ||
else { | ||
if (response.statusCode !== 200) { | ||
reject(response); | ||
} | ||
else { | ||
resolve(response); | ||
} | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Process callback function for HTTP request. | ||
@@ -124,30 +163,2 @@ * | ||
}; | ||
/** | ||
* Handle http request to return it as Promise. | ||
* | ||
* @param method - Which type of http request will be executed. | ||
* @param path - API URL endpoint. | ||
* @param queryParameters - Querystring parameters used for http request. | ||
* @param body - Data sent with http request. | ||
* | ||
* @returns A promise that will complete when the API responds. | ||
*/ | ||
BaseClient.prototype.promisifiedHttpRequest = function (method, path, queryParameters, body) { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { | ||
_this.httpRequest(method, path, queryParameters, body, function (error, response) { | ||
if (error) { | ||
reject(error); | ||
} | ||
else { | ||
if (response.statusCode !== 200) { | ||
reject(response); | ||
} | ||
else { | ||
resolve(response); | ||
} | ||
} | ||
}); | ||
}); | ||
}; | ||
BaseClient.prototype.getRequestTimeoutInSeconds = function () { | ||
@@ -161,13 +172,2 @@ return (this.clientOptions.timeout || 30) * 1000; | ||
/** | ||
* JSON object with default headers sent by HTTP request. | ||
*/ | ||
BaseClient.prototype.getComposedHttpRequestHeaders = function () { | ||
var _a; | ||
return _a = {}, | ||
_a[this.authHeader] = this.token, | ||
_a["Accept"] = "application/json", | ||
_a["User-Agent"] = "Postmark.JS - " + this.clientVersion, | ||
_a; | ||
}; | ||
/** | ||
* Token can't be empty. | ||
@@ -174,0 +174,0 @@ * |
@@ -20,2 +20,3 @@ export interface Bounce { | ||
Content?: string; | ||
MessageStream: string; | ||
} | ||
@@ -22,0 +23,0 @@ export interface BounceDump { |
@@ -25,1 +25,4 @@ export * from "./client/ClientOptions"; | ||
export * from "./triggers/TriggerFilteringParameters"; | ||
export * from "./webhooks/Webhooks"; | ||
export * from "./webhooks/Webhook"; | ||
export * from "./webhooks/WebhookFilteringParameters"; |
@@ -21,2 +21,4 @@ "use strict"; | ||
__export(require("./triggers/TriggerFilteringParameters")); | ||
__export(require("./webhooks/Webhook")); | ||
__export(require("./webhooks/WebhookFilteringParameters")); | ||
//# sourceMappingURL=index.js.map |
@@ -25,2 +25,3 @@ import { Attachment, Header } from "../message/SupportingTypes"; | ||
Attachments: Attachment[]; | ||
MessageStream: string; | ||
} | ||
@@ -27,0 +28,0 @@ export interface InboundMessageDetails extends InboundMessage { |
@@ -23,2 +23,3 @@ import { Hash } from "../client/SupportingTypes"; | ||
Metadata: Hash<string>; | ||
MessageStream: string; | ||
} | ||
@@ -25,0 +26,0 @@ export interface OutboundMessageDetails extends OutboundMessage { |
@@ -16,2 +16,3 @@ import { LinkClickLocation } from "../message/SupportingTypes"; | ||
Recipient: string; | ||
MessageStream: string; | ||
} | ||
@@ -18,0 +19,0 @@ export interface OutboundMessageClicks { |
@@ -28,2 +28,3 @@ export interface ClientDetails { | ||
Recipient: string; | ||
MessageStream: string; | ||
} | ||
@@ -30,0 +31,0 @@ export interface OutboundMessageOpens { |
import BaseClient from "./BaseClient"; | ||
import { Callback, ClientOptions, DefaultResponse, FilteringParameters, TemplateFilteringParameters } from "./models/index"; | ||
import { Bounce, BounceActivationResponse, BounceCounts, BounceDump, BounceFilteringParameters, Bounces, BrowserUsageCounts, ClickCounts, ClickLocationCounts, ClickPlaformUsageCounts, CreateInboundRuleRequest, CreateTagTriggerRequest, CreateTemplateRequest, DeliveryStatistics, EmailClientUsageCounts, EmailPlaformUsageCounts, EmailReadTimesCounts, InboundMessageDetails, InboundMessages, InboundMessagesFilteringParameters, InboundRule, InboundRules, Message, MessageSendingResponse, OpenCounts, OutboundMessageClicks, OutboundMessageClicksFilteringParameters, OutboundMessageDetails, OutboundMessageDump, OutboundMessageOpens, OutboundMessageOpensFilteringParameters, OutboundMessages, OutboundMessagesFilteringParameters, OutboundStatistics, SentCounts, Server, SpamCounts, StatisticsFilteringParameters, TagTrigger, TagTriggerFilteringParameters, TagTriggers, Template, TemplatedMessage, Templates, TemplateValidation, TemplateValidationOptions, TrackedEmailCounts, UpdateServerRequest, UpdateTagTriggerRequest, UpdateTemplateRequest } from "./models/index"; | ||
import { Callback, ClientOptions, DefaultResponse, FilteringParameters } from "./models/index"; | ||
import { Bounce, BounceActivationResponse, BounceCounts, BounceDump, BounceFilteringParameters, Bounces, BrowserUsageCounts, ClickCounts, ClickLocationCounts, ClickPlaformUsageCounts, CreateInboundRuleRequest, CreateTagTriggerRequest, CreateTemplateRequest, CreateWebhookRequest, DeliveryStatistics, EmailClientUsageCounts, EmailPlaformUsageCounts, EmailReadTimesCounts, InboundMessageDetails, InboundMessages, InboundMessagesFilteringParameters, InboundRule, InboundRules, Message, MessageSendingResponse, OpenCounts, OutboundMessageClicks, OutboundMessageClicksFilteringParameters, OutboundMessageDetails, OutboundMessageDump, OutboundMessageOpens, OutboundMessageOpensFilteringParameters, OutboundMessages, OutboundMessagesFilteringParameters, OutboundStatistics, SentCounts, Server, SpamCounts, StatisticsFilteringParameters, TagTrigger, TagTriggerFilteringParameters, TagTriggers, Template, TemplatedMessage, TemplateFilteringParameters, Templates, TemplateValidation, TemplateValidationOptions, TrackedEmailCounts, UpdateServerRequest, UpdateTagTriggerRequest, UpdateTemplateRequest, UpdateWebhookRequest, Webhook, WebhookFilteringParameters, Webhooks } from "./models/index"; | ||
/** | ||
@@ -414,2 +414,43 @@ * Server client class that can be used to interact with an individual Postmark Server. | ||
getInboundRuleTriggers(filter?: FilteringParameters, callback?: Callback<InboundRules>): Promise<InboundRules>; | ||
/** | ||
* Get the list of Webhooks for specific server. | ||
* | ||
* @param filter - Optional filtering parameters | ||
* @param callback - If the callback is provided, it will be passed to the resulting promise as a continuation. | ||
* @returns A promise that will complete when the API responds (or an error occurs). | ||
*/ | ||
getWebhooks(filter?: WebhookFilteringParameters, callback?: Callback<Webhooks>): Promise<Webhooks>; | ||
/** | ||
* Get details for a specific Webhook. | ||
* | ||
* @param id - The ID of the Webhook you wish to retrieve. | ||
* @param callback - If the callback is provided, it will be passed to the resulting promise as a continuation. | ||
* @returns A promise that will complete when the API responds (or an error occurs). | ||
*/ | ||
getWebhook(id: number, callback?: Callback<Webhook>): Promise<Webhook>; | ||
/** | ||
* Create a Webhook on the associated server. | ||
* | ||
* @param options - Configuration options to be used when creating Webhook trigger. | ||
* @param callback - If the callback is provided, it will be passed to the resulting promise as a continuation. | ||
* @returns A promise that will complete when the API responds (or an error occurs). | ||
*/ | ||
createWebhook(options: CreateWebhookRequest, callback?: Callback<Webhook>): Promise<Webhook>; | ||
/** | ||
* Update Webhook on the associated server. | ||
* | ||
* @param id - Id of the webhook you wish to update. | ||
* @param options - Webhook options you wish to update. | ||
* @param callback If the callback is provided, it will be passed to the resulting promise as a continuation. | ||
* @returns A promise that will complete when the API responds (or an error occurs). | ||
*/ | ||
editWebhook(id: number, options: UpdateWebhookRequest, callback?: Callback<Webhook>): Promise<Webhook>; | ||
/** | ||
* Delete an existing Webhook. | ||
* | ||
* @param id - The ID of the Webhook you wish to delete. | ||
* @param callback - If the callback is provided, it will be passed to the resulting promise as a continuation. | ||
* @returns A promise that will complete when the API responds (or an error occurs). | ||
*/ | ||
deleteWebhook(id: number, callback?: Callback<DefaultResponse>): Promise<DefaultResponse>; | ||
} |
@@ -137,3 +137,3 @@ "use strict"; | ||
ServerClient.prototype.getTemplates = function (filter, callback) { | ||
if (filter === void 0) { filter = new index_1.TemplateFilteringParameters(); } | ||
if (filter === void 0) { filter = new index_2.TemplateFilteringParameters(); } | ||
this.setDefaultPaginationValues(filter); | ||
@@ -563,2 +563,54 @@ return this.processRequestWithoutBody(index_1.ClientOptions.HttpMethod.GET, "/templates", filter, callback); | ||
}; | ||
/** | ||
* Get the list of Webhooks for specific server. | ||
* | ||
* @param filter - Optional filtering parameters | ||
* @param callback - If the callback is provided, it will be passed to the resulting promise as a continuation. | ||
* @returns A promise that will complete when the API responds (or an error occurs). | ||
*/ | ||
ServerClient.prototype.getWebhooks = function (filter, callback) { | ||
if (filter === void 0) { filter = {}; } | ||
return this.processRequestWithoutBody(index_1.ClientOptions.HttpMethod.GET, "/webhooks", filter, callback); | ||
}; | ||
/** | ||
* Get details for a specific Webhook. | ||
* | ||
* @param id - The ID of the Webhook you wish to retrieve. | ||
* @param callback - If the callback is provided, it will be passed to the resulting promise as a continuation. | ||
* @returns A promise that will complete when the API responds (or an error occurs). | ||
*/ | ||
ServerClient.prototype.getWebhook = function (id, callback) { | ||
return this.processRequestWithoutBody(index_1.ClientOptions.HttpMethod.GET, "/webhooks/" + id, {}, callback); | ||
}; | ||
/** | ||
* Create a Webhook on the associated server. | ||
* | ||
* @param options - Configuration options to be used when creating Webhook trigger. | ||
* @param callback - If the callback is provided, it will be passed to the resulting promise as a continuation. | ||
* @returns A promise that will complete when the API responds (or an error occurs). | ||
*/ | ||
ServerClient.prototype.createWebhook = function (options, callback) { | ||
return this.processRequestWithBody(index_1.ClientOptions.HttpMethod.POST, "/webhooks", options, callback); | ||
}; | ||
/** | ||
* Update Webhook on the associated server. | ||
* | ||
* @param id - Id of the webhook you wish to update. | ||
* @param options - Webhook options you wish to update. | ||
* @param callback If the callback is provided, it will be passed to the resulting promise as a continuation. | ||
* @returns A promise that will complete when the API responds (or an error occurs). | ||
*/ | ||
ServerClient.prototype.editWebhook = function (id, options, callback) { | ||
return this.processRequestWithBody(index_1.ClientOptions.HttpMethod.PUT, "/webhooks/" + id, options, callback); | ||
}; | ||
/** | ||
* Delete an existing Webhook. | ||
* | ||
* @param id - The ID of the Webhook you wish to delete. | ||
* @param callback - If the callback is provided, it will be passed to the resulting promise as a continuation. | ||
* @returns A promise that will complete when the API responds (or an error occurs). | ||
*/ | ||
ServerClient.prototype.deleteWebhook = function (id, callback) { | ||
return this.processRequestWithoutBody(index_1.ClientOptions.HttpMethod.DELETE, "/webhooks/" + id, {}, callback); | ||
}; | ||
return ServerClient; | ||
@@ -565,0 +617,0 @@ }(BaseClient_1.default)); |
@@ -12,3 +12,3 @@ { | ||
], | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"author": "Igor Balos", | ||
@@ -45,4 +45,6 @@ "contributors": [ | ||
"test": "node_modules/mocha/bin/mocha --timeout 10000 --retries 1 -r ts-node/register test/**/*test.ts", | ||
"unittest": "node_modules/mocha/bin/mocha --timeout 10000 --retries 1 -r ts-node/register test/unit/**/*test.ts", | ||
"watchtests": "node_modules/.bin/mocha --timeout 10000 --retries 1 -r ts-node/register -R list -w --recursive -G test/**/*test.ts", | ||
"lint": "tslint -c tslint.json 'src/**/*.ts'", | ||
"lintfix": "tslint -c tslint.json 'src/**/*.ts' --fix", | ||
"compile-docs": "echo 'Generating docs...' && mkdir -p ./docs && rm -r ./docs && node_modules/.bin/typedoc --options typedoc.json && git add -A ./docs && echo 'Generated docs!'", | ||
@@ -71,2 +73,3 @@ "pull-docs": "git subtree pull --prefix docs origin gh-pages", | ||
"@types/request": "^2.47.1", | ||
"@types/sinon": "^7.5.0", | ||
"chai": "^4.1.2", | ||
@@ -79,3 +82,4 @@ "mocha": "^5.2.0", | ||
"typedoc": "^0.15.0", | ||
"typescript": "^2.9.2" | ||
"typescript": "^2.9.2", | ||
"sinon": "^7.5.0" | ||
}, | ||
@@ -82,0 +86,0 @@ "dependencies": { |
@@ -6,3 +6,5 @@ import * as postmark from "../../src/index"; | ||
import * as sinon from 'sinon'; | ||
import * as nconf from "nconf"; | ||
import BaseClient from "../../src/client/BaseClient"; | ||
const testingKeys = nconf.env().file({ file: __dirname + "/../../testing_keys.json" }); | ||
@@ -59,4 +61,2 @@ | ||
describe("errors", () => { | ||
const invalidTokenError = "InvalidAPIKeyError"; | ||
it("empty token", () => { | ||
@@ -67,20 +67,37 @@ expect(() => new postmark.AccountClient("")) | ||
it("promise error", () => { | ||
client = new postmark.AccountClient("testToken"); | ||
return client.getSenderSignatures().then((result) => { | ||
throw Error(`Should not be here with result: ${result}`); | ||
}, (error) => { | ||
expect(error.name).to.equal(invalidTokenError); | ||
describe("request errors", () => { | ||
const invalidTokenError = "InvalidAPIKeyError"; | ||
let sandbox: sinon.SinonSandbox; | ||
beforeEach(() => { | ||
sandbox = sinon.createSandbox(); | ||
}); | ||
}); | ||
it("callback error", (done) => { | ||
client = new postmark.AccountClient("testToken"); | ||
client.getSenderSignatures(undefined, (error: any, data) => { | ||
expect(data).to.equal(null); | ||
expect(error.name).to.equal(invalidTokenError); | ||
done(); | ||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
it("promise error", () => { | ||
client = new postmark.AccountClient("testToken"); | ||
sandbox.stub(BaseClient.prototype, <any> "httpRequest").yields(undefined, {statusCode: 401, body: 'response'}); | ||
return client.getSenderSignatures().then((result) => { | ||
throw Error(`Should not be here with result: ${result}`); | ||
}, (error) => { | ||
expect(error.name).to.equal(invalidTokenError); | ||
}); | ||
}); | ||
it("callback error", (done) => { | ||
client = new postmark.AccountClient("testToken"); | ||
sandbox.stub(BaseClient.prototype, <any> "httpRequest").yields(undefined, {statusCode: 401, body: 'response'}); | ||
client.getSenderSignatures(undefined, (error: any, data) => { | ||
expect(data).to.equal(null); | ||
expect(error.name).to.equal(invalidTokenError); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
import * as postmark from "../../src/index"; | ||
import { expect } from "chai"; | ||
import {expect} from "chai"; | ||
import "mocha"; | ||
import * as nconf from "nconf"; | ||
const testingKeys = nconf.env().file({ file: __dirname + "/../../testing_keys.json" }); | ||
const testingKeys = nconf.env().file({file: __dirname + "/../../testing_keys.json"}); | ||
const packageJson = require("../../package.json"); | ||
const clientVersion = packageJson.version; | ||
import * as sinon from 'sinon'; | ||
import BaseClient from "../../src/client/BaseClient"; | ||
@@ -40,2 +42,10 @@ describe("ServerClient", () => { | ||
it("getComposedHttpRequestHeaders", () => { | ||
expect(client.getComposedHttpRequestHeaders()).to.eql({ | ||
"X-Postmark-Server-Token": serverToken, | ||
"Accept": "application/json", | ||
"User-Agent": `Postmark.JS - ${clientVersion}`, | ||
}); | ||
}); | ||
describe("clientOptions", () => { | ||
@@ -92,27 +102,50 @@ it("clientOptions=", () => { | ||
describe("errors", () => { | ||
const invalidTokenError = "InvalidAPIKeyError"; | ||
describe("requests", () => { | ||
let sandbox: sinon.SinonSandbox; | ||
it("empty token", () => { | ||
expect(() => new postmark.ServerClient("")) | ||
.to.throw("A valid API token must be provided."); | ||
beforeEach(() => { | ||
sandbox = sinon.createSandbox(); | ||
}); | ||
it("promise error", () => { | ||
return client.getBounces().then((result) => { | ||
return result; | ||
}, (error) => { | ||
expect(error.name).to.equal(invalidTokenError); | ||
}); | ||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
it("callback error", (done) => { | ||
client = new postmark.ServerClient("testToken"); | ||
client.getBounces(undefined, (error: any, data) => { | ||
expect(data).to.equal(null); | ||
expect(error.name).to.equal(invalidTokenError); | ||
done(); | ||
it('processRequest - without body called', () => { | ||
sandbox.stub(BaseClient.prototype, <any> "processRequest").returns("called") | ||
expect(client.getServer()).to.eq("called") | ||
}); | ||
it('processRequest - with body called', () => { | ||
sandbox.stub(BaseClient.prototype, <any> "processRequest").returns("called"); | ||
expect(client.editServer({Name: 'Test'})).to.eq("called") | ||
}); | ||
describe("callback", () => { | ||
it('process it when there are no errors', async() => { | ||
let callback = sinon.spy(); | ||
sandbox.stub(BaseClient.prototype, <any> "processHttpRequest").returns(new Promise( function(resolve) { resolve("test"); })); | ||
await client.getServer(callback); | ||
expect(callback.calledOnce).to.be.true | ||
}); | ||
it('process regular response based on request status', () => { | ||
sandbox.stub(BaseClient.prototype, <any> "httpRequest").yields(undefined, {statusCode: 200, body: 'response'}); | ||
return client.getServer( (error, result) => { | ||
expect(result).to.eq('response'); | ||
}); | ||
}); | ||
it('process error response based on request status', () => { | ||
sandbox.stub(BaseClient.prototype, <any> "httpRequest").yields(undefined, {statusCode: 201, body: 'response'}); | ||
return client.getServer( (error: any, result) => { | ||
expect(error.name).to.eq('UnknownError'); | ||
}).catch( error => {}); | ||
}); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
269893
134
4784
14