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.
Files changed (314) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +15 -3
  3. package/client.d.ts +29 -0
  4. package/domains.d.ts +54 -0
  5. package/domainsCredentials.d.ts +14 -0
  6. package/domainsTags.d.ts +34 -0
  7. package/domainsTemplates.d.ts +35 -0
  8. package/error.d.ts +7 -0
  9. package/events.d.ts +13 -0
  10. package/index.d.ts +9 -0
  11. package/interfaces/APIErrorOptions.d.ts +11 -0
  12. package/{lib/interfaces/ApiResponse.ts → interfaces/ApiResponse.d.ts} +1 -2
  13. package/{lib/interfaces/DomainCredentials.ts → interfaces/DomainCredentials.d.ts} +14 -30
  14. package/{lib/interfaces/DomainTags.ts → interfaces/DomainTags.d.ts} +49 -82
  15. package/{lib/interfaces/DomainTemplates.ts → interfaces/DomainTemplates.d.ts} +35 -79
  16. package/{lib/interfaces/DomainTracking.ts → interfaces/DomainTracking.d.ts} +18 -17
  17. package/{lib/interfaces/Domains.ts → interfaces/Domains.d.ts} +29 -50
  18. package/{lib/interfaces/Events.ts → interfaces/Events.d.ts} +11 -12
  19. package/{lib/interfaces/IFormData.ts → interfaces/IFormData.d.ts} +2 -4
  20. package/interfaces/IMailgunClient.d.ts +24 -0
  21. package/interfaces/IpPools.d.ts +19 -0
  22. package/interfaces/Ips.d.ts +10 -0
  23. package/interfaces/Messages.d.ts +165 -0
  24. package/{lib/interfaces/MultipleValidation.ts → interfaces/MultipleValidation.d.ts} +9 -16
  25. package/interfaces/Options.d.ts +8 -0
  26. package/{lib/interfaces/RequestOptions.ts → interfaces/RequestOptions.d.ts} +2 -4
  27. package/interfaces/StatsOptions.d.ts +22 -0
  28. package/interfaces/Supressions.d.ts +103 -0
  29. package/{lib/interfaces/Validate.ts → interfaces/Validate.d.ts} +0 -3
  30. package/{lib/interfaces/Webhooks.ts → interfaces/Webhooks.d.ts} +11 -17
  31. package/{lib/interfaces/lists.ts → interfaces/lists.d.ts} +1 -5
  32. package/{lib/interfaces/mailListMembers.ts → interfaces/mailListMembers.d.ts} +8 -23
  33. package/{lib/interfaces/routes.ts → interfaces/routes.d.ts} +1 -6
  34. package/ip-pools.d.ts +21 -0
  35. package/ips.d.ts +9 -0
  36. package/lists.d.ts +14 -0
  37. package/mailListMembers.d.ts +14 -0
  38. package/mailgun.node.js +3 -0
  39. package/{dist/mailgun.node.js.LICENSE.txt → mailgun.node.js.LICENSE.txt} +1 -1
  40. package/mailgun.web.js +3 -0
  41. package/{dist/mailgun.web.js.LICENSE.txt → mailgun.web.js.LICENSE.txt} +1 -1
  42. package/messages.d.ts +8 -0
  43. package/multipleValidation.d.ts +10 -0
  44. package/package.json +8 -81
  45. package/request.d.ts +31 -0
  46. package/routes.d.ts +11 -0
  47. package/stats.d.ts +20 -0
  48. package/suppressions.d.ts +50 -0
  49. package/validate.d.ts +9 -0
  50. package/version.md +1 -0
  51. package/webhooks.d.ts +32 -0
  52. package/.editorconfig +0 -10
  53. package/.eslintrc +0 -56
  54. package/.husky/commit-msg +0 -4
  55. package/.travis.yml +0 -5
  56. package/LICENSE +0 -191
  57. package/commitlint.config.js +0 -7
  58. package/dist/mailgun.js.d.ts +0 -1586
  59. package/dist/mailgun.node.js +0 -3
  60. package/dist/mailgun.web.js +0 -3
  61. package/docs/.nojekyll +0 -1
  62. package/docs/assets/highlight.css +0 -127
  63. package/docs/assets/icons.css +0 -1043
  64. package/docs/assets/icons.png +0 -0
  65. package/docs/assets/icons@2x.png +0 -0
  66. package/docs/assets/main.js +0 -52
  67. package/docs/assets/search.js +0 -1
  68. package/docs/assets/style.css +0 -1413
  69. package/docs/assets/widgets.png +0 -0
  70. package/docs/assets/widgets@2x.png +0 -0
  71. package/docs/classes/client.default.html +0 -1
  72. package/docs/classes/domains.Domain.html +0 -1
  73. package/docs/classes/domains.default.html +0 -1
  74. package/docs/classes/domainsCredentials.default.html +0 -1
  75. package/docs/classes/domainsTemplates.DomainTemplateItem.html +0 -1
  76. package/docs/classes/domainsTemplates.default.html +0 -1
  77. package/docs/classes/error.default.html +0 -6
  78. package/docs/classes/events.default.html +0 -1
  79. package/docs/classes/ip_pools.default.html +0 -1
  80. package/docs/classes/ips.default.html +0 -1
  81. package/docs/classes/lists.default.html +0 -1
  82. package/docs/classes/mailListMembers.default.html +0 -1
  83. package/docs/classes/messages.default.html +0 -1
  84. package/docs/classes/multipleValidation.default.html +0 -1
  85. package/docs/classes/request.default.html +0 -1
  86. package/docs/classes/routes.default.html +0 -1
  87. package/docs/classes/stats.default.html +0 -1
  88. package/docs/classes/suppressions.default.html +0 -1
  89. package/docs/classes/validate.default.html +0 -1
  90. package/docs/classes/webhooks.default.html +0 -1
  91. package/docs/enums/interfaces_DomainTemplates.Pages.html +0 -1
  92. package/docs/enums/interfaces_DomainTemplates.YesNo.html +0 -1
  93. package/docs/index.html +0 -1140
  94. package/docs/interfaces/interfaces_APIErrorOptions.default.html +0 -1
  95. package/docs/interfaces/interfaces_ApiResponse.default.html +0 -1
  96. package/docs/interfaces/interfaces_DomainCredentials.CreatedUpdatedDomainCredentialsResponse.html +0 -1
  97. package/docs/interfaces/interfaces_DomainCredentials.DeletedDomainCredentialsResponse.html +0 -1
  98. package/docs/interfaces/interfaces_DomainCredentials.DomainCredentials.html +0 -1
  99. package/docs/interfaces/interfaces_DomainCredentials.DomainCredentialsItem.html +0 -1
  100. package/docs/interfaces/interfaces_DomainCredentials.DomainCredentialsList.html +0 -1
  101. package/docs/interfaces/interfaces_DomainCredentials.DomainCredentialsQuery.html +0 -1
  102. package/docs/interfaces/interfaces_DomainCredentials.DomainCredentialsResponseData.html +0 -1
  103. package/docs/interfaces/interfaces_DomainCredentials.DomainCredentialsResult.html +0 -1
  104. package/docs/interfaces/interfaces_DomainCredentials.IDomainCredentials.html +0 -1
  105. package/docs/interfaces/interfaces_DomainCredentials.UpdateDomainCredentialsData.html +0 -1
  106. package/docs/interfaces/interfaces_DomainTemplates.CreateDomainTemplateAPIResponse.html +0 -1
  107. package/docs/interfaces/interfaces_DomainTemplates.CreateDomainTemplateVersionAPIResponse.html +0 -1
  108. package/docs/interfaces/interfaces_DomainTemplates.CreateDomainTemplateVersionResult.html +0 -1
  109. package/docs/interfaces/interfaces_DomainTemplates.DomainTemplate.html +0 -1
  110. package/docs/interfaces/interfaces_DomainTemplates.DomainTemplateData.html +0 -1
  111. package/docs/interfaces/interfaces_DomainTemplates.DomainTemplateUpdateData.html +0 -1
  112. package/docs/interfaces/interfaces_DomainTemplates.DomainTemplateUpdateVersionData.html +0 -1
  113. package/docs/interfaces/interfaces_DomainTemplates.DomainTemplateVersionData.html +0 -1
  114. package/docs/interfaces/interfaces_DomainTemplates.DomainTemplatesQuery.html +0 -1
  115. package/docs/interfaces/interfaces_DomainTemplates.GetDomainTemplateAPIResponse.html +0 -1
  116. package/docs/interfaces/interfaces_DomainTemplates.IDomainTemplatesClient.html +0 -1
  117. package/docs/interfaces/interfaces_DomainTemplates.ListDomainTemplateVersionsAPIResponse.html +0 -1
  118. package/docs/interfaces/interfaces_DomainTemplates.ListDomainTemplateVersionsResult.html +0 -1
  119. package/docs/interfaces/interfaces_DomainTemplates.ListDomainTemplatesAPIResponse.html +0 -1
  120. package/docs/interfaces/interfaces_DomainTemplates.ListDomainTemplatesResult.html +0 -1
  121. package/docs/interfaces/interfaces_DomainTemplates.MutateDomainTemplateVersionAPIResponse.html +0 -1
  122. package/docs/interfaces/interfaces_DomainTemplates.MutateDomainTemplateVersionResult.html +0 -1
  123. package/docs/interfaces/interfaces_DomainTemplates.NotificationAPIResponse.html +0 -1
  124. package/docs/interfaces/interfaces_DomainTemplates.NotificationResult.html +0 -1
  125. package/docs/interfaces/interfaces_DomainTemplates.ShortTemplateVersion.html +0 -1
  126. package/docs/interfaces/interfaces_DomainTemplates.TemplateQuery.html +0 -1
  127. package/docs/interfaces/interfaces_DomainTemplates.TemplateVersion.html +0 -1
  128. package/docs/interfaces/interfaces_DomainTemplates.UpdateOrDeleteDomainTemplateAPIResponse.html +0 -1
  129. package/docs/interfaces/interfaces_DomainTemplates.UpdateOrDeleteDomainTemplateResult.html +0 -1
  130. package/docs/interfaces/interfaces_DomainTracking.ClickTrackingInfo.html +0 -1
  131. package/docs/interfaces/interfaces_DomainTracking.DomainTrackingData.html +0 -1
  132. package/docs/interfaces/interfaces_DomainTracking.DomainTrackingResponse.html +0 -1
  133. package/docs/interfaces/interfaces_DomainTracking.OpenTrackingInfo.html +0 -1
  134. package/docs/interfaces/interfaces_DomainTracking.UnsubscribeTrackingInfo.html +0 -1
  135. package/docs/interfaces/interfaces_DomainTracking.UpdateDomainTrackingResponse.html +0 -1
  136. package/docs/interfaces/interfaces_DomainTracking.UpdatedOpenTracking.html +0 -1
  137. package/docs/interfaces/interfaces_Domains.ConnectionSettings.html +0 -1
  138. package/docs/interfaces/interfaces_Domains.ConnectionSettingsResponse.html +0 -1
  139. package/docs/interfaces/interfaces_Domains.DKIMAuthorityInfo.html +0 -1
  140. package/docs/interfaces/interfaces_Domains.DKIMSelectorInfo.html +0 -1
  141. package/docs/interfaces/interfaces_Domains.DNSRecord.html +0 -1
  142. package/docs/interfaces/interfaces_Domains.DestroyedDomainResponse.html +0 -1
  143. package/docs/interfaces/interfaces_Domains.DomainData.html +0 -1
  144. package/docs/interfaces/interfaces_Domains.DomainInfo.html +0 -1
  145. package/docs/interfaces/interfaces_Domains.DomainListResponseData.html +0 -1
  146. package/docs/interfaces/interfaces_Domains.DomainResponseData.html +0 -1
  147. package/docs/interfaces/interfaces_Domains.DomainShortData.html +0 -1
  148. package/docs/interfaces/interfaces_Domains.DomainsListItem.html +0 -1
  149. package/docs/interfaces/interfaces_Domains.DomainsQuery.html +0 -1
  150. package/docs/interfaces/interfaces_Domains.MessageResponse.html +0 -1
  151. package/docs/interfaces/interfaces_Domains.ReplacementForPool.html +0 -1
  152. package/docs/interfaces/interfaces_Domains.UpdatedConnectionSettings.html +0 -1
  153. package/docs/interfaces/interfaces_Domains.UpdatedConnectionSettingsRes.html +0 -1
  154. package/docs/interfaces/interfaces_Domains.UpdatedDKIMAuthority.html +0 -1
  155. package/docs/interfaces/interfaces_Domains.UpdatedDKIMAuthorityResponse.html +0 -1
  156. package/docs/interfaces/interfaces_Domains.UpdatedDKIMSelectorResponse.html +0 -1
  157. package/docs/interfaces/interfaces_Domains.UpdatedWebPrefix.html +0 -1
  158. package/docs/interfaces/interfaces_Domains.UpdatedWebPrefixResponse.html +0 -1
  159. package/docs/interfaces/interfaces_Domains.WebPrefixInfo.html +0 -1
  160. package/docs/interfaces/interfaces_Events.DomainEvent.html +0 -1
  161. package/docs/interfaces/interfaces_Events.EventsList.html +0 -1
  162. package/docs/interfaces/interfaces_Events.EventsPage.html +0 -1
  163. package/docs/interfaces/interfaces_Events.EventsResponse.html +0 -1
  164. package/docs/interfaces/interfaces_Events.PagesList.html +0 -1
  165. package/docs/interfaces/interfaces_Events.PagesListAccumulator.html +0 -1
  166. package/docs/interfaces/interfaces_Events.ParsedPage.html +0 -1
  167. package/docs/interfaces/interfaces_Events.ParsedPagesList.html +0 -1
  168. package/docs/interfaces/interfaces_IFormData.IFormDataOptions.html +0 -1
  169. package/docs/interfaces/interfaces_IFormData.InputFormData.html +0 -1
  170. package/docs/interfaces/interfaces_IpPools.IpPool.html +0 -1
  171. package/docs/interfaces/interfaces_IpPools.IpPoolListResponse.html +0 -1
  172. package/docs/interfaces/interfaces_IpPools.IpPoolUpdateData.html +0 -1
  173. package/docs/interfaces/interfaces_Ips.IpData.html +0 -1
  174. package/docs/interfaces/interfaces_Ips.IpsListResponseBody.html +0 -1
  175. package/docs/interfaces/interfaces_MultipleValidation.CanceledMultipleValidationJob.html +0 -1
  176. package/docs/interfaces/interfaces_MultipleValidation.CreatedMultipleValidationJob.html +0 -1
  177. package/docs/interfaces/interfaces_MultipleValidation.IMultipleValidationClient.html +0 -1
  178. package/docs/interfaces/interfaces_MultipleValidation.MultipleValidationJob.html +0 -1
  179. package/docs/interfaces/interfaces_MultipleValidation.MultipleValidationJobsListResponse.html +0 -1
  180. package/docs/interfaces/interfaces_MultipleValidation.MultipleValidationJobsListResult.html +0 -1
  181. package/docs/interfaces/interfaces_MultipleValidation.PagesList.html +0 -1
  182. package/docs/interfaces/interfaces_Options.default.html +0 -1
  183. package/docs/interfaces/interfaces_RequestOptions.default.html +0 -1
  184. package/docs/interfaces/interfaces_StatsOptions.Stat.html +0 -1
  185. package/docs/interfaces/interfaces_StatsOptions.StatsOptions.html +0 -1
  186. package/docs/interfaces/interfaces_StatsOptions.StatsQuery.html +0 -1
  187. package/docs/interfaces/interfaces_Supressions.BounceData.html +0 -1
  188. package/docs/interfaces/interfaces_Supressions.ComplaintData.html +0 -1
  189. package/docs/interfaces/interfaces_Supressions.UnsubscribeData.html +0 -1
  190. package/docs/interfaces/interfaces_Supressions.WhiteListData.html +0 -1
  191. package/docs/interfaces/interfaces_Validate.ValidationResponse.html +0 -1
  192. package/docs/interfaces/interfaces_Validate.ValidationResult.html +0 -1
  193. package/docs/interfaces/interfaces_Webhooks.APIWebhook.html +0 -1
  194. package/docs/interfaces/interfaces_Webhooks.ValidationResponse.html +0 -1
  195. package/docs/interfaces/interfaces_Webhooks.WebhookList.html +0 -1
  196. package/docs/interfaces/interfaces_Webhooks.WebhookResponse.html +0 -1
  197. package/docs/interfaces/interfaces_Webhooks.WebhookResponseBody.html +0 -1
  198. package/docs/interfaces/interfaces_Webhooks.WebhooksQuery.html +0 -1
  199. package/docs/interfaces/interfaces_lists.CreateUpdateList.html +0 -1
  200. package/docs/interfaces/interfaces_lists.DestroyedList.html +0 -1
  201. package/docs/interfaces/interfaces_lists.ListsQuery.html +0 -1
  202. package/docs/interfaces/interfaces_lists.MailingList.html +0 -1
  203. package/docs/interfaces/interfaces_mailListMembers.CreateUpdateMailListMembers.html +0 -1
  204. package/docs/interfaces/interfaces_mailListMembers.CreateUpdateMailListMembersReq.html +0 -1
  205. package/docs/interfaces/interfaces_mailListMembers.DeletedMember.html +0 -1
  206. package/docs/interfaces/interfaces_mailListMembers.IMailListsMembers.html +0 -1
  207. package/docs/interfaces/interfaces_mailListMembers.MailListMember.html +0 -1
  208. package/docs/interfaces/interfaces_mailListMembers.MailListMembersQuery.html +0 -1
  209. package/docs/interfaces/interfaces_mailListMembers.MultipleMembersData.html +0 -1
  210. package/docs/interfaces/interfaces_mailListMembers.MultipleMembersReqData.html +0 -1
  211. package/docs/interfaces/interfaces_mailListMembers.NewMultipleMembersResponse.html +0 -1
  212. package/docs/interfaces/interfaces_routes.CreateUpdateRouteData.html +0 -1
  213. package/docs/interfaces/interfaces_routes.DestroyRouteResponse.html +0 -1
  214. package/docs/interfaces/interfaces_routes.Route.html +0 -1
  215. package/docs/interfaces/interfaces_routes.RoutesListQuery.html +0 -1
  216. package/docs/interfaces/interfaces_routes.UpdateRouteResponse.html +0 -1
  217. package/docs/modules/client.html +0 -1
  218. package/docs/modules/domains.html +0 -1
  219. package/docs/modules/domainsCredentials.html +0 -1
  220. package/docs/modules/domainsTemplates.html +0 -1
  221. package/docs/modules/error.html +0 -1
  222. package/docs/modules/events.html +0 -1
  223. package/docs/modules/interfaces_APIErrorOptions.html +0 -1
  224. package/docs/modules/interfaces_ApiResponse.html +0 -1
  225. package/docs/modules/interfaces_DomainCredentials.html +0 -1
  226. package/docs/modules/interfaces_DomainTemplates.html +0 -1
  227. package/docs/modules/interfaces_DomainTracking.html +0 -1
  228. package/docs/modules/interfaces_Domains.html +0 -1
  229. package/docs/modules/interfaces_Events.html +0 -1
  230. package/docs/modules/interfaces_IFormData.html +0 -1
  231. package/docs/modules/interfaces_IpPools.html +0 -1
  232. package/docs/modules/interfaces_Ips.html +0 -1
  233. package/docs/modules/interfaces_MultipleValidation.html +0 -1
  234. package/docs/modules/interfaces_Options.html +0 -1
  235. package/docs/modules/interfaces_RequestOptions.html +0 -1
  236. package/docs/modules/interfaces_StatsOptions.html +0 -1
  237. package/docs/modules/interfaces_Supressions.html +0 -1
  238. package/docs/modules/interfaces_Validate.html +0 -1
  239. package/docs/modules/interfaces_Webhooks.html +0 -1
  240. package/docs/modules/interfaces_lists.html +0 -1
  241. package/docs/modules/interfaces_mailListMembers.html +0 -1
  242. package/docs/modules/interfaces_routes.html +0 -1
  243. package/docs/modules/ip_pools.html +0 -1
  244. package/docs/modules/ips.html +0 -1
  245. package/docs/modules/lists.html +0 -1
  246. package/docs/modules/mailListMembers.html +0 -1
  247. package/docs/modules/messages.html +0 -1
  248. package/docs/modules/multipleValidation.html +0 -1
  249. package/docs/modules/request.html +0 -1
  250. package/docs/modules/routes.html +0 -1
  251. package/docs/modules/stats.html +0 -1
  252. package/docs/modules/suppressions.html +0 -1
  253. package/docs/modules/validate.html +0 -1
  254. package/docs/modules/webhooks.html +0 -1
  255. package/docs/modules.html +0 -1
  256. package/dts-bundle.js +0 -8
  257. package/examples/addresses.js +0 -20
  258. package/examples/index.html +0 -285
  259. package/examples/list-domains.js +0 -8
  260. package/examples/mailgun.png +0 -0
  261. package/examples/rackspace.png +0 -0
  262. package/examples/send-email.js +0 -24
  263. package/lib/client.ts +0 -79
  264. package/lib/domains.ts +0 -224
  265. package/lib/domainsCredentials.ts +0 -88
  266. package/lib/domainsTags.ts +0 -165
  267. package/lib/domainsTemplates.ts +0 -235
  268. package/lib/error.ts +0 -22
  269. package/lib/events.ts +0 -54
  270. package/lib/index.ts +0 -16
  271. package/lib/interfaces/APIErrorOptions.ts +0 -10
  272. package/lib/interfaces/IpPools.ts +0 -22
  273. package/lib/interfaces/Ips.ts +0 -12
  274. package/lib/interfaces/Options.ts +0 -10
  275. package/lib/interfaces/StatsOptions.ts +0 -25
  276. package/lib/interfaces/Supressions.ts +0 -123
  277. package/lib/ip-pools.ts +0 -36
  278. package/lib/ips.ts +0 -24
  279. package/lib/lists.ts +0 -45
  280. package/lib/mailListMembers.ts +0 -83
  281. package/lib/messages.ts +0 -27
  282. package/lib/multipleValidation.ts +0 -37
  283. package/lib/request.ts +0 -271
  284. package/lib/routes.ts +0 -37
  285. package/lib/stats.ts +0 -62
  286. package/lib/suppressions.ts +0 -253
  287. package/lib/validate.ts +0 -20
  288. package/lib/webhooks.ts +0 -83
  289. package/test/client.test.ts +0 -96
  290. package/test/data/emailsValidation1.csv +0 -3
  291. package/test/domains.test.ts +0 -313
  292. package/test/domainsCredentials.test.ts +0 -97
  293. package/test/domainsTags.test.ts +0 -345
  294. package/test/domainsTemplates.test.ts +0 -392
  295. package/test/error.test.ts +0 -32
  296. package/test/events.test.ts +0 -104
  297. package/test/img/mailgun.png +0 -0
  298. package/test/ips.test.ts +0 -57
  299. package/test/lists.test.ts +0 -100
  300. package/test/mailListMembers.test.ts +0 -198
  301. package/test/messageAttachment.test.ts +0 -50
  302. package/test/messages.test.ts +0 -89
  303. package/test/multipleValidation.test.ts +0 -159
  304. package/test/request.test.ts +0 -103
  305. package/test/routes.test.ts +0 -136
  306. package/test/stats.test.ts +0 -90
  307. package/test/suppressions.test.ts +0 -303
  308. package/test/validate.test.ts +0 -43
  309. package/test/webhooks.test.ts +0 -112
  310. package/tsconfig.json +0 -22
  311. package/tsconfig.webpack.json +0 -10
  312. package/webpack/webpack.common.config.js +0 -46
  313. package/webpack/webpack.dev.config.js +0 -36
  314. 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
- }
@@ -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
- }
@@ -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
- });
@@ -1,3 +0,0 @@
1
- email
2
- 1testEmailAdressForCheck@test.com
3
- 2testEmailAdressForCheck@test.com