mailgun.js 12.2.0 → 12.3.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/Types/index.js CHANGED
@@ -4813,11 +4813,16 @@ var Request = /** @class */ (function () {
4813
4813
  Request.prototype.request = function (method, url, onCallOptions, config) {
4814
4814
  var _a;
4815
4815
  return __awaiter(this, void 0, void 0, function () {
4816
- var options, params, urlValue;
4816
+ var options, params, fullUrl;
4817
4817
  return __generator(this, function (_b) {
4818
4818
  options = __assign({}, onCallOptions);
4819
4819
  params = {};
4820
- urlValue = urljoin(this.url, url);
4820
+ if (config === null || config === void 0 ? void 0 : config.isStorageAPI) {
4821
+ fullUrl = url;
4822
+ }
4823
+ else {
4824
+ fullUrl = urljoin(this.url, url);
4825
+ }
4821
4826
  if ((options === null || options === void 0 ? void 0 : options.query) && Object.getOwnPropertyNames(options === null || options === void 0 ? void 0 : options.query).length > 0) {
4822
4827
  if ((_a = options === null || options === void 0 ? void 0 : options.query) === null || _a === void 0 ? void 0 : _a.searchParams) {
4823
4828
  params.params = new URLSearchParams(options.query.searchParams);
@@ -4829,7 +4834,7 @@ var Request = /** @class */ (function () {
4829
4834
  if (options === null || options === void 0 ? void 0 : options.body) {
4830
4835
  params.data = options === null || options === void 0 ? void 0 : options.body;
4831
4836
  }
4832
- return [2 /*return*/, this.requestProvider.makeRequest(urlValue, method.toUpperCase(), params, config)];
4837
+ return [2 /*return*/, this.requestProvider.makeRequest(fullUrl, method.toUpperCase(), params, config)];
4833
4838
  });
4834
4839
  });
4835
4840
  };
@@ -4912,8 +4917,8 @@ var Request = /** @class */ (function () {
4912
4917
  Request.prototype.put = function (url, data, queryObject) {
4913
4918
  return this.command('put', url, data, {}, queryObject);
4914
4919
  };
4915
- Request.prototype.delete = function (url, data) {
4916
- return this.command('delete', url, data);
4920
+ Request.prototype.delete = function (url, data, queryObject) {
4921
+ return this.command('delete', url, data, {}, { query: queryObject });
4917
4922
  };
4918
4923
  return Request;
4919
4924
  }());
@@ -4955,7 +4960,7 @@ var Domain = /** @class */ (function () {
4955
4960
  }());
4956
4961
 
4957
4962
  var DomainsClient = /** @class */ (function () {
4958
- function DomainsClient(request, domainCredentialsClient, domainTemplatesClient, domainTagsClient, domainTracking, logger) {
4963
+ function DomainsClient(request, domainCredentialsClient, domainTemplatesClient, domainTagsClient, domainTracking, domainKeysClient, logger) {
4959
4964
  if (logger === void 0) { logger = console; }
4960
4965
  this.request = request;
4961
4966
  this.domainCredentials = domainCredentialsClient;
@@ -4963,6 +4968,7 @@ var DomainsClient = /** @class */ (function () {
4963
4968
  this.domainTags = domainTagsClient;
4964
4969
  this.logger = logger;
4965
4970
  this.domainTracking = domainTracking;
4971
+ this.domainKeys = domainKeysClient;
4966
4972
  }
4967
4973
  DomainsClient.prototype._handleBoolValues = function (data) {
4968
4974
  var propsForReplacement = data;
@@ -5103,28 +5109,25 @@ var DomainsClient = /** @class */ (function () {
5103
5109
  }
5104
5110
  return this.request.delete(urljoin('/v3/domains', domain, 'ips', 'ip_pool', searchParams));
5105
5111
  };
5112
+ /**
5113
+ * @deprecated "domains.updateDKIMAuthority" method is deprecated,
5114
+ * and moved into the "domains.domainKeys.updateDKIMAuthority".
5115
+ * Current method will be removed in the future releases.
5116
+ */
5106
5117
  DomainsClient.prototype.updateDKIMAuthority = function (domain, data) {
5107
- var options = { query: "self=".concat(data.self) };
5108
- return this.request.put("/v3/domains/".concat(domain, "/dkim_authority"), {}, options)
5109
- .then(function (res) { return res; })
5110
- .then(function (res) { return res.body; });
5118
+ this.logger.warn('"domains.updateDKIMAuthority" method is deprecated. Please use "domains.domainKeys.updateDKIMAuthority" instead');
5119
+ return this.domainKeys.updateDKIMAuthority(domain, data);
5111
5120
  };
5121
+ /**
5122
+ * @deprecated "domains.updateDKIMSelector" method is deprecated,
5123
+ * and moved into the "domains.domainKeys.updateDKIMSelector".
5124
+ * Current method will be removed in the future releases.
5125
+ */
5112
5126
  DomainsClient.prototype.updateDKIMSelector = function (domain, data) {
5113
- var _a;
5114
5127
  return __awaiter(this, void 0, void 0, function () {
5115
- var options, res;
5116
- return __generator(this, function (_b) {
5117
- switch (_b.label) {
5118
- case 0:
5119
- options = { query: "dkim_selector=".concat(data.dkimSelector) };
5120
- return [4 /*yield*/, this.request.put("/v3/domains/".concat(domain, "/dkim_selector"), {}, options)];
5121
- case 1:
5122
- res = _b.sent();
5123
- return [2 /*return*/, {
5124
- status: res.status,
5125
- message: (_a = res === null || res === void 0 ? void 0 : res.body) === null || _a === void 0 ? void 0 : _a.message
5126
- }];
5127
- }
5128
+ return __generator(this, function (_a) {
5129
+ this.logger.warn('"domains.updateDKIMSelector" method is deprecated. Please use domains.domainKeys.updateDKIMSelector instead');
5130
+ return [2 /*return*/, this.domainKeys.updateDKIMSelector(domain, data)];
5128
5131
  });
5129
5132
  });
5130
5133
  };
@@ -5587,9 +5590,6 @@ var MessagesClient = /** @class */ (function () {
5587
5590
  'o:require-tls',
5588
5591
  'o:skip-verification'
5589
5592
  ]);
5590
- if (!data || Object.keys(data).length === 0) {
5591
- throw APIError.getUserDataError('Message data object can not be empty', 'Message data object can not be empty');
5592
- }
5593
5593
  return Object.keys(data).reduce(function (acc, key) {
5594
5594
  if (yesNoProperties.has(key) && typeof data[key] === 'boolean') {
5595
5595
  acc[key] = data[key] ? 'yes' : 'no';
@@ -5604,6 +5604,9 @@ var MessagesClient = /** @class */ (function () {
5604
5604
  return __assign({ status: response.status }, response.body);
5605
5605
  };
5606
5606
  MessagesClient.prototype.create = function (domain, data) {
5607
+ if (!data || Object.keys(data).length === 0) {
5608
+ throw APIError.getUserDataError('Message data object can not be empty', 'Message data object can not be empty');
5609
+ }
5607
5610
  if (data.message) {
5608
5611
  return this.request.postWithFD("/v3/".concat(domain, "/messages.mime"), data)
5609
5612
  .then(this._parseResponse);
@@ -5612,6 +5615,95 @@ var MessagesClient = /** @class */ (function () {
5612
5615
  return this.request.postWithFD("/v3/".concat(domain, "/messages"), modifiedData)
5613
5616
  .then(this._parseResponse);
5614
5617
  };
5618
+ MessagesClient.prototype.retrieveStoredEmail = function (domain, storageKey) {
5619
+ return __awaiter(this, void 0, void 0, function () {
5620
+ var res;
5621
+ return __generator(this, function (_a) {
5622
+ switch (_a.label) {
5623
+ case 0: return [4 /*yield*/, this.request.get("/v3/domains/".concat(domain, "/messages/").concat(storageKey))];
5624
+ case 1:
5625
+ res = _a.sent();
5626
+ return [2 /*return*/, res.body];
5627
+ }
5628
+ });
5629
+ });
5630
+ };
5631
+ /**
5632
+ * domain: string
5633
+ * Domain name used to send the message
5634
+ *
5635
+ * storageKey: string
5636
+ * Storage key from the email's associated events
5637
+ * (Example: Accepted/Delivered events storage.key field)
5638
+ *
5639
+ * recipients: string
5640
+ * Email address of the recipient(s). You can use commas to separate multiple recipients
5641
+ */
5642
+ MessagesClient.prototype.resendEmail = function (domain, storageKey, recipients) {
5643
+ return __awaiter(this, void 0, void 0, function () {
5644
+ var res;
5645
+ return __generator(this, function (_a) {
5646
+ switch (_a.label) {
5647
+ case 0: return [4 /*yield*/, this.request.postWithFD("/v3/domains/".concat(domain, "/messages/").concat(storageKey), { to: recipients })];
5648
+ case 1:
5649
+ res = _a.sent();
5650
+ return [2 /*return*/, this._parseResponse(res)];
5651
+ }
5652
+ });
5653
+ });
5654
+ };
5655
+ MessagesClient.prototype.getMessagesQueueStatus = function (domain) {
5656
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
5657
+ return __awaiter(this, void 0, void 0, function () {
5658
+ var res, apiResponse, result;
5659
+ return __generator(this, function (_l) {
5660
+ switch (_l.label) {
5661
+ case 0: return [4 /*yield*/, this.request.get("/v3/domains/".concat(domain, "/sending_queues"))];
5662
+ case 1:
5663
+ res = _l.sent();
5664
+ apiResponse = res.body;
5665
+ result = {
5666
+ regular: {
5667
+ is_disabled: (_a = apiResponse.regular) === null || _a === void 0 ? void 0 : _a.is_disabled,
5668
+ disabled: {
5669
+ until: ((_c = (_b = apiResponse.regular) === null || _b === void 0 ? void 0 : _b.disabled) === null || _c === void 0 ? void 0 : _c.until) ? new Date(apiResponse.regular.disabled.until) : '',
5670
+ reason: ((_e = (_d = apiResponse.regular) === null || _d === void 0 ? void 0 : _d.disabled) === null || _e === void 0 ? void 0 : _e.reason) || '',
5671
+ }
5672
+ },
5673
+ scheduled: {
5674
+ is_disabled: (_f = apiResponse.scheduled) === null || _f === void 0 ? void 0 : _f.is_disabled,
5675
+ disabled: {
5676
+ until: ((_h = (_g = apiResponse.scheduled) === null || _g === void 0 ? void 0 : _g.disabled) === null || _h === void 0 ? void 0 : _h.until) ? new Date(apiResponse.scheduled.disabled.until) : '',
5677
+ reason: ((_k = (_j = apiResponse.scheduled) === null || _j === void 0 ? void 0 : _j.disabled) === null || _k === void 0 ? void 0 : _k.reason) || '',
5678
+ }
5679
+ }
5680
+ };
5681
+ return [2 /*return*/, result];
5682
+ }
5683
+ });
5684
+ });
5685
+ };
5686
+ /** Deletes all scheduled and undelivered mail from the domain queue.
5687
+ * https://documentation.mailgun.com/docs/mailgun/api-reference/send/mailgun/messages/delete-v3--domain-name--envelopes
5688
+ */
5689
+ MessagesClient.prototype.clearMessagesQueue = function (domain, storageUrl) {
5690
+ return __awaiter(this, void 0, void 0, function () {
5691
+ var allowedStorageUrls, res;
5692
+ return __generator(this, function (_a) {
5693
+ switch (_a.label) {
5694
+ case 0:
5695
+ allowedStorageUrls = ['storage-us-east4.api.mailgun.net', 'storage-us-west1.api.mailgun.net', 'storage-europe-west1.api.mailgun.net'];
5696
+ if (!allowedStorageUrls.includes(storageUrl)) {
5697
+ throw APIError.getUserDataError('Invalid storage URL', 'The provided storage URL is not allowed.');
5698
+ }
5699
+ return [4 /*yield*/, this.request.command('delete', "https://".concat(storageUrl, "/v3/").concat(domain, "/envelopes"), undefined, { isStorageAPI: true })];
5700
+ case 1:
5701
+ res = _a.sent();
5702
+ return [2 /*return*/, res.body];
5703
+ }
5704
+ });
5705
+ });
5706
+ };
5615
5707
  return MessagesClient;
5616
5708
  }());
5617
5709
 
@@ -6872,6 +6964,155 @@ var DomainTrackingClient = /** @class */ (function () {
6872
6964
  return DomainTrackingClient;
6873
6965
  }());
6874
6966
 
6967
+ var DomainKeysClient = /** @class */ (function (_super) {
6968
+ __extends(DomainKeysClient, _super);
6969
+ function DomainKeysClient(request) {
6970
+ var _this = _super.call(this, request) || this;
6971
+ _this.request = request;
6972
+ _this.baseRoute = '/v3/domains/';
6973
+ return _this;
6974
+ }
6975
+ DomainKeysClient.prototype._parseDomainKeysList = function (response) {
6976
+ return {
6977
+ items: response.items,
6978
+ };
6979
+ };
6980
+ DomainKeysClient.prototype.parseList = function (response) {
6981
+ response.body.items;
6982
+ this.parsePageLinks(response, '?', 'page');
6983
+ response.status;
6984
+ return {
6985
+ items: response.body.items,
6986
+ pages: this.parsePageLinks(response, '?', 'page'),
6987
+ status: response.status || 200,
6988
+ };
6989
+ };
6990
+ DomainKeysClient.prototype.list = function (domainName) {
6991
+ return __awaiter(this, void 0, void 0, function () {
6992
+ var res;
6993
+ return __generator(this, function (_a) {
6994
+ switch (_a.label) {
6995
+ case 0: return [4 /*yield*/, this.request.get(urljoin('v4/domains/', domainName, '/keys'))];
6996
+ case 1:
6997
+ res = _a.sent();
6998
+ return [2 /*return*/, __assign(__assign({}, this._parseDomainKeysList(res.body)), { status: res.status })];
6999
+ }
7000
+ });
7001
+ });
7002
+ };
7003
+ DomainKeysClient.prototype.listAll = function (query) {
7004
+ return __awaiter(this, void 0, void 0, function () {
7005
+ var preparedQuery, res;
7006
+ return __generator(this, function (_a) {
7007
+ switch (_a.label) {
7008
+ case 0:
7009
+ preparedQuery = __assign(__assign(__assign({}, ((query === null || query === void 0 ? void 0 : query.signingDomain)
7010
+ ? { signing_domain: encodeURIComponent(query.signingDomain) }
7011
+ : {})), ((query === null || query === void 0 ? void 0 : query.selector) ? { selector: encodeURIComponent(query.selector) } : {})), { page: '', limit: '' });
7012
+ return [4 /*yield*/, this.requestListWithPages(urljoin('/v1/dkim/keys'), preparedQuery)];
7013
+ case 1:
7014
+ res = _a.sent();
7015
+ return [2 /*return*/, res];
7016
+ }
7017
+ });
7018
+ });
7019
+ };
7020
+ DomainKeysClient.prototype.create = function (data) {
7021
+ return __awaiter(this, void 0, void 0, function () {
7022
+ var preparedData, res;
7023
+ return __generator(this, function (_a) {
7024
+ switch (_a.label) {
7025
+ case 0:
7026
+ preparedData = {
7027
+ signing_domain: data.signingDomain,
7028
+ selector: data.selector,
7029
+ };
7030
+ if (data.bits) {
7031
+ preparedData.bits = data.bits;
7032
+ }
7033
+ if (data.pem) {
7034
+ preparedData.pem = data.pem;
7035
+ }
7036
+ return [4 /*yield*/, this.request.postWithFD(urljoin('v1/dkim/keys'), preparedData)];
7037
+ case 1:
7038
+ res = _a.sent();
7039
+ return [2 /*return*/, __assign({ status: res.status }, res.body)];
7040
+ }
7041
+ });
7042
+ });
7043
+ };
7044
+ DomainKeysClient.prototype.activate = function (domainName, selector) {
7045
+ return __awaiter(this, void 0, void 0, function () {
7046
+ var res;
7047
+ return __generator(this, function (_a) {
7048
+ switch (_a.label) {
7049
+ case 0: return [4 /*yield*/, this.request.put("/v4/domains/".concat(domainName, "/keys/").concat(selector, "/activate"))];
7050
+ case 1:
7051
+ res = _a.sent();
7052
+ return [2 /*return*/, __assign(__assign({}, res.body), { status: res.status })];
7053
+ }
7054
+ });
7055
+ });
7056
+ };
7057
+ DomainKeysClient.prototype.deactivate = function (domainName, selector) {
7058
+ return __awaiter(this, void 0, void 0, function () {
7059
+ var res;
7060
+ return __generator(this, function (_a) {
7061
+ switch (_a.label) {
7062
+ case 0: return [4 /*yield*/, this.request.put("/v4/domains/".concat(domainName, "/keys/").concat(selector, "/deactivate"))];
7063
+ case 1:
7064
+ res = _a.sent();
7065
+ return [2 /*return*/, __assign(__assign({}, res.body), { status: res.status })];
7066
+ }
7067
+ });
7068
+ });
7069
+ };
7070
+ DomainKeysClient.prototype.destroy = function (domain, selector) {
7071
+ return __awaiter(this, void 0, void 0, function () {
7072
+ var res;
7073
+ return __generator(this, function (_a) {
7074
+ switch (_a.label) {
7075
+ case 0: return [4 /*yield*/, this.request.delete(urljoin('v1/dkim/keys'), undefined, { signing_domain: domain, selector: selector })];
7076
+ case 1:
7077
+ res = _a.sent();
7078
+ return [2 /*return*/, res.body];
7079
+ }
7080
+ });
7081
+ });
7082
+ };
7083
+ DomainKeysClient.prototype.updateDKIMSelector = function (domain, data) {
7084
+ var _a;
7085
+ return __awaiter(this, void 0, void 0, function () {
7086
+ var options, res;
7087
+ return __generator(this, function (_b) {
7088
+ switch (_b.label) {
7089
+ case 0:
7090
+ options = { query: "dkim_selector=".concat(data.dkimSelector) };
7091
+ return [4 /*yield*/, this.request.put("/v3/domains/".concat(domain, "/dkim_selector"), {}, options)];
7092
+ case 1:
7093
+ res = _b.sent();
7094
+ return [2 /*return*/, {
7095
+ status: res.status,
7096
+ message: (_a = res === null || res === void 0 ? void 0 : res.body) === null || _a === void 0 ? void 0 : _a.message
7097
+ }];
7098
+ }
7099
+ });
7100
+ });
7101
+ };
7102
+ DomainKeysClient.prototype.updateDKIMAuthority = function (domain, data) {
7103
+ return __awaiter(this, void 0, void 0, function () {
7104
+ var options;
7105
+ return __generator(this, function (_a) {
7106
+ options = { query: "self=".concat(data.self) };
7107
+ return [2 /*return*/, this.request.put("/v3/domains/".concat(domain, "/dkim_authority"), {}, options)
7108
+ .then(function (res) { return res; })
7109
+ .then(function (res) { return res.body; })];
7110
+ });
7111
+ });
7112
+ };
7113
+ return DomainKeysClient;
7114
+ }(NavigationThruPages));
7115
+
6875
7116
  var MailgunClient = /** @class */ (function () {
6876
7117
  function MailgunClient(options, formData) {
6877
7118
  var config = __assign({}, options);
@@ -6894,6 +7135,7 @@ var MailgunClient = /** @class */ (function () {
6894
7135
  var domainTemplatesClient = new DomainTemplatesClient(this.request);
6895
7136
  var domainTagsClient = new DomainTagsClient(this.request);
6896
7137
  var domainTrackingClient = new DomainTrackingClient(this.request);
7138
+ var domainKeysClient = new DomainKeysClient(this.request);
6897
7139
  var multipleValidationClient = new MultipleValidationClient(this.request);
6898
7140
  var InboxPlacementsResultsSharingClient = new IPRSharingClient(this.request);
6899
7141
  var seedsListsAttributes = new InboxPlacementsAttributesClient(this.request, '/v4/inbox/seedlists/a');
@@ -6903,7 +7145,7 @@ var MailgunClient = /** @class */ (function () {
6903
7145
  var seedsListsClient = new SeedsListsClient(this.request, seedsListsAttributes, seedsListsFiltersClient);
6904
7146
  var inboxPlacementsResultsClient = new InboxPlacementsResultsClient(this.request, resultsAttributesClient, resultsFiltersClient, InboxPlacementsResultsSharingClient);
6905
7147
  var inboxPlacementsProvidersClient = new InboxPlacementsProvidersClient(this.request);
6906
- this.domains = new DomainsClient(this.request, domainCredentialsClient, domainTemplatesClient, domainTagsClient, domainTrackingClient);
7148
+ this.domains = new DomainsClient(this.request, domainCredentialsClient, domainTemplatesClient, domainTagsClient, domainTrackingClient, domainKeysClient);
6907
7149
  this.webhooks = new WebhooksClient(this.request);
6908
7150
  this.events = new EventClient(this.request);
6909
7151
  this.stats = new StatsClient(this.request);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mailgun.js",
3
- "version": "12.2.0",
3
+ "version": "12.3.0",
4
4
  "author": "Mailgun",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/version.md CHANGED
@@ -1 +1 @@
1
- 12.2.0
1
+ 12.3.0