mailgun.js 5.0.3 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/README.md +15 -3
- package/client.d.ts +29 -0
- package/domains.d.ts +54 -0
- package/domainsCredentials.d.ts +14 -0
- package/domainsTags.d.ts +34 -0
- package/domainsTemplates.d.ts +35 -0
- package/error.d.ts +7 -0
- package/events.d.ts +13 -0
- package/index.d.ts +9 -0
- package/interfaces/APIErrorOptions.d.ts +11 -0
- package/{lib/interfaces/ApiResponse.ts → interfaces/ApiResponse.d.ts} +1 -2
- package/{lib/interfaces/DomainCredentials.ts → interfaces/DomainCredentials.d.ts} +14 -30
- package/{lib/interfaces/DomainTags.ts → interfaces/DomainTags.d.ts} +49 -82
- package/{lib/interfaces/DomainTemplates.ts → interfaces/DomainTemplates.d.ts} +35 -79
- package/{lib/interfaces/DomainTracking.ts → interfaces/DomainTracking.d.ts} +18 -17
- package/{lib/interfaces/Domains.ts → interfaces/Domains.d.ts} +29 -50
- package/{lib/interfaces/Events.ts → interfaces/Events.d.ts} +11 -12
- package/{lib/interfaces/IFormData.ts → interfaces/IFormData.d.ts} +2 -4
- package/interfaces/IMailgunClient.d.ts +24 -0
- package/interfaces/IpPools.d.ts +19 -0
- package/interfaces/Ips.d.ts +10 -0
- package/interfaces/Messages.d.ts +165 -0
- package/{lib/interfaces/MultipleValidation.ts → interfaces/MultipleValidation.d.ts} +9 -16
- package/interfaces/Options.d.ts +8 -0
- package/{lib/interfaces/RequestOptions.ts → interfaces/RequestOptions.d.ts} +2 -4
- package/interfaces/StatsOptions.d.ts +22 -0
- package/interfaces/Supressions.d.ts +103 -0
- package/{lib/interfaces/Validate.ts → interfaces/Validate.d.ts} +0 -3
- package/{lib/interfaces/Webhooks.ts → interfaces/Webhooks.d.ts} +11 -17
- package/{lib/interfaces/lists.ts → interfaces/lists.d.ts} +1 -5
- package/{lib/interfaces/mailListMembers.ts → interfaces/mailListMembers.d.ts} +8 -23
- package/{lib/interfaces/routes.ts → interfaces/routes.d.ts} +1 -6
- package/ip-pools.d.ts +21 -0
- package/ips.d.ts +9 -0
- package/lists.d.ts +14 -0
- package/mailListMembers.d.ts +14 -0
- package/mailgun.node.js +3 -0
- package/{dist/mailgun.node.js.LICENSE.txt → mailgun.node.js.LICENSE.txt} +1 -1
- package/mailgun.web.js +3 -0
- package/{dist/mailgun.web.js.LICENSE.txt → mailgun.web.js.LICENSE.txt} +1 -1
- package/messages.d.ts +8 -0
- package/multipleValidation.d.ts +10 -0
- package/package.json +8 -81
- package/request.d.ts +31 -0
- package/routes.d.ts +11 -0
- package/stats.d.ts +20 -0
- package/suppressions.d.ts +50 -0
- package/validate.d.ts +9 -0
- package/version.md +1 -0
- package/webhooks.d.ts +32 -0
- package/.editorconfig +0 -10
- package/.eslintrc +0 -56
- package/.husky/commit-msg +0 -4
- package/.travis.yml +0 -5
- package/LICENSE +0 -191
- package/commitlint.config.js +0 -7
- package/dist/mailgun.js.d.ts +0 -1586
- package/dist/mailgun.node.js +0 -3
- package/dist/mailgun.web.js +0 -3
- package/docs/.nojekyll +0 -1
- package/docs/assets/highlight.css +0 -127
- package/docs/assets/icons.css +0 -1043
- package/docs/assets/icons.png +0 -0
- package/docs/assets/icons@2x.png +0 -0
- package/docs/assets/main.js +0 -52
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1413
- package/docs/assets/widgets.png +0 -0
- package/docs/assets/widgets@2x.png +0 -0
- package/docs/classes/client.default.html +0 -1
- package/docs/classes/domains.Domain.html +0 -1
- package/docs/classes/domains.default.html +0 -1
- package/docs/classes/domainsCredentials.default.html +0 -1
- package/docs/classes/domainsTemplates.DomainTemplateItem.html +0 -1
- package/docs/classes/domainsTemplates.default.html +0 -1
- package/docs/classes/error.default.html +0 -6
- package/docs/classes/events.default.html +0 -1
- package/docs/classes/ip_pools.default.html +0 -1
- package/docs/classes/ips.default.html +0 -1
- package/docs/classes/lists.default.html +0 -1
- package/docs/classes/mailListMembers.default.html +0 -1
- package/docs/classes/messages.default.html +0 -1
- package/docs/classes/multipleValidation.default.html +0 -1
- package/docs/classes/request.default.html +0 -1
- package/docs/classes/routes.default.html +0 -1
- package/docs/classes/stats.default.html +0 -1
- package/docs/classes/suppressions.default.html +0 -1
- package/docs/classes/validate.default.html +0 -1
- package/docs/classes/webhooks.default.html +0 -1
- package/docs/enums/interfaces_DomainTemplates.Pages.html +0 -1
- package/docs/enums/interfaces_DomainTemplates.YesNo.html +0 -1
- package/docs/index.html +0 -1140
- package/docs/interfaces/interfaces_APIErrorOptions.default.html +0 -1
- package/docs/interfaces/interfaces_ApiResponse.default.html +0 -1
- package/docs/interfaces/interfaces_DomainCredentials.CreatedUpdatedDomainCredentialsResponse.html +0 -1
- package/docs/interfaces/interfaces_DomainCredentials.DeletedDomainCredentialsResponse.html +0 -1
- package/docs/interfaces/interfaces_DomainCredentials.DomainCredentials.html +0 -1
- package/docs/interfaces/interfaces_DomainCredentials.DomainCredentialsItem.html +0 -1
- package/docs/interfaces/interfaces_DomainCredentials.DomainCredentialsList.html +0 -1
- package/docs/interfaces/interfaces_DomainCredentials.DomainCredentialsQuery.html +0 -1
- package/docs/interfaces/interfaces_DomainCredentials.DomainCredentialsResponseData.html +0 -1
- package/docs/interfaces/interfaces_DomainCredentials.DomainCredentialsResult.html +0 -1
- package/docs/interfaces/interfaces_DomainCredentials.IDomainCredentials.html +0 -1
- package/docs/interfaces/interfaces_DomainCredentials.UpdateDomainCredentialsData.html +0 -1
- package/docs/interfaces/interfaces_DomainTemplates.CreateDomainTemplateAPIResponse.html +0 -1
- package/docs/interfaces/interfaces_DomainTemplates.CreateDomainTemplateVersionAPIResponse.html +0 -1
- package/docs/interfaces/interfaces_DomainTemplates.CreateDomainTemplateVersionResult.html +0 -1
- package/docs/interfaces/interfaces_DomainTemplates.DomainTemplate.html +0 -1
- package/docs/interfaces/interfaces_DomainTemplates.DomainTemplateData.html +0 -1
- package/docs/interfaces/interfaces_DomainTemplates.DomainTemplateUpdateData.html +0 -1
- package/docs/interfaces/interfaces_DomainTemplates.DomainTemplateUpdateVersionData.html +0 -1
- package/docs/interfaces/interfaces_DomainTemplates.DomainTemplateVersionData.html +0 -1
- package/docs/interfaces/interfaces_DomainTemplates.DomainTemplatesQuery.html +0 -1
- package/docs/interfaces/interfaces_DomainTemplates.GetDomainTemplateAPIResponse.html +0 -1
- package/docs/interfaces/interfaces_DomainTemplates.IDomainTemplatesClient.html +0 -1
- package/docs/interfaces/interfaces_DomainTemplates.ListDomainTemplateVersionsAPIResponse.html +0 -1
- package/docs/interfaces/interfaces_DomainTemplates.ListDomainTemplateVersionsResult.html +0 -1
- package/docs/interfaces/interfaces_DomainTemplates.ListDomainTemplatesAPIResponse.html +0 -1
- package/docs/interfaces/interfaces_DomainTemplates.ListDomainTemplatesResult.html +0 -1
- package/docs/interfaces/interfaces_DomainTemplates.MutateDomainTemplateVersionAPIResponse.html +0 -1
- package/docs/interfaces/interfaces_DomainTemplates.MutateDomainTemplateVersionResult.html +0 -1
- package/docs/interfaces/interfaces_DomainTemplates.NotificationAPIResponse.html +0 -1
- package/docs/interfaces/interfaces_DomainTemplates.NotificationResult.html +0 -1
- package/docs/interfaces/interfaces_DomainTemplates.ShortTemplateVersion.html +0 -1
- package/docs/interfaces/interfaces_DomainTemplates.TemplateQuery.html +0 -1
- package/docs/interfaces/interfaces_DomainTemplates.TemplateVersion.html +0 -1
- package/docs/interfaces/interfaces_DomainTemplates.UpdateOrDeleteDomainTemplateAPIResponse.html +0 -1
- package/docs/interfaces/interfaces_DomainTemplates.UpdateOrDeleteDomainTemplateResult.html +0 -1
- package/docs/interfaces/interfaces_DomainTracking.ClickTrackingInfo.html +0 -1
- package/docs/interfaces/interfaces_DomainTracking.DomainTrackingData.html +0 -1
- package/docs/interfaces/interfaces_DomainTracking.DomainTrackingResponse.html +0 -1
- package/docs/interfaces/interfaces_DomainTracking.OpenTrackingInfo.html +0 -1
- package/docs/interfaces/interfaces_DomainTracking.UnsubscribeTrackingInfo.html +0 -1
- package/docs/interfaces/interfaces_DomainTracking.UpdateDomainTrackingResponse.html +0 -1
- package/docs/interfaces/interfaces_DomainTracking.UpdatedOpenTracking.html +0 -1
- package/docs/interfaces/interfaces_Domains.ConnectionSettings.html +0 -1
- package/docs/interfaces/interfaces_Domains.ConnectionSettingsResponse.html +0 -1
- package/docs/interfaces/interfaces_Domains.DKIMAuthorityInfo.html +0 -1
- package/docs/interfaces/interfaces_Domains.DKIMSelectorInfo.html +0 -1
- package/docs/interfaces/interfaces_Domains.DNSRecord.html +0 -1
- package/docs/interfaces/interfaces_Domains.DestroyedDomainResponse.html +0 -1
- package/docs/interfaces/interfaces_Domains.DomainData.html +0 -1
- package/docs/interfaces/interfaces_Domains.DomainInfo.html +0 -1
- package/docs/interfaces/interfaces_Domains.DomainListResponseData.html +0 -1
- package/docs/interfaces/interfaces_Domains.DomainResponseData.html +0 -1
- package/docs/interfaces/interfaces_Domains.DomainShortData.html +0 -1
- package/docs/interfaces/interfaces_Domains.DomainsListItem.html +0 -1
- package/docs/interfaces/interfaces_Domains.DomainsQuery.html +0 -1
- package/docs/interfaces/interfaces_Domains.MessageResponse.html +0 -1
- package/docs/interfaces/interfaces_Domains.ReplacementForPool.html +0 -1
- package/docs/interfaces/interfaces_Domains.UpdatedConnectionSettings.html +0 -1
- package/docs/interfaces/interfaces_Domains.UpdatedConnectionSettingsRes.html +0 -1
- package/docs/interfaces/interfaces_Domains.UpdatedDKIMAuthority.html +0 -1
- package/docs/interfaces/interfaces_Domains.UpdatedDKIMAuthorityResponse.html +0 -1
- package/docs/interfaces/interfaces_Domains.UpdatedDKIMSelectorResponse.html +0 -1
- package/docs/interfaces/interfaces_Domains.UpdatedWebPrefix.html +0 -1
- package/docs/interfaces/interfaces_Domains.UpdatedWebPrefixResponse.html +0 -1
- package/docs/interfaces/interfaces_Domains.WebPrefixInfo.html +0 -1
- package/docs/interfaces/interfaces_Events.DomainEvent.html +0 -1
- package/docs/interfaces/interfaces_Events.EventsList.html +0 -1
- package/docs/interfaces/interfaces_Events.EventsPage.html +0 -1
- package/docs/interfaces/interfaces_Events.EventsResponse.html +0 -1
- package/docs/interfaces/interfaces_Events.PagesList.html +0 -1
- package/docs/interfaces/interfaces_Events.PagesListAccumulator.html +0 -1
- package/docs/interfaces/interfaces_Events.ParsedPage.html +0 -1
- package/docs/interfaces/interfaces_Events.ParsedPagesList.html +0 -1
- package/docs/interfaces/interfaces_IFormData.IFormDataOptions.html +0 -1
- package/docs/interfaces/interfaces_IFormData.InputFormData.html +0 -1
- package/docs/interfaces/interfaces_IpPools.IpPool.html +0 -1
- package/docs/interfaces/interfaces_IpPools.IpPoolListResponse.html +0 -1
- package/docs/interfaces/interfaces_IpPools.IpPoolUpdateData.html +0 -1
- package/docs/interfaces/interfaces_Ips.IpData.html +0 -1
- package/docs/interfaces/interfaces_Ips.IpsListResponseBody.html +0 -1
- package/docs/interfaces/interfaces_MultipleValidation.CanceledMultipleValidationJob.html +0 -1
- package/docs/interfaces/interfaces_MultipleValidation.CreatedMultipleValidationJob.html +0 -1
- package/docs/interfaces/interfaces_MultipleValidation.IMultipleValidationClient.html +0 -1
- package/docs/interfaces/interfaces_MultipleValidation.MultipleValidationJob.html +0 -1
- package/docs/interfaces/interfaces_MultipleValidation.MultipleValidationJobsListResponse.html +0 -1
- package/docs/interfaces/interfaces_MultipleValidation.MultipleValidationJobsListResult.html +0 -1
- package/docs/interfaces/interfaces_MultipleValidation.PagesList.html +0 -1
- package/docs/interfaces/interfaces_Options.default.html +0 -1
- package/docs/interfaces/interfaces_RequestOptions.default.html +0 -1
- package/docs/interfaces/interfaces_StatsOptions.Stat.html +0 -1
- package/docs/interfaces/interfaces_StatsOptions.StatsOptions.html +0 -1
- package/docs/interfaces/interfaces_StatsOptions.StatsQuery.html +0 -1
- package/docs/interfaces/interfaces_Supressions.BounceData.html +0 -1
- package/docs/interfaces/interfaces_Supressions.ComplaintData.html +0 -1
- package/docs/interfaces/interfaces_Supressions.UnsubscribeData.html +0 -1
- package/docs/interfaces/interfaces_Supressions.WhiteListData.html +0 -1
- package/docs/interfaces/interfaces_Validate.ValidationResponse.html +0 -1
- package/docs/interfaces/interfaces_Validate.ValidationResult.html +0 -1
- package/docs/interfaces/interfaces_Webhooks.APIWebhook.html +0 -1
- package/docs/interfaces/interfaces_Webhooks.ValidationResponse.html +0 -1
- package/docs/interfaces/interfaces_Webhooks.WebhookList.html +0 -1
- package/docs/interfaces/interfaces_Webhooks.WebhookResponse.html +0 -1
- package/docs/interfaces/interfaces_Webhooks.WebhookResponseBody.html +0 -1
- package/docs/interfaces/interfaces_Webhooks.WebhooksQuery.html +0 -1
- package/docs/interfaces/interfaces_lists.CreateUpdateList.html +0 -1
- package/docs/interfaces/interfaces_lists.DestroyedList.html +0 -1
- package/docs/interfaces/interfaces_lists.ListsQuery.html +0 -1
- package/docs/interfaces/interfaces_lists.MailingList.html +0 -1
- package/docs/interfaces/interfaces_mailListMembers.CreateUpdateMailListMembers.html +0 -1
- package/docs/interfaces/interfaces_mailListMembers.CreateUpdateMailListMembersReq.html +0 -1
- package/docs/interfaces/interfaces_mailListMembers.DeletedMember.html +0 -1
- package/docs/interfaces/interfaces_mailListMembers.IMailListsMembers.html +0 -1
- package/docs/interfaces/interfaces_mailListMembers.MailListMember.html +0 -1
- package/docs/interfaces/interfaces_mailListMembers.MailListMembersQuery.html +0 -1
- package/docs/interfaces/interfaces_mailListMembers.MultipleMembersData.html +0 -1
- package/docs/interfaces/interfaces_mailListMembers.MultipleMembersReqData.html +0 -1
- package/docs/interfaces/interfaces_mailListMembers.NewMultipleMembersResponse.html +0 -1
- package/docs/interfaces/interfaces_routes.CreateUpdateRouteData.html +0 -1
- package/docs/interfaces/interfaces_routes.DestroyRouteResponse.html +0 -1
- package/docs/interfaces/interfaces_routes.Route.html +0 -1
- package/docs/interfaces/interfaces_routes.RoutesListQuery.html +0 -1
- package/docs/interfaces/interfaces_routes.UpdateRouteResponse.html +0 -1
- package/docs/modules/client.html +0 -1
- package/docs/modules/domains.html +0 -1
- package/docs/modules/domainsCredentials.html +0 -1
- package/docs/modules/domainsTemplates.html +0 -1
- package/docs/modules/error.html +0 -1
- package/docs/modules/events.html +0 -1
- package/docs/modules/interfaces_APIErrorOptions.html +0 -1
- package/docs/modules/interfaces_ApiResponse.html +0 -1
- package/docs/modules/interfaces_DomainCredentials.html +0 -1
- package/docs/modules/interfaces_DomainTemplates.html +0 -1
- package/docs/modules/interfaces_DomainTracking.html +0 -1
- package/docs/modules/interfaces_Domains.html +0 -1
- package/docs/modules/interfaces_Events.html +0 -1
- package/docs/modules/interfaces_IFormData.html +0 -1
- package/docs/modules/interfaces_IpPools.html +0 -1
- package/docs/modules/interfaces_Ips.html +0 -1
- package/docs/modules/interfaces_MultipleValidation.html +0 -1
- package/docs/modules/interfaces_Options.html +0 -1
- package/docs/modules/interfaces_RequestOptions.html +0 -1
- package/docs/modules/interfaces_StatsOptions.html +0 -1
- package/docs/modules/interfaces_Supressions.html +0 -1
- package/docs/modules/interfaces_Validate.html +0 -1
- package/docs/modules/interfaces_Webhooks.html +0 -1
- package/docs/modules/interfaces_lists.html +0 -1
- package/docs/modules/interfaces_mailListMembers.html +0 -1
- package/docs/modules/interfaces_routes.html +0 -1
- package/docs/modules/ip_pools.html +0 -1
- package/docs/modules/ips.html +0 -1
- package/docs/modules/lists.html +0 -1
- package/docs/modules/mailListMembers.html +0 -1
- package/docs/modules/messages.html +0 -1
- package/docs/modules/multipleValidation.html +0 -1
- package/docs/modules/request.html +0 -1
- package/docs/modules/routes.html +0 -1
- package/docs/modules/stats.html +0 -1
- package/docs/modules/suppressions.html +0 -1
- package/docs/modules/validate.html +0 -1
- package/docs/modules/webhooks.html +0 -1
- package/docs/modules.html +0 -1
- package/dts-bundle.js +0 -8
- package/examples/addresses.js +0 -20
- package/examples/index.html +0 -285
- package/examples/list-domains.js +0 -8
- package/examples/mailgun.png +0 -0
- package/examples/rackspace.png +0 -0
- package/examples/send-email.js +0 -24
- package/lib/client.ts +0 -79
- package/lib/domains.ts +0 -224
- package/lib/domainsCredentials.ts +0 -88
- package/lib/domainsTags.ts +0 -165
- package/lib/domainsTemplates.ts +0 -235
- package/lib/error.ts +0 -22
- package/lib/events.ts +0 -54
- package/lib/index.ts +0 -16
- package/lib/interfaces/APIErrorOptions.ts +0 -10
- package/lib/interfaces/IpPools.ts +0 -22
- package/lib/interfaces/Ips.ts +0 -12
- package/lib/interfaces/Options.ts +0 -10
- package/lib/interfaces/StatsOptions.ts +0 -25
- package/lib/interfaces/Supressions.ts +0 -123
- package/lib/ip-pools.ts +0 -36
- package/lib/ips.ts +0 -24
- package/lib/lists.ts +0 -45
- package/lib/mailListMembers.ts +0 -83
- package/lib/messages.ts +0 -27
- package/lib/multipleValidation.ts +0 -37
- package/lib/request.ts +0 -271
- package/lib/routes.ts +0 -37
- package/lib/stats.ts +0 -62
- package/lib/suppressions.ts +0 -253
- package/lib/validate.ts +0 -20
- package/lib/webhooks.ts +0 -83
- package/test/client.test.ts +0 -96
- package/test/data/emailsValidation1.csv +0 -3
- package/test/domains.test.ts +0 -313
- package/test/domainsCredentials.test.ts +0 -97
- package/test/domainsTags.test.ts +0 -345
- package/test/domainsTemplates.test.ts +0 -392
- package/test/error.test.ts +0 -32
- package/test/events.test.ts +0 -104
- package/test/img/mailgun.png +0 -0
- package/test/ips.test.ts +0 -57
- package/test/lists.test.ts +0 -100
- package/test/mailListMembers.test.ts +0 -198
- package/test/messageAttachment.test.ts +0 -50
- package/test/messages.test.ts +0 -89
- package/test/multipleValidation.test.ts +0 -159
- package/test/request.test.ts +0 -103
- package/test/routes.test.ts +0 -136
- package/test/stats.test.ts +0 -90
- package/test/suppressions.test.ts +0 -303
- package/test/validate.test.ts +0 -43
- package/test/webhooks.test.ts +0 -112
- package/tsconfig.json +0 -22
- package/tsconfig.webpack.json +0 -10
- package/webpack/webpack.common.config.js +0 -46
- package/webpack/webpack.dev.config.js +0 -36
- package/webpack/webpack.release.config.js +0 -45
package/lib/stats.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import urljoin from 'url-join';
|
|
2
|
-
import Request from './request';
|
|
3
|
-
import { StatsQuery, StatsOptions, Stat } from './interfaces/StatsOptions';
|
|
4
|
-
|
|
5
|
-
class Stats {
|
|
6
|
-
start: Date;
|
|
7
|
-
end: Date;
|
|
8
|
-
resolution: string;
|
|
9
|
-
stats: Stat[];
|
|
10
|
-
|
|
11
|
-
constructor(data: StatsOptions) {
|
|
12
|
-
this.start = new Date(data.start);
|
|
13
|
-
this.end = new Date(data.end);
|
|
14
|
-
this.resolution = data.resolution;
|
|
15
|
-
this.stats = data.stats.map(function (stat: Stat) {
|
|
16
|
-
const res = { ...stat };
|
|
17
|
-
res.time = new Date(stat.time);
|
|
18
|
-
return res;
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export default class StatsClient {
|
|
24
|
-
request: Request;
|
|
25
|
-
|
|
26
|
-
constructor(request: Request) {
|
|
27
|
-
this.request = request;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
private prepareSearchParams(query: StatsQuery | undefined): Array<Array<string>> {
|
|
31
|
-
let searchParams = [] as Array<Array<string>>;
|
|
32
|
-
if (typeof query === 'object' && Object.keys(query).length) {
|
|
33
|
-
searchParams = Object.entries(query).reduce((arrayWithPairs, currentPair) => {
|
|
34
|
-
const [key, value] = currentPair;
|
|
35
|
-
if (Array.isArray(value) && value.length) {
|
|
36
|
-
const repeatedProperty = value.map((item) => [key, item]);
|
|
37
|
-
return [...arrayWithPairs, ...repeatedProperty];
|
|
38
|
-
}
|
|
39
|
-
arrayWithPairs.push([key, value]);
|
|
40
|
-
return arrayWithPairs;
|
|
41
|
-
}, [] as Array<Array<string>>);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return searchParams;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
_parseStats(response: { body: StatsOptions }): Stats {
|
|
48
|
-
return new Stats(response.body);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
getDomain(domain: string, query?: StatsQuery): Promise<Stats> {
|
|
52
|
-
const searchParams = this.prepareSearchParams(query);
|
|
53
|
-
return this.request.get(urljoin('/v3', domain, 'stats/total'), searchParams)
|
|
54
|
-
.then(this._parseStats);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
getAccount(query?: StatsQuery): Promise<Stats> {
|
|
58
|
-
const searchParams = this.prepareSearchParams(query);
|
|
59
|
-
return this.request.get('/v3/stats/total', searchParams)
|
|
60
|
-
.then(this._parseStats);
|
|
61
|
-
}
|
|
62
|
-
}
|
package/lib/suppressions.ts
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
/* eslint-disable camelcase */
|
|
2
|
-
import urljoin from 'url-join';
|
|
3
|
-
|
|
4
|
-
import Request from './request';
|
|
5
|
-
import {
|
|
6
|
-
BounceData,
|
|
7
|
-
ComplaintData,
|
|
8
|
-
PagesList,
|
|
9
|
-
PagesListAccumulator,
|
|
10
|
-
ParsedPage,
|
|
11
|
-
ParsedPagesList,
|
|
12
|
-
SuppressionCreationData,
|
|
13
|
-
SuppressionCreationResponse,
|
|
14
|
-
SuppressionCreationResult,
|
|
15
|
-
SuppressionDestroyResponse,
|
|
16
|
-
SuppressionDestroyResult,
|
|
17
|
-
SuppressionList,
|
|
18
|
-
SuppressionListQuery,
|
|
19
|
-
SuppressionListResponse,
|
|
20
|
-
SuppressionModels,
|
|
21
|
-
SuppressionResponse,
|
|
22
|
-
UnsubscribeData,
|
|
23
|
-
WhiteListData,
|
|
24
|
-
} from './interfaces/Supressions';
|
|
25
|
-
import APIError from './error';
|
|
26
|
-
import APIErrorOptions from './interfaces/APIErrorOptions';
|
|
27
|
-
|
|
28
|
-
const createOptions = {
|
|
29
|
-
headers: { 'Content-Type': 'application/json' }
|
|
30
|
-
};
|
|
31
|
-
export class Suppression {
|
|
32
|
-
type: string;
|
|
33
|
-
constructor(type: SuppressionModels) {
|
|
34
|
-
this.type = type;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
export class Bounce extends Suppression {
|
|
38
|
-
address: string;
|
|
39
|
-
code: number;
|
|
40
|
-
error: string;
|
|
41
|
-
created_at: Date;
|
|
42
|
-
|
|
43
|
-
constructor(data: BounceData) {
|
|
44
|
-
super(SuppressionModels.BOUNCES);
|
|
45
|
-
this.address = data.address;
|
|
46
|
-
this.code = +data.code;
|
|
47
|
-
this.error = data.error;
|
|
48
|
-
this.created_at = new Date(data.created_at);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export class Complaint extends Suppression {
|
|
53
|
-
address: string | undefined;
|
|
54
|
-
created_at: Date;
|
|
55
|
-
|
|
56
|
-
constructor(data: ComplaintData) {
|
|
57
|
-
super(SuppressionModels.COMPLAINTS);
|
|
58
|
-
this.address = data.address;
|
|
59
|
-
this.created_at = new Date(data.created_at);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export class Unsubscribe extends Suppression {
|
|
64
|
-
address: string;
|
|
65
|
-
tags: string[];
|
|
66
|
-
created_at: Date;
|
|
67
|
-
|
|
68
|
-
constructor(data: UnsubscribeData) {
|
|
69
|
-
super(SuppressionModels.UNSUBSCRIBES);
|
|
70
|
-
this.address = data.address;
|
|
71
|
-
this.tags = data.tags;
|
|
72
|
-
this.created_at = new Date(data.created_at);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export class WhiteList extends Suppression {
|
|
77
|
-
value: string;
|
|
78
|
-
reason: string;
|
|
79
|
-
createdAt: Date;
|
|
80
|
-
|
|
81
|
-
constructor(data: WhiteListData) {
|
|
82
|
-
super(SuppressionModels.WHITELISTS);
|
|
83
|
-
this.value = data.value;
|
|
84
|
-
this.reason = data.reason;
|
|
85
|
-
this.createdAt = new Date(data.createdAt);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export default class SuppressionClient {
|
|
90
|
-
request: Request;
|
|
91
|
-
models: Map<string, any>;
|
|
92
|
-
|
|
93
|
-
constructor(request: Request) {
|
|
94
|
-
this.request = request;
|
|
95
|
-
this.models = new Map();
|
|
96
|
-
this.models.set('bounces', Bounce);
|
|
97
|
-
this.models.set('complaints', Complaint);
|
|
98
|
-
this.models.set('unsubscribes', Unsubscribe);
|
|
99
|
-
this.models.set('whitelists', WhiteList);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
_parsePage(id: string, pageUrl: string) : ParsedPage {
|
|
103
|
-
const parsedUrl = new URL(pageUrl);
|
|
104
|
-
const { searchParams } = parsedUrl;
|
|
105
|
-
return {
|
|
106
|
-
id,
|
|
107
|
-
page: searchParams.has('page') ? searchParams.get('page') : undefined,
|
|
108
|
-
address: searchParams.has('address') ? searchParams.get('address') : undefined,
|
|
109
|
-
url: pageUrl
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
_parsePageLinks(response: SuppressionListResponse): ParsedPagesList {
|
|
114
|
-
const pages = Object.entries(response.body.paging as PagesList);
|
|
115
|
-
return pages.reduce(
|
|
116
|
-
(acc: PagesListAccumulator, pair: [pageUrl: string, id: string]) => {
|
|
117
|
-
const id = pair[0];
|
|
118
|
-
const pageUrl = pair[1];
|
|
119
|
-
acc[id] = this._parsePage(id, pageUrl);
|
|
120
|
-
return acc;
|
|
121
|
-
}, {}
|
|
122
|
-
) as unknown as ParsedPagesList;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
_parseList(
|
|
126
|
-
response: SuppressionListResponse,
|
|
127
|
-
Model: {
|
|
128
|
-
new(data: BounceData | ComplaintData | UnsubscribeData | WhiteListData):
|
|
129
|
-
Bounce | Complaint | Unsubscribe | WhiteList
|
|
130
|
-
}
|
|
131
|
-
): SuppressionList {
|
|
132
|
-
const data = {} as SuppressionList;
|
|
133
|
-
data.items = response.body.items.map((item) => new Model(item));
|
|
134
|
-
|
|
135
|
-
data.pages = this._parsePageLinks(response);
|
|
136
|
-
|
|
137
|
-
return data;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
_parseItem<T extends Suppression>(
|
|
141
|
-
data : BounceData | ComplaintData | UnsubscribeData | WhiteListData,
|
|
142
|
-
Model: {
|
|
143
|
-
new(data: BounceData | ComplaintData | UnsubscribeData | WhiteListData):
|
|
144
|
-
T
|
|
145
|
-
}
|
|
146
|
-
): T {
|
|
147
|
-
return new Model(data);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
private createWhiteList(
|
|
151
|
-
domain: string,
|
|
152
|
-
data: SuppressionCreationData | SuppressionCreationData[]
|
|
153
|
-
): Promise<SuppressionCreationResult> {
|
|
154
|
-
if (Array.isArray(data)) {
|
|
155
|
-
throw new APIError({
|
|
156
|
-
status: 400,
|
|
157
|
-
statusText: 'Data property should be an object',
|
|
158
|
-
body: {
|
|
159
|
-
message: 'Whitelist\'s creation process does not support multiple creations. Data property should be an object'
|
|
160
|
-
}
|
|
161
|
-
} as APIErrorOptions);
|
|
162
|
-
}
|
|
163
|
-
return this.request
|
|
164
|
-
.postWithFD(urljoin('v3', domain, 'whitelists'), data)
|
|
165
|
-
.then(this.prepareResponse);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
private checkType(type: string) {
|
|
169
|
-
if (!this.models.has(type)) {
|
|
170
|
-
throw new APIError({
|
|
171
|
-
status: 400,
|
|
172
|
-
statusText: 'Unknown type value',
|
|
173
|
-
body: { message: 'Type may be only one of [bounces, complaints, unsubscribes, whitelists]' }
|
|
174
|
-
} as APIErrorOptions);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
private prepareResponse(response: SuppressionCreationResponse): SuppressionCreationResult {
|
|
179
|
-
return {
|
|
180
|
-
message: response.body.message,
|
|
181
|
-
type: response.body.type || '',
|
|
182
|
-
value: response.body.value || '',
|
|
183
|
-
status: response.status
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
list(
|
|
188
|
-
domain: string,
|
|
189
|
-
type: string,
|
|
190
|
-
query?: SuppressionListQuery
|
|
191
|
-
): Promise<SuppressionList> {
|
|
192
|
-
this.checkType(type);
|
|
193
|
-
|
|
194
|
-
const model = this.models.get(type);
|
|
195
|
-
return this.request
|
|
196
|
-
.get(urljoin('v3', domain, type), query)
|
|
197
|
-
.then((response: SuppressionListResponse) => this._parseList(response, model));
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
get(
|
|
201
|
-
domain: string,
|
|
202
|
-
type: string,
|
|
203
|
-
address: string
|
|
204
|
-
): Promise<Bounce | Complaint | Unsubscribe | WhiteList> {
|
|
205
|
-
this.checkType(type);
|
|
206
|
-
|
|
207
|
-
const model = this.models.get(type);
|
|
208
|
-
return this.request
|
|
209
|
-
.get(urljoin('v3', domain, type, encodeURIComponent(address)))
|
|
210
|
-
.then((response: SuppressionResponse) => this._parseItem<typeof model>(response.body, model));
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
create(
|
|
214
|
-
domain: string,
|
|
215
|
-
type: string,
|
|
216
|
-
data: SuppressionCreationData | SuppressionCreationData[]
|
|
217
|
-
): Promise<SuppressionCreationResult> {
|
|
218
|
-
this.checkType(type);
|
|
219
|
-
// supports adding multiple suppressions by default
|
|
220
|
-
let postData;
|
|
221
|
-
if (type === 'whitelists') {
|
|
222
|
-
return this.createWhiteList(domain, data);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if (!Array.isArray(data)) {
|
|
226
|
-
postData = [data];
|
|
227
|
-
} else {
|
|
228
|
-
postData = [...data];
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
return this.request
|
|
232
|
-
.post(urljoin('v3', domain, type), JSON.stringify(postData), createOptions)
|
|
233
|
-
.then(this.prepareResponse);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
destroy(
|
|
237
|
-
domain: string,
|
|
238
|
-
type: string,
|
|
239
|
-
address: string
|
|
240
|
-
): Promise<SuppressionDestroyResult> {
|
|
241
|
-
this.checkType(type);
|
|
242
|
-
return this.request
|
|
243
|
-
.delete(urljoin('v3', domain, type, encodeURIComponent(address)))
|
|
244
|
-
.then((response: SuppressionDestroyResponse) => ({
|
|
245
|
-
message: response.body.message,
|
|
246
|
-
value: response.body.value || '',
|
|
247
|
-
address: response.body.address || '',
|
|
248
|
-
status: response.status
|
|
249
|
-
}));
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
module.exports = SuppressionClient;
|
package/lib/validate.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import APIResponse from './interfaces/ApiResponse';
|
|
2
|
-
import { IMultipleValidationClient } from './interfaces/MultipleValidation';
|
|
3
|
-
import { ValidationResult, ValidationResponse } from './interfaces/Validate';
|
|
4
|
-
import Request from './request';
|
|
5
|
-
|
|
6
|
-
export default class ValidateClient {
|
|
7
|
-
public multipleValidation;
|
|
8
|
-
request: Request;
|
|
9
|
-
|
|
10
|
-
constructor(request: Request, multipleValidationClient: IMultipleValidationClient) {
|
|
11
|
-
this.request = request;
|
|
12
|
-
this.multipleValidation = multipleValidationClient;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
get(address: string): Promise<ValidationResult> {
|
|
16
|
-
return this.request.get('/v4/address/validate', { address })
|
|
17
|
-
.then((response : APIResponse) => response)
|
|
18
|
-
.then((res : ValidationResponse) => res.body as ValidationResult);
|
|
19
|
-
}
|
|
20
|
-
}
|
package/lib/webhooks.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import urljoin from 'url-join';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
ValidationResponse,
|
|
5
|
-
WebhookList,
|
|
6
|
-
WebhookResponse,
|
|
7
|
-
WebhooksIds,
|
|
8
|
-
WebhooksQuery
|
|
9
|
-
} from './interfaces/Webhooks';
|
|
10
|
-
import Request from './request';
|
|
11
|
-
|
|
12
|
-
class Webhook {
|
|
13
|
-
id: string;
|
|
14
|
-
url: string | undefined;
|
|
15
|
-
|
|
16
|
-
constructor(id: string, url: string | undefined) {
|
|
17
|
-
this.id = id;
|
|
18
|
-
this.url = url;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export default class WebhookClient {
|
|
23
|
-
request: Request;
|
|
24
|
-
|
|
25
|
-
constructor(request: Request) {
|
|
26
|
-
this.request = request;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
_parseWebhookList(response: { body: { webhooks: WebhookList } }): WebhookList {
|
|
30
|
-
return response.body.webhooks;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
_parseWebhookWithID(id: string) {
|
|
34
|
-
return function (response: WebhookResponse): Webhook {
|
|
35
|
-
const webhookResponse = response?.body?.webhook;
|
|
36
|
-
let url = webhookResponse?.url;
|
|
37
|
-
if (!url) {
|
|
38
|
-
url = webhookResponse?.urls && webhookResponse.urls.length
|
|
39
|
-
? webhookResponse.urls[0]
|
|
40
|
-
: undefined;
|
|
41
|
-
}
|
|
42
|
-
return new Webhook(id, url);
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
_parseWebhookTest(response: { body: { code: number, message: string } })
|
|
47
|
-
: {code: number, message:string} {
|
|
48
|
-
return { code: response.body.code, message: response.body.message } as ValidationResponse;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
list(domain: string, query: WebhooksQuery): Promise<WebhookList> {
|
|
52
|
-
return this.request.get(urljoin('/v3/domains', domain, 'webhooks'), query)
|
|
53
|
-
.then(this._parseWebhookList);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
get(domain: string, id: WebhooksIds): Promise<Webhook> {
|
|
57
|
-
return this.request.get(urljoin('/v3/domains', domain, 'webhooks', id))
|
|
58
|
-
.then(this._parseWebhookWithID(id));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
create(domain: string,
|
|
62
|
-
id: string,
|
|
63
|
-
url: string,
|
|
64
|
-
test = false): Promise<Webhook | ValidationResponse> {
|
|
65
|
-
if (test) {
|
|
66
|
-
return this.request.putWithFD(urljoin('/v3/domains', domain, 'webhooks', id, 'test'), { url })
|
|
67
|
-
.then(this._parseWebhookTest);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return this.request.postWithFD(urljoin('/v3/domains', domain, 'webhooks'), { id, url })
|
|
71
|
-
.then(this._parseWebhookWithID(id));
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
update(domain: string, id: string, url: string): Promise<Webhook> {
|
|
75
|
-
return this.request.putWithFD(urljoin('/v3/domains', domain, 'webhooks', id), { url })
|
|
76
|
-
.then(this._parseWebhookWithID(id));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
destroy(domain: string, id: string) : Promise<Webhook> {
|
|
80
|
-
return this.request.delete(urljoin('/v3/domains', domain, 'webhooks', id))
|
|
81
|
-
.then(this._parseWebhookWithID(id));
|
|
82
|
-
}
|
|
83
|
-
}
|
package/test/client.test.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import formData from 'form-data';
|
|
2
|
-
|
|
3
|
-
import { expect } from 'chai';
|
|
4
|
-
|
|
5
|
-
import Client from '../lib/client';
|
|
6
|
-
import Request from '../lib/request';
|
|
7
|
-
import DomainsClient from '../lib/domains';
|
|
8
|
-
import EventsClient from '../lib/events';
|
|
9
|
-
import WebhooksClient from '../lib/webhooks';
|
|
10
|
-
import SuppressionsClient from '../lib/suppressions';
|
|
11
|
-
import MessagesClient from '../lib/messages';
|
|
12
|
-
import RoutesClient from '../lib/routes';
|
|
13
|
-
import ValidateClient from '../lib/validate';
|
|
14
|
-
|
|
15
|
-
import { InputFormData } from '../lib/interfaces/IFormData';
|
|
16
|
-
import StatsClient from '../lib/stats';
|
|
17
|
-
import ListsClient from '../lib/lists';
|
|
18
|
-
import IpPoolsClient from '../lib/ip-pools';
|
|
19
|
-
import IpsClient from '../lib/ips';
|
|
20
|
-
|
|
21
|
-
describe('Client', function () {
|
|
22
|
-
let client: any;
|
|
23
|
-
|
|
24
|
-
beforeEach(function () {
|
|
25
|
-
client = new Client({
|
|
26
|
-
username: 'username',
|
|
27
|
-
key: 'key',
|
|
28
|
-
public_key: 'key',
|
|
29
|
-
timeout: 10000
|
|
30
|
-
}, formData as InputFormData);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('raises error when username is not provided', function () {
|
|
34
|
-
expect(
|
|
35
|
-
function () {
|
|
36
|
-
return new Client({ key: 'key' } as any, formData as InputFormData);
|
|
37
|
-
}
|
|
38
|
-
).to.throw('Parameter "username" is required');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('raises error when key is not provided', function () {
|
|
42
|
-
expect(
|
|
43
|
-
function () {
|
|
44
|
-
return new Client({ username: 'username' } as any, formData as InputFormData);
|
|
45
|
-
}
|
|
46
|
-
).to.throw('Parameter "key" is required');
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('exposes raw request client', function () {
|
|
50
|
-
client.request.should.be.instanceOf(Request);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('creates domain client', function () {
|
|
54
|
-
client.domains.should.be.instanceOf(DomainsClient);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('creates event client', function () {
|
|
58
|
-
client.events.should.be.instanceOf(EventsClient);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('creates webhook client', function () {
|
|
62
|
-
client.webhooks.should.be.instanceOf(WebhooksClient);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('creates suppressions client', function () {
|
|
66
|
-
client.suppressions.should.be.instanceOf(SuppressionsClient);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('creates stats client', function () {
|
|
70
|
-
client.stats.should.be.instanceOf(StatsClient);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('creates messages client', function () {
|
|
74
|
-
client.messages.should.be.instanceOf(MessagesClient);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('creates routes client', function () {
|
|
78
|
-
client.routes.should.be.instanceOf(RoutesClient);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('creates ips client', function () {
|
|
82
|
-
client.ips.should.be.instanceOf(IpsClient);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('creates ip_pools client', function () {
|
|
86
|
-
client.ip_pools.should.be.instanceOf(IpPoolsClient);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('creates lists client', function () {
|
|
90
|
-
client.lists.should.be.instanceOf(ListsClient);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('creates address validate client', function () {
|
|
94
|
-
client.validate.should.be.instanceOf(ValidateClient);
|
|
95
|
-
});
|
|
96
|
-
});
|