@brickert/kerio-connect-api 0.0.8 → 0.0.9

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/index.d.ts CHANGED
@@ -178,7 +178,7 @@ export class IPAddressGroup extends KerioModules {
178
178
  * Obtain a Mapped Array of IPAddressGroupItem indexed by their ID for the specified group name
179
179
  * @param group_name Name of the IPAddressGroup
180
180
  */
181
- listIPAddressItemsByGroupName(group_name: string): Promise<Map<KerioIPAddressID, IPAddressGroupItem>>;
181
+ listByGroupName(group_name: string): Promise<Map<KerioIPAddressID, IPAddressGroupItem>>;
182
182
 
183
183
  /**
184
184
  * Add a IPAddressGroupItem of type 'host' of a single IP Address, with a specified description name, within a specified group name, and whether to have it enabled.
@@ -189,7 +189,7 @@ export class IPAddressGroup extends KerioModules {
189
189
  * @param enabled True to enable this host in the group
190
190
  * @returns Provides the unique KerioID of this host entry
191
191
  */
192
- addHostToIPAddressGroup(host_ip: string, description: string, group_name: string, enabled: boolean): Promise<KerioIPAddressID>;
192
+ addHost(host_ip: string, description: string, group_name: string, enabled: boolean): Promise<KerioIPAddressID>;
193
193
 
194
194
  /**
195
195
  * Remove this IPAddressGroupItem of type 'host' of a single IP Address from this group name
@@ -197,7 +197,7 @@ export class IPAddressGroup extends KerioModules {
197
197
  * @param group_name Name of the IPAddressGroup string to remove this host in
198
198
  * @returns Returns True when removal was successful
199
199
  */
200
- removeHostFromIPAddressGroupByIP(host_ip: string, group_name: string): Promise<boolean>;
200
+ removeHostByIP(host_ip: string, group_name: string): Promise<boolean>;
201
201
 
202
202
  /**
203
203
  * Remove IPAddressGroupItem(s) of type 'host' by the description name from this group name. TAKE CARE as this will remove all items upto the specified max limit that share the same name. You may limit number of items to remove. They are sorted by their unique ID.
@@ -206,8 +206,14 @@ export class IPAddressGroup extends KerioModules {
206
206
  * @param remove_limit Max number of group items to remove upto. Specifying -1 will remove ALL by the description name
207
207
  * @returns Returns an array of host IP addresses that were removed
208
208
  */
209
- removeHostFromIPAddressGroupByDesc(description: string, group_name: string, remove_limit: number): Promise<Array<KerioIPAddressHost>>;
209
+ removeHostByDesc(description: string, group_name: string, remove_limit: number): Promise<Array<KerioIPAddressHost>>;
210
210
 
211
+ /**
212
+ * Remove IPAddressGroupItem by their unique ID
213
+ * @param KerioIPAddressID The unique ID for this entry obtained from Kerio.IPAddressGroup.listByGroupName
214
+ * @returns Returns True when removal was successful
215
+ */
216
+ removeHostByID(id: KerioIPAddressID): Promise<boolean>;
211
217
  }
212
218
 
213
219
  export type KerioIPAddressHost = string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brickert/kerio-connect-api",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "An unofficial API wrapper for Kerio Connect Mail Server jsonrpc Admin API.",
5
5
  "keywords": [
6
6
  "kerio",
@@ -10,7 +10,7 @@ export class IPAddressGroup extends KerioModules {
10
10
  * @param {string} group_name Name of the IPAddressGroup these items are a member of
11
11
  * @returns {Promise<Map<import('../index.d.ts').KerioIPAddressID, import('../index.d.ts').IPAddressGroupItem>>}
12
12
  */
13
- async listIPAddressItemsByGroupName(group_name = null) {
13
+ async listByGroupName(group_name = null) {
14
14
  try {
15
15
 
16
16
  if (!this.instance.logged_in) {
@@ -21,7 +21,7 @@ export class IPAddressGroup extends KerioModules {
21
21
  name: "KerioClientSessionError",
22
22
  message: `Kerio session invalid. Try logging in again.`,
23
23
  type: 'Kerio',
24
- from: "Kerio.IPAddressGroups.listIPAddressItemsByGroupName"
24
+ from: "Kerio.IPAddressGroups.listByGroupName"
25
25
  }
26
26
  }
27
27
 
@@ -31,7 +31,7 @@ export class IPAddressGroup extends KerioModules {
31
31
  name: "KerioInvalidIPAddressGroupNameError",
32
32
  message: `Invalid referred Group Name while processing API method 'IPAddressGroups.get' for name '${group_name}'`,
33
33
  type: 'Kerio',
34
- from: "Kerio.IPAddressGroups.listIPAddressItemsByGroupName"
34
+ from: "Kerio.IPAddressGroups.listByGroupName"
35
35
  }
36
36
  }
37
37
 
@@ -85,7 +85,7 @@ export class IPAddressGroup extends KerioModules {
85
85
  name: "KerioListIPAddressItems",
86
86
  message: `listed ${ipAddresslist.size} items in IPAddressGroup '${group_name}'`,
87
87
  type: 'Kerio',
88
- from: "Kerio.IPAddressGroups.listIPAddressItemsByGroupName"
88
+ from: "Kerio.IPAddressGroups.listByGroupName"
89
89
  });
90
90
 
91
91
  return ipAddresslist;
@@ -98,7 +98,7 @@ export class IPAddressGroup extends KerioModules {
98
98
  name: "KerioRequestError",
99
99
  message: `Error occured while fetching results from API method 'IPAddressGroups.get' by name of '${group_name}'`,
100
100
  type: 'Kerio',
101
- from: "Kerio.IPAddressGroups.listIPAddressItemsByGroupName"
101
+ from: "Kerio.IPAddressGroups.listByGroupName"
102
102
  }
103
103
  }
104
104
 
@@ -116,7 +116,7 @@ export class IPAddressGroup extends KerioModules {
116
116
  * @param {boolean} enabled Enabled or disabled for this entry, defaults true
117
117
  * @returns {Promise<import('../index.d.ts').KerioIPAddressID>}
118
118
  */
119
- async addHostToIPAddressGroup(host_ip, description = null, group_name = null, enabled = true) {
119
+ async addHost(host_ip, description = null, group_name = null, enabled = true) {
120
120
  try {
121
121
 
122
122
  if (!this.instance.logged_in) {
@@ -127,7 +127,7 @@ export class IPAddressGroup extends KerioModules {
127
127
  name: "KerioClientSessionError",
128
128
  message: `Kerio session invalid. Try logging in again.`,
129
129
  type: 'Kerio',
130
- from: "Kerio.IPAddressGroups.addHostToIPAddressGroup"
130
+ from: "Kerio.IPAddressGroups.addHost"
131
131
  }
132
132
  }
133
133
 
@@ -136,7 +136,7 @@ export class IPAddressGroup extends KerioModules {
136
136
  name: "KerioInvalidHostError",
137
137
  message: `Invalid Host IP while processing API method 'IPAddressGroups.create' for host '${host_ip}' in group '${group_name}'`,
138
138
  type: 'Kerio',
139
- from: "Kerio.IPAddressGroups.addHostToIPAddressGroup"
139
+ from: "Kerio.IPAddressGroups.addHost"
140
140
  }
141
141
  }
142
142
 
@@ -145,7 +145,7 @@ export class IPAddressGroup extends KerioModules {
145
145
  name: "KerioInvalidHostDescriptionError",
146
146
  message: `Invalid Description for IPAddressEntry while processing API method 'IPAddressGroups.create' for host '${host_ip}' in group '${group_name}'`,
147
147
  type: 'Kerio',
148
- from: "Kerio.IPAddressGroups.addHostToIPAddressGroup"
148
+ from: "Kerio.IPAddressGroups.addHost"
149
149
  }
150
150
  }
151
151
 
@@ -154,7 +154,7 @@ export class IPAddressGroup extends KerioModules {
154
154
  name: "KerioInvalidIPAddressGroupNameError",
155
155
  message: `Invalid referred Group Name while processing API method 'IPAddressGroups.create' for host '${host_ip}' in group '${group_name}'`,
156
156
  type: 'Kerio',
157
- from: "Kerio.IPAddressGroups.addHostToIPAddressGroup"
157
+ from: "Kerio.IPAddressGroups.addHost"
158
158
  }
159
159
  }
160
160
 
@@ -163,7 +163,7 @@ export class IPAddressGroup extends KerioModules {
163
163
  name: "KerioInvalidIPAddressEntryEnableError",
164
164
  message: `Invalid Enabled value while processing API method 'IPAddressGroups.create' for host '${host_ip}' in group '${group_name}'`,
165
165
  type: 'Kerio',
166
- from: "Kerio.IPAddressGroups.addHostToIPAddressGroup"
166
+ from: "Kerio.IPAddressGroups.addHost"
167
167
  }
168
168
  }
169
169
 
@@ -195,7 +195,7 @@ export class IPAddressGroup extends KerioModules {
195
195
  name: "KerioAddHostIPAddressGroup",
196
196
  message: `Added host ${host_ip} with description ${description} in IPAddressGroup '${group_name}'`,
197
197
  type: 'Kerio',
198
- from: "Kerio.IPAddressGroups.addHostToIPAddressGroup"
198
+ from: "Kerio.IPAddressGroups.addHost"
199
199
  });
200
200
 
201
201
  return response_body.result.result[0].id;
@@ -207,21 +207,21 @@ export class IPAddressGroup extends KerioModules {
207
207
  name: "KerioDuplicateError",
208
208
  message: `Duplicate Host IP while processing API method 'IPAddressGroups.create' for host '${host_ip}' in group '${group_name}'`,
209
209
  type: 'Kerio',
210
- from: "Kerio.IPAddressGroups.addHostToIPAddressGroup"
210
+ from: "Kerio.IPAddressGroups.addHost"
211
211
  }
212
212
  case 1003:
213
213
  throw {
214
214
  name: "KerioInvalidHostError",
215
215
  message: `Invalid Host IP while processing API method 'IPAddressGroups.create' for host '${host_ip}' in group '${group_name}'`,
216
216
  type: 'Kerio',
217
- from: "Kerio.IPAddressGroups.addHostToIPAddressGroup"
217
+ from: "Kerio.IPAddressGroups.addHost"
218
218
  }
219
219
  default:
220
220
  throw {
221
221
  name: "KerioRequestError",
222
222
  message: `Error occured while fetching results from API method 'IPAddressGroups.create' for host '${host_ip}' in group '${group_name}'`,
223
223
  type: 'Kerio',
224
- from: "Kerio.IPAddressGroups.addHostToIPAddressGroup"
224
+ from: "Kerio.IPAddressGroups.addHost"
225
225
  }
226
226
  }
227
227
  }
@@ -238,7 +238,7 @@ export class IPAddressGroup extends KerioModules {
238
238
  * @param {string} group_name IPAddressGroup name this host is a member of
239
239
  * @returns {Promise<boolean>} Returns true when removal was successful
240
240
  */
241
- async removeHostFromIPAddressGroupByIP(host_ip, group_name = null) {
241
+ async removeHostByIP(host_ip, group_name = null) {
242
242
  try {
243
243
 
244
244
  if (!this.instance.logged_in) {
@@ -249,7 +249,7 @@ export class IPAddressGroup extends KerioModules {
249
249
  name: "KerioClientSessionError",
250
250
  message: `Kerio session invalid. Try logging in again.`,
251
251
  type: 'Kerio',
252
- from: "Kerio.IPAddressGroups.removeHostFromIPAddressGroupByIP"
252
+ from: "Kerio.IPAddressGroups.removeHostByIP"
253
253
  }
254
254
  }
255
255
 
@@ -258,7 +258,7 @@ export class IPAddressGroup extends KerioModules {
258
258
  name: "KerioInvalidHostError",
259
259
  message: `Invalid Host IP while processing API method 'IPAddressGroups.remove' for host '${host_ip}' in group '${group_name}'`,
260
260
  type: 'Kerio',
261
- from: "Kerio.IPAddressGroups.removeHostFromIPAddressGroupByIP"
261
+ from: "Kerio.IPAddressGroups.removeHostByIP"
262
262
  }
263
263
  }
264
264
 
@@ -267,11 +267,11 @@ export class IPAddressGroup extends KerioModules {
267
267
  name: "KerioInvalidIPAddressGroupNameError",
268
268
  message: `Invalid referred Group Name while processing API method 'IPAddressGroups.remove' for host '${host_ip}' in group '${group_name}'`,
269
269
  type: 'Kerio',
270
- from: "Kerio.IPAddressGroups.removeHostFromIPAddressGroupByIP"
270
+ from: "Kerio.IPAddressGroups.removeHostByIP"
271
271
  }
272
272
  }
273
273
 
274
- let get_host_ID_response = await this.listIPAddressItemsByGroupName(group_name);
274
+ let get_host_ID_response = await this.listByGroupName(group_name);
275
275
 
276
276
  if (get_host_ID_response.size != 0) {
277
277
 
@@ -305,7 +305,7 @@ export class IPAddressGroup extends KerioModules {
305
305
  name: "KerioRemoveHostIPAddressGroup",
306
306
  message: `Removed host '${host_ip}' in group '${group_name}'`,
307
307
  type: 'Kerio',
308
- from: "Kerio.IPAddressGroups.removeHostFromIPAddressGroupByIP"
308
+ from: "Kerio.IPAddressGroups.removeHostByIP"
309
309
  });
310
310
 
311
311
  return true;
@@ -317,21 +317,21 @@ export class IPAddressGroup extends KerioModules {
317
317
  name: "KerioHostRemoveError",
318
318
  message: `Host does not exist within group while fetching results from API method 'IPAddressGroups.remove' for host '${host_ip}' in group '${group_name}'`,
319
319
  type: 'Kerio',
320
- from: "Kerio.IPAddressGroups.removeHostFromIPAddressGroupByIP"
320
+ from: "Kerio.IPAddressGroups.removeHostByIP"
321
321
  }
322
322
  case 1003:
323
323
  throw {
324
324
  name: "KerioHostRemoveError",
325
325
  message: `Host ID invalid while fetching results from API method 'IPAddressGroups.remove' for host '${host_ip}' in group '${group_name}'`,
326
326
  type: 'Kerio',
327
- from: "Kerio.IPAddressGroups.removeHostFromIPAddressGroupByIP"
327
+ from: "Kerio.IPAddressGroups.removeHostByIP"
328
328
  }
329
329
  default:
330
330
  throw {
331
331
  name: "KerioRequestError",
332
332
  message: `Error occured while fetching results from API method 'IPAddressGroups.remove' for host '${host_ip}' in group '${group_name}'`,
333
333
  type: 'Kerio',
334
- from: "Kerio.IPAddressGroups.removeHostFromIPAddressGroupByIP"
334
+ from: "Kerio.IPAddressGroups.removeHostByIP"
335
335
  }
336
336
  }
337
337
  }
@@ -340,7 +340,7 @@ export class IPAddressGroup extends KerioModules {
340
340
  name: "KerioHostNotExistError",
341
341
  message: `Host IP does not exist in group while processing API method 'IPAddressGroups.remove' for host '${host_ip}' in group '${group_name}'`,
342
342
  type: 'Kerio',
343
- from: "Kerio.IPAddressGroups.removeHostFromIPAddressGroupByIP"
343
+ from: "Kerio.IPAddressGroups.removeHostByIP"
344
344
  }
345
345
  }
346
346
  } else {
@@ -348,7 +348,7 @@ export class IPAddressGroup extends KerioModules {
348
348
  name: "KerioHostNotExistGroupError",
349
349
  message: `Group has no hosts while processing API method 'IPAddressGroups.remove' for host '${host_ip}' in group '${group_name}'`,
350
350
  type: 'Kerio',
351
- from: "Kerio.IPAddressGroups.removeHostFromIPAddressGroupByIP"
351
+ from: "Kerio.IPAddressGroups.removeHostByIP"
352
352
  }
353
353
  }
354
354
 
@@ -365,7 +365,7 @@ export class IPAddressGroup extends KerioModules {
365
365
  * @param {number} remove_limit Max number of group items to remove upto. Specifying -1 will remove ALL by the description name
366
366
  * @returns Returns an array of host IP addresses that were removed
367
367
  */
368
- async removeHostFromIPAddressGroupByDesc(description = null, group_name = null, remove_limit = 1) {
368
+ async removeHostByDesc(description = null, group_name = null, remove_limit = 1) {
369
369
  try {
370
370
 
371
371
  if (!this.instance.logged_in) {
@@ -376,7 +376,7 @@ export class IPAddressGroup extends KerioModules {
376
376
  name: "KerioClientSessionError",
377
377
  message: `Kerio session invalid. Try logging in again.`,
378
378
  type: 'Kerio',
379
- from: "Kerio.IPAddressGroups.removeHostFromIPAddressGroupByDesc"
379
+ from: "Kerio.IPAddressGroups.removeHostByDesc"
380
380
  }
381
381
  }
382
382
 
@@ -385,7 +385,7 @@ export class IPAddressGroup extends KerioModules {
385
385
  name: "KerioInvalidGroupEntryRemoveLimitError",
386
386
  message: `Invalid number of max host entries to remove while processing API method 'IPAddressGroups.remove' for description '${description}' in group '${group_name}'`,
387
387
  type: 'Kerio',
388
- from: "Kerio.IPAddressGroups.removeHostFromIPAddressGroupByDesc"
388
+ from: "Kerio.IPAddressGroups.removeHostByDesc"
389
389
  }
390
390
  }
391
391
 
@@ -394,7 +394,7 @@ export class IPAddressGroup extends KerioModules {
394
394
  name: "KerioInvalidGroupEntryDescriptionError",
395
395
  message: `Invalid Description to search query while processing API method 'IPAddressGroups.remove' for description '${description}' in group '${group_name}'`,
396
396
  type: 'Kerio',
397
- from: "Kerio.IPAddressGroups.removeHostFromIPAddressGroupByDesc"
397
+ from: "Kerio.IPAddressGroups.removeHostByDesc"
398
398
  }
399
399
  }
400
400
 
@@ -403,11 +403,11 @@ export class IPAddressGroup extends KerioModules {
403
403
  name: "KerioInvalidIPAddressGroupNameError",
404
404
  message: `Invalid referred Group Name while processing API method 'IPAddressGroups.remove' for description '${description}' in group '${group_name}'`,
405
405
  type: 'Kerio',
406
- from: "Kerio.IPAddressGroups.removeHostFromIPAddressGroupByDesc"
406
+ from: "Kerio.IPAddressGroups.removeHostByDesc"
407
407
  }
408
408
  }
409
409
 
410
- let get_host_ID_response = await this.listIPAddressItemsByGroupName(group_name);
410
+ let get_host_ID_response = await this.listByGroupName(group_name);
411
411
 
412
412
  if (get_host_ID_response.size != 0) {
413
413
 
@@ -453,21 +453,21 @@ export class IPAddressGroup extends KerioModules {
453
453
  name: "KerioHostRemoveError",
454
454
  message: `Host does not exist within group while fetching results from API method 'IPAddressGroups.remove' in group '${group_name}'`,
455
455
  type: 'Kerio',
456
- from: "Kerio.IPAddressGroups.removeHostFromIPAddressGroupByDesc"
456
+ from: "Kerio.IPAddressGroups.removeHostByDesc"
457
457
  }
458
458
  case 1003:
459
459
  throw {
460
460
  name: "KerioHostRemoveError",
461
461
  message: `Host ID invalid while fetching results from API method 'IPAddressGroups.remove' in group '${group_name}'`,
462
462
  type: 'Kerio',
463
- from: "Kerio.IPAddressGroups.removeHostFromIPAddressGroupByDesc"
463
+ from: "Kerio.IPAddressGroups.removeHostByDesc"
464
464
  }
465
465
  default:
466
466
  throw {
467
467
  name: "KerioRequestError",
468
468
  message: `Error occured while fetching results from API method 'IPAddressGroups.remove' in group '${group_name}'`,
469
469
  type: 'Kerio',
470
- from: "Kerio.IPAddressGroups.removeHostFromIPAddressGroupByDesc"
470
+ from: "Kerio.IPAddressGroups.removeHostByDesc"
471
471
  }
472
472
  }
473
473
  }
@@ -476,7 +476,7 @@ export class IPAddressGroup extends KerioModules {
476
476
  name: "KerioDescriptionHostsNotExistError",
477
477
  message: `Host ID(s) from specified description does not exist in group while processing API method 'IPAddressGroups.remove' for description '${description}' in group '${group_name}'`,
478
478
  type: 'Kerio',
479
- from: "Kerio.IPAddressGroups.removeHostFromIPAddressGroupByDesc"
479
+ from: "Kerio.IPAddressGroups.removeHostByDesc"
480
480
  }
481
481
  }
482
482
  } else {
@@ -484,7 +484,7 @@ export class IPAddressGroup extends KerioModules {
484
484
  name: "KerioHostNotExistGroupError",
485
485
  message: `Group has no hosts with the specified description while processing API method 'IPAddressGroups.remove' for description '${description}' in group '${group_name}'`,
486
486
  type: 'Kerio',
487
- from: "Kerio.IPAddressGroups.removeHostFromIPAddressGroupByDesc"
487
+ from: "Kerio.IPAddressGroups.removeHostByDesc"
488
488
  }
489
489
  }
490
490
 
@@ -493,4 +493,84 @@ export class IPAddressGroup extends KerioModules {
493
493
  throw e;
494
494
  }
495
495
  }
496
+
497
+ /**
498
+ * Remove IPAddressGroupItem by their unique ID
499
+ * @param {string} id The unique ID for this entry obtained from Kerio.IPAddressGroup.listByGroupName
500
+ * @returns {Promise<boolean>} Returns True when removal was successful
501
+ */
502
+ async removeHostByID(id) {
503
+ try {
504
+
505
+ if (!this.instance.logged_in) {
506
+
507
+ this.reset();
508
+
509
+ throw {
510
+ name: "KerioClientSessionError",
511
+ message: `Kerio session invalid. Try logging in again.`,
512
+ type: 'Kerio',
513
+ from: "Kerio.IPAddressGroups.removeHostByID"
514
+ }
515
+ }
516
+
517
+ if (!id) {
518
+ throw {
519
+ name: "KerioInvalidIPAddressGroupItemIDError",
520
+ message: `Invalid IPAddressGroupItem ID while processing API method 'IPAddressGroups.remove' for ID '${id}'`,
521
+ type: 'Kerio',
522
+ from: "Kerio.IPAddressGroups.removeHostByID"
523
+ }
524
+ }
525
+
526
+ let remove_host_response = await this.sessionedRequest({
527
+ http_method: 'POST',
528
+ api_method: 'IpAddressGroups.remove',
529
+ auth: {
530
+ cookie: this.instance.session_cookie,
531
+ token: this.instance.x_token
532
+ },
533
+ body_params: {
534
+ groupIds: [id]
535
+ }
536
+ });
537
+
538
+ let response_body = remove_host_response._body;
539
+
540
+ if (Array.isArray(response_body.result.errors) && response_body.result.errors.length == 0) {
541
+
542
+ this.instance.logger.info({
543
+ name: "KerioRemoveHostIPAddressGroup",
544
+ message: `Removed an IPAddressGroup entry of ID '${id}' successfully`,
545
+ type: 'Kerio',
546
+ from: "Kerio.IPAddressGroups.removeHostByID"
547
+ });
548
+
549
+ return true;
550
+
551
+ } else {
552
+ switch (response_body.result.errors[0]?.code) {
553
+ case 1003:
554
+ throw {
555
+ name: "KerioHostRemoveError",
556
+ message: `Host ID invalid while fetching results from API method 'IPAddressGroups.remove' for ID '${id}'`,
557
+ type: 'Kerio',
558
+ from: "Kerio.IPAddressGroups.removeHostByID"
559
+ }
560
+ default:
561
+ throw {
562
+ name: "KerioRequestError",
563
+ message: `General error occured while fetching results from API method 'IPAddressGroups.remove' for ID '${id}'`,
564
+ type: 'Kerio',
565
+ from: "Kerio.IPAddressGroups.removeHostByID"
566
+ }
567
+ }
568
+ }
569
+
570
+ } catch (e) {
571
+ this.instance.logger.error(e);
572
+ throw e;
573
+ }
574
+ }
575
+
496
576
  }