mailgun.js 7.0.2 → 8.0.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/README.md CHANGED
@@ -110,6 +110,7 @@ The following service methods are available to instantiated clients. The example
110
110
  - [createMembers](#createmembers)
111
111
  - [updateMember](#updatemember)
112
112
  - [destroyMember](#destroymember)
113
+ - [Navigation thru lists](#navigation-thru-lists)
113
114
  - [Browser Demo](#browser-demo)
114
115
  - [Development](#development)
115
116
  - [Requirements](#requirements)
@@ -138,6 +139,7 @@ Parameter | Description
138
139
  to | Email address of the recipient(s). Example: "Bob <bob@host.com>". You can use commas to separate multiple recipients (e.g.: "test@example.com,test@example.com" or ["test@example.com", "test@example.com"]).
139
140
  cc | Same as `To` but for `carbon copy`
140
141
  bcc | Same as `To` but for `blind carbon copy`
142
+ subject | Subject of the message.
141
143
  html | HTML version of the message.
142
144
  text | Text version of the message.
143
145
  message | MIME string of the message. Make sure to use multipart/form-data to send this as a file upload.
@@ -165,7 +167,7 @@ v:my-var | v: prefix followed by an arbitrary name allows to attach a c
165
167
  html: "<h1>Testing some Mailgun awesomness!</h1>"
166
168
  })
167
169
  .then(msg => console.log(msg)) // logs response data
168
- .catch(err => console.log(err)); // logs any error
170
+ .catch(err => console.error(err)); // logs any error
169
171
  ```
170
172
 
171
173
  - MIME Example:
@@ -178,7 +180,7 @@ v:my-var | v: prefix followed by an arbitrary name allows to attach a c
178
180
  message: "<mime encoded string here>"
179
181
  })
180
182
  .then(msg => console.log(msg)) // logs response data
181
- .catch(err => console.log(err)); // logs any error
183
+ .catch(err => console.error(err)); // logs any error
182
184
  ```
183
185
 
184
186
  Messages with attachments:
@@ -399,14 +401,14 @@ Recipient Variables are custom variables that you define, which you can then ref
399
401
 
400
402
  #### list
401
403
 
402
- `mg.domains.list(query)` - [api docs](https://documentation.mailgun.com/api-domains.html)
404
+ `mg.domains.list(query)` - [api docs](https://documentation.mailgun.com/en/latest/api-domains.html)
403
405
 
404
406
  Example:
405
407
 
406
408
  ```js
407
409
  mg.domains.list()
408
410
  .then(domains => console.log(domains)) // logs array of domains
409
- .catch(err => console.log(err)); // logs any error
411
+ .catch(err => console.error(err)); // logs any error
410
412
  ```
411
413
 
412
414
  Promise Returns: array of Domain instances
@@ -444,7 +446,7 @@ Example:
444
446
  ```js
445
447
  mg.domains.get()
446
448
  .then(domains => console.log(domains)) // logs array of domains
447
- .catch(err => console.log(err)); // logs any error
449
+ .catch(err => console.error(err)); // logs any error
448
450
  ```
449
451
 
450
452
  Promise Returns: Domain instance
@@ -503,7 +505,7 @@ Example:
503
505
  ```js
504
506
  mg.domains.create({name: 'foobar.example.com'})
505
507
  .then(msg => console.log(msg)) // logs response data
506
- .catch(err => console.log(err)); // logs any error
508
+ .catch(err => console.error(err)); // logs any error
507
509
  ```
508
510
 
509
511
  Options:
@@ -570,7 +572,7 @@ Example:
570
572
  ```js
571
573
  mg.domains.destroy('foobar.example.com')
572
574
  .then(msg => console.log(msg)) // logs response data
573
- .catch(err => console.log(err)); // logs any error
575
+ .catch(err => console.error(err)); // logs any error
574
576
  ```
575
577
 
576
578
  Promise Returns:
@@ -590,7 +592,7 @@ Example:
590
592
  ```js
591
593
  mg.domains.getTracking('foobar.example.com')
592
594
  .then(msg => console.log(msg)) // logs response data
593
- .catch(err => console.log(err)); // logs any error
595
+ .catch(err => console.error(err)); // logs any error
594
596
  ```
595
597
 
596
598
  Promise Returns:
@@ -620,7 +622,7 @@ Open Tracking Example:
620
622
  ```js
621
623
  mg.domains.updateTracking('foobar.example.com', 'open', {active: true})
622
624
  .then(msg => console.log(msg)) // logs response data
623
- .catch(err => console.log(err)); // logs any error
625
+ .catch(err => console.error(err)); // logs any error
624
626
  ```
625
627
 
626
628
  Open Tracking Options
@@ -645,7 +647,7 @@ Click Tracking Example:
645
647
  ```js
646
648
  mg.domains.updateTracking('foobar.example.com', 'click', {active: true})
647
649
  .then(msg => console.log(msg)) // logs response data
648
- .catch(err => console.log(err)); // logs any error
650
+ .catch(err => console.error(err)); // logs any error
649
651
  ```
650
652
 
651
653
  Click Tracking Options
@@ -674,7 +676,7 @@ mg.domains.updateTracking('foobar.example.com', 'unsubscribe', {
674
676
  text_footer: "\n\nTo unsubscribe click: <%unsubscribe_url%>\n\n"
675
677
  })
676
678
  .then(msg => console.log(msg)) // logs response data
677
- .catch(err => console.log(err)); // logs any error
679
+ .catch(err => console.error(err)); // logs any error
678
680
  ```
679
681
 
680
682
  Unsubscribe Tracking Options
@@ -706,7 +708,7 @@ Example:
706
708
  ```js
707
709
  mg.domains.getIps('foobar.example.com')
708
710
  .then(msg => console.log(msg)) // logs response data
709
- .catch(err => console.log(err)); // logs any error
711
+ .catch(err => console.error(err)); // logs any error
710
712
  ```
711
713
 
712
714
  Promise Returns:
@@ -724,7 +726,7 @@ Example:
724
726
  ```js
725
727
  mg.domains.assignIp('foobar.example.com', "192.168.0.3")
726
728
  .then(msg => console.log(msg)) // logs response data
727
- .catch(err => console.log(err)); // logs any error
729
+ .catch(err => console.error(err)); // logs any error
728
730
  ```
729
731
 
730
732
 
@@ -743,7 +745,7 @@ Example:
743
745
  ```js
744
746
  mg.domains.deleteIp('foobar.example.com', "192.168.0.3")
745
747
  .then(msg => console.log(msg)) // logs response data
746
- .catch(err => console.log(err)); // logs any error
748
+ .catch(err => console.error(err)); // logs any error
747
749
  ```
748
750
 
749
751
 
@@ -765,7 +767,7 @@ Example:
765
767
  ```js
766
768
  mg.events.get('foobar.example.com', { page: 'mypageid' })
767
769
  .then(data => console.log(data.items)) // logs array of event objects
768
- .catch(err => console.log(err)); // logs any error
770
+ .catch(err => console.error(err)); // logs any error
769
771
  ```
770
772
 
771
773
  Options:
@@ -845,7 +847,7 @@ Example:
845
847
  ```js
846
848
  mg.stats.getDomain('foobar.example.com', {event: ['delivered', 'accepted', 'failed', 'complained']})
847
849
  .then(msg => console.log(msg)) // logs response data
848
- .catch(err => console.log(err)); // logs any error
850
+ .catch(err => console.error(err)); // logs any error
849
851
  ```
850
852
 
851
853
  Promise Returns:
@@ -871,7 +873,7 @@ Example:
871
873
  ```js
872
874
  mg.stats.getDomain('foobar.example.com', {event: ['delivered', 'accepted', 'failed', 'complained']})
873
875
  .then(msg => console.log(msg)) // logs response data
874
- .catch(err => console.log(err)); // logs any error
876
+ .catch(err => console.error(err)); // logs any error
875
877
  ```
876
878
 
877
879
  Promise Returns:
@@ -899,7 +901,7 @@ Bounces Example:
899
901
  ```js
900
902
  mg.suppressions.list('foobar.example.com', 'bounces')
901
903
  .then(msg => console.log(msg)) // logs response data
902
- .catch(err => console.log(err)); // logs any error
904
+ .catch(err => console.error(err)); // logs any error
903
905
  ```
904
906
 
905
907
  Unsubscribes Example:
@@ -907,7 +909,7 @@ Unsubscribes Example:
907
909
  ```js
908
910
  mg.suppressions.list('foobar.example.com', 'unsubscribes')
909
911
  .then(msg => console.log(msg)) // logs response data
910
- .catch(err => console.log(err)); // logs any error
912
+ .catch(err => console.error(err)); // logs any error
911
913
  ```
912
914
 
913
915
  Complaints Example:
@@ -915,7 +917,7 @@ Complaints Example:
915
917
  ```js
916
918
  mg.suppressions.list('foobar.example.com', 'complaints')
917
919
  .then(msg => console.log(msg)) // logs response data
918
- .catch(err => console.log(err)); // logs any error
920
+ .catch(err => console.error(err)); // logs any error
919
921
  ```
920
922
 
921
923
  Promise Returns:
@@ -949,7 +951,7 @@ Bounces Example:
949
951
  ```js
950
952
  mg.suppressions.get('foobar.example.com', 'bounces', 'address@example.com')
951
953
  .then(msg => console.log(msg)) // logs response data
952
- .catch(err => console.log(err)); // logs any error
954
+ .catch(err => console.error(err)); // logs any error
953
955
  ```
954
956
 
955
957
  Unsubscribes Example:
@@ -957,7 +959,7 @@ Unsubscribes Example:
957
959
  ```js
958
960
  mg.suppressions.get('foobar.example.com', 'unsubscribes', 'address@example.com')
959
961
  .then(msg => console.log(msg)) // logs response data
960
- .catch(err => console.log(err)); // logs any error
962
+ .catch(err => console.error(err)); // logs any error
961
963
  ```
962
964
 
963
965
  Complaints Example:
@@ -965,7 +967,7 @@ Complaints Example:
965
967
  ```js
966
968
  mg.suppressions.get('foobar.example.com', 'complaints', 'address@example.com')
967
969
  .then(msg => console.log(msg)) // logs response data
968
- .catch(err => console.log(err)); // logs any error
970
+ .catch(err => console.error(err)); // logs any error
969
971
  ```
970
972
 
971
973
  Options:
@@ -990,7 +992,7 @@ Bounces Example:
990
992
  ```js
991
993
  mg.suppressions.create('foobar.example.com', 'bounces', [{address: 'bob@example.com'}])
992
994
  .then(msg => console.log(msg)) // logs response data
993
- .catch(err => console.log(err)); // logs any error
995
+ .catch(err => console.error(err)); // logs any error
994
996
  ```
995
997
 
996
998
  Bounces Options: Contains an array with the following object properties
@@ -1015,7 +1017,7 @@ Unsubscribes Example:
1015
1017
  ```js
1016
1018
  mg.suppressions.create('foobar.example.com', 'unsubscribes', [{address: 'bob@example.com'}])
1017
1019
  .then(msg => console.log(msg)) // logs response data
1018
- .catch(err => console.log(err)); // logs any error
1020
+ .catch(err => console.error(err)); // logs any error
1019
1021
  ```
1020
1022
 
1021
1023
  Unsubscribes Options: Contains an array with the following object properties
@@ -1039,7 +1041,7 @@ Complaints Example:
1039
1041
  ```js
1040
1042
  mg.suppressions.create('foobar.example.com', 'complaints', [{address: 'bob@example.com'}])
1041
1043
  .then(msg => console.log(msg)) // logs response data
1042
- .catch(err => console.log(err)); // logs any error
1044
+ .catch(err => console.error(err)); // logs any error
1043
1045
  ```
1044
1046
 
1045
1047
  Complaints Options: Contains an array with the following object properties
@@ -1068,7 +1070,7 @@ Example:
1068
1070
  ```js
1069
1071
  mg.webhooks.list('foobar.example.com')
1070
1072
  .then(msg => console.log(msg)) // logs response data
1071
- .catch(err => console.log(err)); // logs any error
1073
+ .catch(err => console.error(err)); // logs any error
1072
1074
  ```
1073
1075
 
1074
1076
  Promise Returns:
@@ -1096,7 +1098,7 @@ Example:
1096
1098
  ```js
1097
1099
  mg.webhooks.get('foobar.example.com', 'open') // bounce, deliver, drop, spam, unsubscribe, click, open
1098
1100
  .then(msg => console.log(msg)) // logs response data
1099
- .catch(err => console.log(err)); // logs any error
1101
+ .catch(err => console.error(err)); // logs any error
1100
1102
  ```
1101
1103
 
1102
1104
  Promise Returns:
@@ -1116,7 +1118,7 @@ Example:
1116
1118
  ```js
1117
1119
  mg.webhooks.create('foobar.example.com', 'open', 'http://requestb.in') // bounce, deliver, drop, spam, unsubscribe, click, open
1118
1120
  .then(msg => console.log(msg)) // logs response data
1119
- .catch(err => console.log(err)); // logs any error
1121
+ .catch(err => console.error(err)); // logs any error
1120
1122
  ```
1121
1123
 
1122
1124
  Promise Returns:
@@ -1132,7 +1134,7 @@ Test Webhook Example:
1132
1134
  ```js
1133
1135
  mg.webhooks.get('foobar.example.com', 'open', 'http://requestb.in', true) // bounce, deliver, drop, spam, unsubscribe, click, open
1134
1136
  .then(msg => console.log(msg)) // logs response data
1135
- .catch(err => console.log(err)); // logs any error
1137
+ .catch(err => console.error(err)); // logs any error
1136
1138
  ```
1137
1139
 
1138
1140
  Promise Returns:
@@ -1153,7 +1155,7 @@ Example:
1153
1155
  ```js
1154
1156
  mg.webhooks.update('foobar.example.com', 'open', 'http://requestb.in') // bounce, deliver, drop, spam, unsubscribe, click, open
1155
1157
  .then(msg => console.log(msg)) // logs response data
1156
- .catch(err => console.log(err)); // logs any error
1158
+ .catch(err => console.error(err)); // logs any error
1157
1159
  ```
1158
1160
 
1159
1161
  Promise Returns:
@@ -1173,7 +1175,7 @@ Example:
1173
1175
  ```js
1174
1176
  mg.webhooks.update('foobar.example.com', 'open') // bounce, deliver, drop, spam, unsubscribe, click, open
1175
1177
  .then(msg => console.log(msg)) // logs response data
1176
- .catch(err => console.log(err)); // logs any error
1178
+ .catch(err => console.error(err)); // logs any error
1177
1179
  ```
1178
1180
 
1179
1181
  Promise Returns:
@@ -1195,7 +1197,7 @@ Example:
1195
1197
  ```js
1196
1198
  mg.routes.list()
1197
1199
  .then(data => console.log(data)) // logs response body
1198
- .catch(err => console.log(err)); // logs any error
1200
+ .catch(err => console.error(err)); // logs any error
1199
1201
  ```
1200
1202
 
1201
1203
  Promise Returns: response body
@@ -1222,7 +1224,7 @@ Example:
1222
1224
  ```js
1223
1225
  mg.routes.get('562da483125730608a7d1719')
1224
1226
  .then(data => console.log(data)) // logs response body
1225
- .catch(err => console.log(err)); // logs any error
1227
+ .catch(err => console.error(err)); // logs any error
1226
1228
  ```
1227
1229
 
1228
1230
  Promise Returns: response body
@@ -1252,7 +1254,7 @@ mg.routes.create({
1252
1254
  action: ['forward("http://myhost.com/messages/")', 'stop()']
1253
1255
  })
1254
1256
  .then(data => console.log(data)) // logs response body
1255
- .catch(err => console.log(err)); // logs any error
1257
+ .catch(err => console.error(err)); // logs any error
1256
1258
  ```
1257
1259
 
1258
1260
  Promise Returns: response body
@@ -1282,7 +1284,7 @@ mg.routes.update('562da483125730608a7d1719', {
1282
1284
  action: ['forward("http://myhost.com/messages/")', 'stop()']
1283
1285
  })
1284
1286
  .then(data => console.log(data)) // logs response body
1285
- .catch(err => console.log(err)); // logs any error
1287
+ .catch(err => console.error(err)); // logs any error
1286
1288
  ```
1287
1289
 
1288
1290
  Promise Returns: response body
@@ -1308,7 +1310,7 @@ Example:
1308
1310
  ```js
1309
1311
  mg.routes.destroy('562da483125730608a7d1719')
1310
1312
  .then(data => console.log(data)) // logs response body
1311
- .catch(err => console.log(err)); // logs any error
1313
+ .catch(err => console.error(err)); // logs any error
1312
1314
  ```
1313
1315
 
1314
1316
  Promise Returns: response body
@@ -1331,7 +1333,7 @@ Example:
1331
1333
  ```js
1332
1334
  mg.validate.get('foo@mailgun.net')
1333
1335
  .then(data => console.log(data)) // logs response body
1334
- .catch(err => console.log(err)); // logs any error
1336
+ .catch(err => console.error(err)); // logs any error
1335
1337
  ```
1336
1338
 
1337
1339
  Promise Returns: response body
@@ -1386,7 +1388,7 @@ Response shape:
1386
1388
  ```js
1387
1389
  mg.validate.multipleValidation.list()
1388
1390
  .then(data => console.log(data)) // logs response body
1389
- .catch(err => console.log(err)); // logs any error
1391
+ .catch(err => console.error(err)); // logs any error
1390
1392
  ```
1391
1393
 
1392
1394
  Response shape:
@@ -1432,7 +1434,7 @@ Response shape:
1432
1434
  ```js
1433
1435
  mg.validate.multipleValidation.get('name_of_the_list')
1434
1436
  .then(data => console.log(data)) // logs response body
1435
- .catch(err => console.log(err)); // logs any error
1437
+ .catch(err => console.error(err)); // logs any error
1436
1438
  ```
1437
1439
 
1438
1440
  Response shape:
@@ -1469,7 +1471,7 @@ cancels bulk validation job
1469
1471
  ```js
1470
1472
  mg.validate.multipleValidation.destroy('name_of_the_list');
1471
1473
  .then(data => console.log(data)) // logs response body
1472
- .catch(err => console.log(err)); // logs any error
1474
+ .catch(err => console.error(err)); // logs any error
1473
1475
  ```
1474
1476
 
1475
1477
  Response shape:
@@ -1493,7 +1495,7 @@ Example:
1493
1495
  ```js
1494
1496
  mg.lists.list()
1495
1497
  .then(data => console.log(data)) // logs response body
1496
- .catch(err => console.log(err)); // logs any error
1498
+ .catch(err => console.error(err)); // logs any error
1497
1499
  ```
1498
1500
 
1499
1501
  Promise Returns: response body
@@ -1521,7 +1523,7 @@ Example:
1521
1523
  ```js
1522
1524
  mg.lists.get('noreply@sample.com')
1523
1525
  .then(data => console.log(data)) // logs response body
1524
- .catch(err => console.log(err)); // logs any error
1526
+ .catch(err => console.error(err)); // logs any error
1525
1527
  ```
1526
1528
 
1527
1529
  Promise Returns: response body
@@ -1553,7 +1555,7 @@ mg.lists.create({
1553
1555
  reply_preference: 'list', // optional, modifiable on website
1554
1556
  })
1555
1557
  .then(data => console.log(data)) // logs response body
1556
- .catch(err => console.log(err)); // logs any error
1558
+ .catch(err => console.error(err)); // logs any error
1557
1559
  ```
1558
1560
 
1559
1561
  Promise Returns: response body
@@ -1585,7 +1587,7 @@ mg.lists.update('reply@sample.com', {
1585
1587
  reply_preference: 'sender', // optional, modifiable on website
1586
1588
  })
1587
1589
  .then(data => console.log(data)) // logs response body
1588
- .catch(err => console.log(err)); // logs any error
1590
+ .catch(err => console.error(err)); // logs any error
1589
1591
  ```
1590
1592
 
1591
1593
  Promise Returns: response body
@@ -1611,7 +1613,7 @@ Example:
1611
1613
  ```js
1612
1614
  mg.lists.destroy('foo@sample.com')
1613
1615
  .then(data => console.log(data)) // logs response body
1614
- .catch(err => console.log(err)); // logs any error
1616
+ .catch(err => console.error(err)); // logs any error
1615
1617
  ```
1616
1618
 
1617
1619
  Promise Returns: response body
@@ -1636,7 +1638,7 @@ Example:
1636
1638
  ```js
1637
1639
  mg.lists.members.listMembers('reply@sample.com')
1638
1640
  .then(data => console.log(data)) // logs response body
1639
- .catch(err => console.log(err)); // logs any error
1641
+ .catch(err => console.error(err)); // logs any error
1640
1642
  ```
1641
1643
 
1642
1644
  Promise Returns: response body
@@ -1661,7 +1663,7 @@ Example:
1661
1663
  ```js
1662
1664
  mg.lists.members.getMember('reply@sample.com', 'foo@bar.com')
1663
1665
  .then(data => console.log(data)) // logs response body
1664
- .catch(err => console.log(err)); // logs any error
1666
+ .catch(err => console.error(err)); // logs any error
1665
1667
  ```
1666
1668
 
1667
1669
  Promise Returns: response body
@@ -1690,7 +1692,7 @@ mg.lists.members.createMember('reply@sample.com', {
1690
1692
  upsert: 'yes', // optional, choose yes to insert if not exist, or update it exist
1691
1693
  })
1692
1694
  .then(data => console.log(data)) // logs response body
1693
- .catch(err => console.log(err)); // logs any error
1695
+ .catch(err => console.error(err)); // logs any error
1694
1696
  ```
1695
1697
 
1696
1698
  Promise Returns: response body
@@ -1729,7 +1731,7 @@ mg.lists.members.createMembers('reply@sample.com', {
1729
1731
  upsert: "yes",
1730
1732
  })
1731
1733
  .then(data => console.log(data)) // logs response body
1732
- .catch(err => console.log(err)); // logs any error
1734
+ .catch(err => console.error(err)); // logs any error
1733
1735
  ```
1734
1736
 
1735
1737
  Promise Returns: response body
@@ -1764,7 +1766,7 @@ mg.lists.members.updateMember('reply@sample.com', 'bot1@foobar.com', {
1764
1766
  subscribed: false,
1765
1767
  })
1766
1768
  .then(data => console.log(data)) // logs response body
1767
- .catch(err => console.log(err)); // logs any error
1769
+ .catch(err => console.error(err)); // logs any error
1768
1770
  ```
1769
1771
 
1770
1772
  Promise Returns: response body
@@ -1787,18 +1789,183 @@ Example:
1787
1789
  ```js
1788
1790
  mg.lists.members.destroyMember('reply@sample.com', 'bot2@foobar.com')
1789
1791
  .then(data => console.log(data)) // logs response body
1790
- .catch(err => console.log(err)); // logs any error
1792
+ .catch(err => console.error(err)); // logs any error
1791
1793
  ```
1792
1794
 
1793
1795
  Promise Returns: response body
1794
1796
 
1795
- ```
1797
+ ```js
1796
1798
  {
1797
1799
  member: { address: 'bot2@foobar.com' },
1798
1800
  message: 'Mailing list member has been deleted'
1799
1801
  }
1800
1802
  ```
1801
1803
 
1804
+ ## Navigation thru lists
1805
+ Most of the methods that return items in a list support pagination.
1806
+ There are two ways to receive part of the list:
1807
+ 1. Provide properties 'limit' and 'page' in the query.
1808
+ This way uses more frequently in the SDK and works for the next methods:
1809
+ - mg.domains.domainTags.list()
1810
+ - mg.domains.domainTemplates.list()
1811
+ - mg.domains.domainTemplates.listVersions()
1812
+ - mg.events.get()
1813
+ - mg.lists.list()
1814
+ - mg.lists.members.listMembers()
1815
+ - mg.validate.list()
1816
+ - mg.suppressions.list()
1817
+
1818
+ The general idea is that after you made the first call with a limit property in the query you will receive a response with a property called pages in it. This property implements the next interface:
1819
+
1820
+ ```TS
1821
+ {
1822
+ previous: {
1823
+ id: string;
1824
+ page: string;
1825
+ iteratorPosition: string | undefined;
1826
+ url: string
1827
+ };
1828
+ first: {
1829
+ id: string;
1830
+ page: string;
1831
+ iteratorPosition: string | undefined;
1832
+ url: string
1833
+ };
1834
+ last: {
1835
+ id: string;
1836
+ page: string;
1837
+ iteratorPosition: string | undefined;
1838
+ url: string
1839
+ };
1840
+ next: {
1841
+ id: string;
1842
+ page: string;
1843
+ iteratorPosition: string | undefined;
1844
+ url: string
1845
+ };
1846
+ }
1847
+ ```
1848
+ To receive the next page you need to add the page property to the query argument. This property should contain a string value from 'page' property in response.pages.(previous/first/last/next).
1849
+
1850
+ Example:
1851
+ ```Js
1852
+ // first call
1853
+ const listMembers = await mg.lists.members.listMembers('your_mailing_list', { limit: 2 });
1854
+
1855
+ /* response
1856
+ {
1857
+ items: [
1858
+ {
1859
+ address: 'test-0@example.com',
1860
+ name: 'test name 0',
1861
+ subscribed: true,
1862
+ vars: [Object]
1863
+ },
1864
+ {
1865
+ address: 'test-1@example.com',
1866
+ name: 'test name 1',
1867
+ subscribed: true,
1868
+ vars: [Object]
1869
+ }
1870
+ ],
1871
+ pages: {
1872
+ first: {
1873
+ id: 'first',
1874
+ page: '?page=first&limit=2',
1875
+ iteratorPosition: undefined,
1876
+ url: 'https://your_domain/v3/lists/your_mailing_list/members/pages?page=first&limit=2'
1877
+ },
1878
+ last: {
1879
+ id: 'last',
1880
+ page: '?page=last&limit=2',
1881
+ iteratorPosition: undefined,
1882
+ url: 'https://your_domain/v3/lists/your_mailing_list/members/pages?page=last&limit=2'
1883
+ },
1884
+ next: {
1885
+ id: 'next',
1886
+ page: '?page=next&address=test-1%40example.com&limit=2',
1887
+ iteratorPosition: 'test-1@example.com',
1888
+ url: 'https://your_domain/v3/lists/your_mailing_list/members/pages?page=next&address=test-1%40example.com&limit=2'
1889
+ },
1890
+ previous: {
1891
+ id: 'previous',
1892
+ page: '?page=prev&address=test-0%40example.com&limit=2',
1893
+ iteratorPosition: 'test-0@example.com',
1894
+ url: 'https://your_domain/v3/lists/your_mailing_list/members/pages?page=prev&address=test-0%40example.com&limit=2'
1895
+ }
1896
+ }
1897
+ }
1898
+ */
1899
+ // second call
1900
+ const listMembers = await mg.lists.members.listMembers(
1901
+ 'your_mailing_list',
1902
+ {
1903
+ limit: 2,
1904
+ page: '?page=next&address=test-1%40example.com&limit=2'
1905
+ }
1906
+ );
1907
+
1908
+ /* response
1909
+ {
1910
+ items: [
1911
+ {
1912
+ address: 'test-2@example.com',
1913
+ name: 'test name 2',
1914
+ subscribed: true,
1915
+ vars: [Object]
1916
+ },
1917
+ {
1918
+ address: 'test-3@example.com',
1919
+ name: 'test name 3',
1920
+ subscribed: true,
1921
+ vars: [Object]
1922
+ }
1923
+ ],
1924
+ pages: {
1925
+ first: {
1926
+ id: 'first',
1927
+ page: '?page=first&limit=2',
1928
+ iteratorPosition: undefined,
1929
+ url: 'https://your_domain/v3/lists/your_mailing_list/members/pages?page=first&limit=2'
1930
+ },
1931
+ last: {
1932
+ id: 'last',
1933
+ page: '?page=last&limit=2',
1934
+ iteratorPosition: undefined,
1935
+ url: 'https://your_domain/v3/lists/your_mailing_list/members/pages?page=last&limit=2'
1936
+ },
1937
+ next: {
1938
+ id: 'next',
1939
+ page: '?page=next&address=test-3%40example.com&limit=2',
1940
+ iteratorPosition: 'test-3@example.com',
1941
+ url: 'https://your_domain/v3/lists/your_mailing_list/members/pages?page=next&address=test-3%40example.com&limit=2'
1942
+ },
1943
+ previous: {
1944
+ id: 'previous',
1945
+ page: '?page=prev&address=test-2%40example.com&limit=2',
1946
+ iteratorPosition: 'test-2@example.com',
1947
+ url: 'https://your_domain/v3/lists/your_mailing_list/members/pages?page=prev&address=test-2%40example.com&limit=2'
1948
+ }
1949
+ }
1950
+ }
1951
+ */
1952
+ ```
1953
+ 2. The second option of navigation is to provide properties 'limit' and 'skip' in the query. This way uses only in a few places for now:
1954
+ - mg.domains.list()
1955
+ - mg.domains.domainCredentials.list()
1956
+ - mg.routes.list()
1957
+ - mg.webhooks.list()
1958
+ The main idea here is quite simple you just need to provide how many records from the start of a list you want to skip and how many to receive. You can do it using the query parameter in each method.
1959
+ Example:
1960
+ ```js
1961
+ const listDomainCredentials = await client.domains.domainCredentials.list(
1962
+ 'your_domain_name',
1963
+ {
1964
+ skip: 10,
1965
+ limit: 1
1966
+ }
1967
+ );
1968
+ ```
1802
1969
 
1803
1970
 
1804
1971
  ## Browser Demo
@@ -0,0 +1,19 @@
1
+ import { ParsedPage, ParsedPagesList, QueryWithPage, ResponseWithPaging } from '../interfaces/NavigationThruPages';
2
+ import { BounceData, IBounce } from '../interfaces/Suppressions/Bounce';
3
+ import { ComplaintData, IComplaint } from '../interfaces/Suppressions/Complaint';
4
+ import { IUnsubscribe, UnsubscribeData } from '../interfaces/Suppressions/Unsubscribe';
5
+ import { IWhiteList, WhiteListData } from '../interfaces/Suppressions/WhiteList';
6
+ import Request from '../request';
7
+ export default abstract class NavigationThruPages<T> {
8
+ request?: Request;
9
+ constructor(request?: Request);
10
+ protected parsePage(id: string, pageUrl: string, urlSeparator: string, iteratorName: string | undefined): ParsedPage;
11
+ protected parsePageLinks(response: ResponseWithPaging, urlSeparator: string, iteratorName?: string): ParsedPagesList;
12
+ private updateUrlAndQuery;
13
+ protected requestListWithPages(clientUrl: string, query?: QueryWithPage, Model?: {
14
+ new (data: BounceData | ComplaintData | UnsubscribeData | WhiteListData): IBounce | IComplaint | IUnsubscribe | IWhiteList;
15
+ }): Promise<T>;
16
+ protected abstract parseList(response: ResponseWithPaging, Model?: {
17
+ new (data: BounceData | ComplaintData | UnsubscribeData | WhiteListData): IBounce | IComplaint | IUnsubscribe | IWhiteList;
18
+ }): T;
19
+ }
package/domainsTags.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import Request from './request';
2
- import { DomainTagCountriesAggregation, DomainTagDevicesAggregation, DomainTagProvidersAggregation, DomainTagsItem, DomainTagsItemInfo, DomainTagsList, DomainTagsMessageRes, DomainTagsQuery, DomainTagsStatisticQuery, DomainTagStatAPIResponse, DomainTagStatisticItem, DomainTagStatisticResult, IDomainTagsClient, Resolution } from './interfaces/DomainTags';
2
+ import { DomainTagCountriesAggregation, DomainTagDevicesAggregation, DomainTagProvidersAggregation, DomainTagsItem, DomainTagsItemInfo, DomainTagsList, DomainTagsMessageRes, DomainTagsQuery, DomainTagsResponseData, DomainTagsStatisticQuery, DomainTagStatAPIResponse, DomainTagStatisticItem, DomainTagStatisticResult, IDomainTagsClient, Resolution } from './interfaces/DomainTags';
3
+ import NavigationThruPages from './common/NavigationThruPages';
3
4
  export declare class DomainTag implements DomainTagsItem {
4
5
  tag: string;
5
6
  description: string;
@@ -16,12 +17,11 @@ export declare class DomainTagStatistic implements DomainTagStatisticResult {
16
17
  stats: DomainTagStatisticItem[];
17
18
  constructor(tagStatisticInfo: DomainTagStatAPIResponse);
18
19
  }
19
- export default class DomainTagsClient implements IDomainTagsClient {
20
+ export default class DomainTagsClient extends NavigationThruPages<DomainTagsList> implements IDomainTagsClient {
20
21
  baseRoute: string;
21
22
  request: Request;
22
23
  constructor(request: Request);
23
- private _parsePageLinks;
24
- private _parseDomainTagsList;
24
+ protected parseList(response: DomainTagsResponseData): DomainTagsList;
25
25
  private _parseTagStatistic;
26
26
  list(domain: string, query?: DomainTagsQuery): Promise<DomainTagsList>;
27
27
  get(domain: string, tag: string): Promise<DomainTagsItem>;