@brickert/kerio-connect-api 0.0.7 → 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 +109 -5
- package/package.json +1 -1
- package/src/ipaddressgroups.js +117 -37
- package/src/kerio.js +2 -0
- package/src/msgqueues.js +469 -0
package/index.d.ts
CHANGED
|
@@ -83,6 +83,7 @@ export interface GenericResponse {
|
|
|
83
83
|
result?: Array;
|
|
84
84
|
token?: string;
|
|
85
85
|
detail?: string;
|
|
86
|
+
deleteItems?: number;
|
|
86
87
|
}
|
|
87
88
|
};
|
|
88
89
|
}
|
|
@@ -109,6 +110,7 @@ export class Kerio extends WebClient {
|
|
|
109
110
|
Logs: Logs;
|
|
110
111
|
Domains: Domains;
|
|
111
112
|
Users: Users;
|
|
113
|
+
MessageQueues: MessageQueues;
|
|
112
114
|
|
|
113
115
|
login(user: KerioUser): void;
|
|
114
116
|
|
|
@@ -176,7 +178,7 @@ export class IPAddressGroup extends KerioModules {
|
|
|
176
178
|
* Obtain a Mapped Array of IPAddressGroupItem indexed by their ID for the specified group name
|
|
177
179
|
* @param group_name Name of the IPAddressGroup
|
|
178
180
|
*/
|
|
179
|
-
|
|
181
|
+
listByGroupName(group_name: string): Promise<Map<KerioIPAddressID, IPAddressGroupItem>>;
|
|
180
182
|
|
|
181
183
|
/**
|
|
182
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.
|
|
@@ -187,7 +189,7 @@ export class IPAddressGroup extends KerioModules {
|
|
|
187
189
|
* @param enabled True to enable this host in the group
|
|
188
190
|
* @returns Provides the unique KerioID of this host entry
|
|
189
191
|
*/
|
|
190
|
-
|
|
192
|
+
addHost(host_ip: string, description: string, group_name: string, enabled: boolean): Promise<KerioIPAddressID>;
|
|
191
193
|
|
|
192
194
|
/**
|
|
193
195
|
* Remove this IPAddressGroupItem of type 'host' of a single IP Address from this group name
|
|
@@ -195,7 +197,7 @@ export class IPAddressGroup extends KerioModules {
|
|
|
195
197
|
* @param group_name Name of the IPAddressGroup string to remove this host in
|
|
196
198
|
* @returns Returns True when removal was successful
|
|
197
199
|
*/
|
|
198
|
-
|
|
200
|
+
removeHostByIP(host_ip: string, group_name: string): Promise<boolean>;
|
|
199
201
|
|
|
200
202
|
/**
|
|
201
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.
|
|
@@ -204,8 +206,14 @@ export class IPAddressGroup extends KerioModules {
|
|
|
204
206
|
* @param remove_limit Max number of group items to remove upto. Specifying -1 will remove ALL by the description name
|
|
205
207
|
* @returns Returns an array of host IP addresses that were removed
|
|
206
208
|
*/
|
|
207
|
-
|
|
209
|
+
removeHostByDesc(description: string, group_name: string, remove_limit: number): Promise<Array<KerioIPAddressHost>>;
|
|
208
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>;
|
|
209
217
|
}
|
|
210
218
|
|
|
211
219
|
export type KerioIPAddressHost = string;
|
|
@@ -404,4 +412,100 @@ export interface KerioUserStatistic {
|
|
|
404
412
|
xmpp: number;
|
|
405
413
|
xmpps: number;
|
|
406
414
|
}
|
|
407
|
-
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
export class MessageQueues extends KerioModules {
|
|
418
|
+
/**
|
|
419
|
+
* Get a Mapped Array of KerioMessageItems indexed by their ID for messages that are pending to be processed
|
|
420
|
+
* @returns {Promise<Map<import('../index.d.ts').KerioMessageID, import('../index.d.ts').KerioMessageItem>>}
|
|
421
|
+
*/
|
|
422
|
+
pending(): Promise<Map<KerioMessageID, KerioMessageItem>>;
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Remove select message(s) that are held in queue/processing queue.
|
|
426
|
+
* @param messageId Single or Array of KerioMessageID(s)
|
|
427
|
+
* @returns {Promise<number>} Number of successfully removed messages
|
|
428
|
+
*/
|
|
429
|
+
removeFromQueue(messageId: KerioMessageID | Array<KerioMessageID>): Promise<number>;
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Remove all message(s) in the queue pending to be processed
|
|
433
|
+
* @returns {Promise<number>} Number of successfully removed messages
|
|
434
|
+
*/
|
|
435
|
+
flushQueue(): Promise<number>;
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Manually trigger sending these message(s) before their scheduled re-attempt
|
|
439
|
+
* @param messageId Single or Array of KerioMessageID(s)
|
|
440
|
+
* @returns {Promise<void>} Returns void. Access Kerio.MessageQueues.pending() to see any changes, messages not listed there are successfully being placed into the processed queue.
|
|
441
|
+
*/
|
|
442
|
+
trySendingNow(messageId: KerioMessageID | Array<KerioMessageID>): Promise<void>;
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Get a Mapped Array of KerioMessageItems indexed by their ID for a snapshot of the server's activity on processing messages
|
|
446
|
+
* @returns {Promise<Map<import('../index.d.ts').KerioMessageID, import('../index.d.ts').KerioMessageProcessedItem>>}
|
|
447
|
+
*/
|
|
448
|
+
processing(): Promise<Map<KerioMessageID, KerioMessageProcessedItem>>;
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Manually process message(s) now from their current stage.
|
|
452
|
+
* @returns {Promise<void>} Returns void. Access Kerio.MessageQueues.procesing() to see any changes, messages not listed there are successfully delivered to the destination server.
|
|
453
|
+
*/
|
|
454
|
+
tryProcessingNow(): Promise<void>;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* @example "1a2b3c4d-00000"
|
|
459
|
+
*/
|
|
460
|
+
export type KerioMessageID = string;
|
|
461
|
+
|
|
462
|
+
export interface KerioMessageItem {
|
|
463
|
+
id: KerioMessageID;
|
|
464
|
+
status: string;
|
|
465
|
+
time: {
|
|
466
|
+
creationTime: string; //YYYY-MM-DD HH:MM of server's timezone
|
|
467
|
+
nextTry: string; //YYYY-MM-DD HH:MM of server's timezone
|
|
468
|
+
};
|
|
469
|
+
messageSize: {
|
|
470
|
+
value: number;
|
|
471
|
+
units: "Bytes"
|
|
472
|
+
};
|
|
473
|
+
headers: {
|
|
474
|
+
from: string;
|
|
475
|
+
to: string;
|
|
476
|
+
};
|
|
477
|
+
authSender: {
|
|
478
|
+
address: string; //Authorized SMTP user email address
|
|
479
|
+
ip: string; //Authorized SMTP user ip address
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
export interface KerioMessageProcessedItem {
|
|
484
|
+
id: KerioMessageID;
|
|
485
|
+
status: {
|
|
486
|
+
progress: number; //Current progress in the current status stage
|
|
487
|
+
stage: KerioMessageProcessStatusEnum;
|
|
488
|
+
timeInCurrentStatus: string; //in HH:MM:SS format
|
|
489
|
+
};
|
|
490
|
+
messageSize: {
|
|
491
|
+
value: number;
|
|
492
|
+
units: "Bytes"
|
|
493
|
+
};
|
|
494
|
+
headers: {
|
|
495
|
+
from: string;
|
|
496
|
+
to: string;
|
|
497
|
+
destination: string; //Target SMTP server FQDN
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* msExecuting: General execution/starting state.
|
|
504
|
+
* msBackup: Message is being backed up.
|
|
505
|
+
* msContentFiltering: Passing through content/spam filters.
|
|
506
|
+
* msAntivirusControl: Being scanned for viruses.
|
|
507
|
+
* msLocalDelivering: Delivering to a mailbox on the local server.
|
|
508
|
+
* msSmtpDelivering: Attempting delivery to the next hop SMTP server.
|
|
509
|
+
* msFinishing: Finalizing the delivery/cleanup process.
|
|
510
|
+
*/
|
|
511
|
+
export type KerioMessageProcessStatusEnum = "msExecuting" | "msBackup" | "msContentFiltering" | "msAntivirusControl" | "msLocalDelivering" | "msSmtpDelivering" | "msFinishing";
|
package/package.json
CHANGED
package/src/ipaddressgroups.js
CHANGED
|
@@ -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
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
270
|
+
from: "Kerio.IPAddressGroups.removeHostByIP"
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
-
let get_host_ID_response = await this.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
406
|
+
from: "Kerio.IPAddressGroups.removeHostByDesc"
|
|
407
407
|
}
|
|
408
408
|
}
|
|
409
409
|
|
|
410
|
-
let get_host_ID_response = await this.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
}
|
package/src/kerio.js
CHANGED
|
@@ -3,6 +3,7 @@ import { Logs } from "./logs.js";
|
|
|
3
3
|
import { Session } from "./session.js";
|
|
4
4
|
import { Domains } from "./domains.js";
|
|
5
5
|
import { Users } from "./users.js";
|
|
6
|
+
import { MessageQueues } from "./msgqueues.js";
|
|
6
7
|
import { WebClient } from "./client.js";
|
|
7
8
|
import { CronJob } from 'cron';
|
|
8
9
|
import pino from 'pino';
|
|
@@ -27,6 +28,7 @@ export class Kerio extends WebClient {
|
|
|
27
28
|
this.Session = new Session(this);
|
|
28
29
|
this.Domains = new Domains(this);
|
|
29
30
|
this.Users = new Users(this);
|
|
31
|
+
this.MessageQueues = new MessageQueues(this);
|
|
30
32
|
|
|
31
33
|
this.logger = pino({
|
|
32
34
|
level: "debug",
|
package/src/msgqueues.js
ADDED
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
import { KerioModules } from './modules.js';
|
|
2
|
+
|
|
3
|
+
export class MessageQueues extends KerioModules {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Get a Mapped Array of KerioMessageItems indexed by their ID for messages that are pending to be processed
|
|
7
|
+
* @returns {Promise<Map<import('../index.d.ts').KerioMessageID, import('../index.d.ts').KerioMessageItem>>}
|
|
8
|
+
*/
|
|
9
|
+
async pending() {
|
|
10
|
+
try {
|
|
11
|
+
if (!this.instance.logged_in) {
|
|
12
|
+
|
|
13
|
+
this.reset();
|
|
14
|
+
|
|
15
|
+
throw {
|
|
16
|
+
name: "KerioClientSessionError",
|
|
17
|
+
message: `Kerio session invalid. Try logging in again.`,
|
|
18
|
+
type: 'Kerio',
|
|
19
|
+
from: "Kerio.MessageQueues.queued"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let queue_response = await this.sessionedRequest({
|
|
24
|
+
http_method: 'POST',
|
|
25
|
+
api_method: 'Queue.get',
|
|
26
|
+
auth: {
|
|
27
|
+
cookie: this.instance.session_cookie,
|
|
28
|
+
token: this.instance.x_token
|
|
29
|
+
},
|
|
30
|
+
body_params: {
|
|
31
|
+
query: {
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
let response_body = queue_response._body;
|
|
37
|
+
|
|
38
|
+
if (!response_body.result?.errors && !response_body?.error) {
|
|
39
|
+
|
|
40
|
+
var queueMsgsResult = new Map();
|
|
41
|
+
|
|
42
|
+
if (response_body.result.list.length > 0) {
|
|
43
|
+
response_body.result.list.forEach(msg => {
|
|
44
|
+
|
|
45
|
+
queueMsgsResult.set(msg.id, {
|
|
46
|
+
id: msg.id,
|
|
47
|
+
status: msg.status,
|
|
48
|
+
time: {
|
|
49
|
+
created: msg.creationTime,
|
|
50
|
+
nextTry: msg.nextTry
|
|
51
|
+
},
|
|
52
|
+
messageSize: {
|
|
53
|
+
value: msg.messageSize.value,
|
|
54
|
+
units: msg.messageSize.units
|
|
55
|
+
},
|
|
56
|
+
headers: {
|
|
57
|
+
from: msg.from,
|
|
58
|
+
to: msg.to
|
|
59
|
+
},
|
|
60
|
+
authSender: {
|
|
61
|
+
address: msg.authSender,
|
|
62
|
+
ip: msg.senderIp
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
this.instance.logger.debug({
|
|
69
|
+
name: "KerioQueuedMessagesPending",
|
|
70
|
+
message: `listed ${queueMsgsResult.size} queued messages pending to be processed`,
|
|
71
|
+
type: "Kerio",
|
|
72
|
+
from: "Kerio.MessageQueues.queued"
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return queueMsgsResult;
|
|
76
|
+
|
|
77
|
+
} else {
|
|
78
|
+
throw {
|
|
79
|
+
name: "KerioRequestError",
|
|
80
|
+
message: `Error occured while fetching results from API method 'Queue.get'`,
|
|
81
|
+
type: 'Kerio',
|
|
82
|
+
from: "Kerio.MessageQueues.list"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
} catch (e) {
|
|
87
|
+
this.instance.logger.error(e);
|
|
88
|
+
throw e;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Remove select message(s) that are held in the list of queue/processing queue.
|
|
94
|
+
* @param messageId Single or Array of KerioMessageID(s)
|
|
95
|
+
* @returns {Promise<number>} Number of successfully removed messages
|
|
96
|
+
*/
|
|
97
|
+
async removeFromQueue(messageId = null) {
|
|
98
|
+
try {
|
|
99
|
+
if (!this.instance.logged_in) {
|
|
100
|
+
|
|
101
|
+
this.reset();
|
|
102
|
+
|
|
103
|
+
throw {
|
|
104
|
+
name: "KerioClientSessionError",
|
|
105
|
+
message: `Kerio session invalid. Try logging in again.`,
|
|
106
|
+
type: 'Kerio',
|
|
107
|
+
from: "Kerio.MessageQueues.removeFromQueue"
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (!messageId || (Array.isArray(messageId) && messageId.length == 0)) {
|
|
112
|
+
throw {
|
|
113
|
+
name: "KerioMessageIdError",
|
|
114
|
+
message: `Invalid message ID or array of message IDs while processing API method 'Queue.remove'`,
|
|
115
|
+
type: 'Kerio',
|
|
116
|
+
from: "Kerio.MessageQueues.removeFromQueue"
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
//If single message ID string, convert to array of one element
|
|
121
|
+
if (!Array.isArray(messageId)) {
|
|
122
|
+
messageId = [messageId];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
let queue_remove_response = await this.sessionedRequest({
|
|
126
|
+
http_method: 'POST',
|
|
127
|
+
api_method: 'Queue.remove',
|
|
128
|
+
auth: {
|
|
129
|
+
cookie: this.instance.session_cookie,
|
|
130
|
+
token: this.instance.x_token
|
|
131
|
+
},
|
|
132
|
+
body_params: {
|
|
133
|
+
query: {
|
|
134
|
+
},
|
|
135
|
+
messageIds: messageId
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
let response_body = queue_remove_response._body;
|
|
140
|
+
|
|
141
|
+
if (!response_body.result?.errors && !response_body?.error) {
|
|
142
|
+
|
|
143
|
+
this.instance.logger.debug({
|
|
144
|
+
name: "KerioQueuedMessagesRemoved",
|
|
145
|
+
message: `Removed ${response_body.result.deleteItems} queued messages that were pending to be processed`,
|
|
146
|
+
type: "Kerio",
|
|
147
|
+
from: "Kerio.MessageQueues.removeFromQueue"
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
return response_body.result.deleteItems;
|
|
151
|
+
|
|
152
|
+
} else {
|
|
153
|
+
throw {
|
|
154
|
+
name: "KerioRequestError",
|
|
155
|
+
message: `Error occured while fetching results from API method 'Queue.remove'`,
|
|
156
|
+
type: 'Kerio',
|
|
157
|
+
from: "Kerio.MessageQueues.removeFromQueue"
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
} catch (e) {
|
|
162
|
+
this.instance.logger.error(e);
|
|
163
|
+
throw e;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Remove all message(s) in the queue pending to be processed
|
|
169
|
+
* @returns {Promise<number>} Number of successfully removed messages
|
|
170
|
+
*/
|
|
171
|
+
async flushQueue() {
|
|
172
|
+
try {
|
|
173
|
+
if (!this.instance.logged_in) {
|
|
174
|
+
|
|
175
|
+
this.reset();
|
|
176
|
+
|
|
177
|
+
throw {
|
|
178
|
+
name: "KerioClientSessionError",
|
|
179
|
+
message: `Kerio session invalid. Try logging in again.`,
|
|
180
|
+
type: 'Kerio',
|
|
181
|
+
from: "Kerio.MessageQueues.flushQueue"
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
let queue_response = await this.sessionedRequest({
|
|
186
|
+
http_method: 'POST',
|
|
187
|
+
api_method: 'Queue.removeAll',
|
|
188
|
+
auth: {
|
|
189
|
+
cookie: this.instance.session_cookie,
|
|
190
|
+
token: this.instance.x_token
|
|
191
|
+
},
|
|
192
|
+
body_params: {
|
|
193
|
+
query: {
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
let response_body = queue_response._body;
|
|
199
|
+
|
|
200
|
+
if (!response_body.result?.errors && !response_body?.error) {
|
|
201
|
+
|
|
202
|
+
this.instance.logger.debug({
|
|
203
|
+
name: "KerioQueuedMessagesFlush",
|
|
204
|
+
message: `Flushed ${response_body.result.deleteItems} queued messages pending to be processed`,
|
|
205
|
+
type: "Kerio",
|
|
206
|
+
from: "Kerio.MessageQueues.flushQueue"
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
return response_body.result.deleteItems;
|
|
210
|
+
|
|
211
|
+
} else {
|
|
212
|
+
throw {
|
|
213
|
+
name: "KerioRequestError",
|
|
214
|
+
message: `Error occured while fetching results from API method 'Queue.removeAll'`,
|
|
215
|
+
type: 'Kerio',
|
|
216
|
+
from: "Kerio.MessageQueues.flushQueue"
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
} catch (e) {
|
|
221
|
+
this.instance.logger.error(e);
|
|
222
|
+
throw e;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Manually trigger sending these message(s) before their scheduled re-attempt
|
|
228
|
+
* @param messageId Single or Array of KerioMessageID(s)
|
|
229
|
+
* @returns {Promise<void>} Returns void. Access Kerio.MessageQueues.queued() to see any changes, messages not listed there are successfully being placed into the processed queue.
|
|
230
|
+
*/
|
|
231
|
+
async trySendingNow(messageId = null) {
|
|
232
|
+
try {
|
|
233
|
+
if (!this.instance.logged_in) {
|
|
234
|
+
|
|
235
|
+
this.reset();
|
|
236
|
+
|
|
237
|
+
throw {
|
|
238
|
+
name: "KerioClientSessionError",
|
|
239
|
+
message: `Kerio session invalid. Try logging in again.`,
|
|
240
|
+
type: 'Kerio',
|
|
241
|
+
from: "Kerio.MessageQueues.trySendingNow"
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (!messageId || (Array.isArray(messageId) && messageId.length == 0)) {
|
|
246
|
+
throw {
|
|
247
|
+
name: "KerioMessageIdError",
|
|
248
|
+
message: `Invalid message ID or array of message IDs while processing API method 'Queue.tryToSend'`,
|
|
249
|
+
type: 'Kerio',
|
|
250
|
+
from: "Kerio.MessageQueues.trySendingNow"
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
//If single message ID string, convert to array of one element
|
|
255
|
+
if (!Array.isArray(messageId)) {
|
|
256
|
+
messageId = [messageId];
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
let try_sending_response = await this.sessionedRequest({
|
|
260
|
+
http_method: 'POST',
|
|
261
|
+
api_method: 'Queue.tryToSend',
|
|
262
|
+
auth: {
|
|
263
|
+
cookie: this.instance.session_cookie,
|
|
264
|
+
token: this.instance.x_token
|
|
265
|
+
},
|
|
266
|
+
body_params: {
|
|
267
|
+
query: {
|
|
268
|
+
},
|
|
269
|
+
messageIds: messageId
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
let response_body = try_sending_response._body;
|
|
274
|
+
|
|
275
|
+
if (!response_body.result?.errors && !response_body?.error) {
|
|
276
|
+
|
|
277
|
+
let debug_msg = "";
|
|
278
|
+
|
|
279
|
+
if (Array.isArray(messageId)) {
|
|
280
|
+
debug_msg = `Processing ${messageId.length} specified queued messages right now. Message IDs of '${messageId.join(', ')}'`;
|
|
281
|
+
} else {
|
|
282
|
+
debug_msg = `Processing queued message right now. Message ID of '${messageId}'`;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
this.instance.logger.debug({
|
|
286
|
+
name: "KerioQueueTrySendingNowAttempt",
|
|
287
|
+
message: debug_msg,
|
|
288
|
+
type: "Kerio",
|
|
289
|
+
from: "Kerio.MessageQueues.trySendingNow"
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
return;
|
|
293
|
+
|
|
294
|
+
} else {
|
|
295
|
+
|
|
296
|
+
if (response_body?.error?.code) {
|
|
297
|
+
switch (response_body?.error?.code) {
|
|
298
|
+
case 1000:
|
|
299
|
+
// One or more Message Ids don't exist or already processed
|
|
300
|
+
// Safe to silently error and return as you are intended to do Kerio.MessageQueues.pending() to check the status after.
|
|
301
|
+
return;
|
|
302
|
+
default:
|
|
303
|
+
throw {
|
|
304
|
+
name: "KerioRequestError",
|
|
305
|
+
message: `Error occured while fetching results from API method 'Queue.tryToSend'`,
|
|
306
|
+
type: 'Kerio',
|
|
307
|
+
from: "Kerio.MessageQueues.trySendingNow"
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
throw {
|
|
313
|
+
name: "KerioRequestError",
|
|
314
|
+
message: `Error occured while fetching results from API method 'Queue.tryToSend'`,
|
|
315
|
+
type: 'Kerio',
|
|
316
|
+
from: "Kerio.MessageQueues.trySendingNow"
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
} catch (e) {
|
|
321
|
+
this.instance.logger.error(e);
|
|
322
|
+
throw e;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Get a Mapped Array of KerioMessageItems indexed by their ID for a snapshot of the server's activity on processing messages
|
|
328
|
+
* @returns {Promise<Map<import('../index.d.ts').KerioMessageID, import('../index.d.ts').KerioMessageProcessedItem>>}
|
|
329
|
+
*/
|
|
330
|
+
async processing() {
|
|
331
|
+
try {
|
|
332
|
+
if (!this.instance.logged_in) {
|
|
333
|
+
|
|
334
|
+
this.reset();
|
|
335
|
+
|
|
336
|
+
throw {
|
|
337
|
+
name: "KerioClientSessionError",
|
|
338
|
+
message: `Kerio session invalid. Try logging in again.`,
|
|
339
|
+
type: 'Kerio',
|
|
340
|
+
from: "Kerio.MessageQueues.processing"
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
let process_response = await this.sessionedRequest({
|
|
345
|
+
http_method: 'POST',
|
|
346
|
+
api_method: 'Queue.getProcessed',
|
|
347
|
+
auth: {
|
|
348
|
+
cookie: this.instance.session_cookie,
|
|
349
|
+
token: this.instance.x_token
|
|
350
|
+
},
|
|
351
|
+
body_params: {
|
|
352
|
+
query: {
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
let response_body = process_response._body;
|
|
358
|
+
|
|
359
|
+
if (!response_body.result?.errors && !response_body?.error) {
|
|
360
|
+
|
|
361
|
+
var processMsgsResult = new Map();
|
|
362
|
+
|
|
363
|
+
if (response_body.result.list.length > 0) {
|
|
364
|
+
response_body.result.list.forEach(msg => {
|
|
365
|
+
|
|
366
|
+
processMsgsResult.set(msg.id, {
|
|
367
|
+
id: msg.id,
|
|
368
|
+
status: {
|
|
369
|
+
progress: msg.percentage,
|
|
370
|
+
stage: msg.status,
|
|
371
|
+
timeInCurrentStatus: msg.time
|
|
372
|
+
},
|
|
373
|
+
messageSize: {
|
|
374
|
+
value: msg.messageSize.value,
|
|
375
|
+
units: msg.messageSize.units
|
|
376
|
+
},
|
|
377
|
+
headers: {
|
|
378
|
+
from: msg.from,
|
|
379
|
+
to: msg.to,
|
|
380
|
+
destination: msg.server
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
this.instance.logger.debug({
|
|
387
|
+
name: "KerioQueuedMessages",
|
|
388
|
+
message: `listed ${processMsgsResult.size} processing messages`,
|
|
389
|
+
type: "Kerio",
|
|
390
|
+
from: "Kerio.MessageQueues.processing"
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
return processMsgsResult;
|
|
394
|
+
|
|
395
|
+
} else {
|
|
396
|
+
throw {
|
|
397
|
+
name: "KerioRequestError",
|
|
398
|
+
message: `Error occured while fetching results from API method 'Queue.get'`,
|
|
399
|
+
type: 'Kerio',
|
|
400
|
+
from: "Kerio.MessageQueues.list"
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
} catch (e) {
|
|
405
|
+
this.instance.logger.error(e);
|
|
406
|
+
throw e;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Manually process message(s) now from their current stage.
|
|
412
|
+
* @returns {Promise<void>} Returns void. Access Kerio.MessageQueues.procesing() to see any changes, messages not listed there are successfully delivered to the destination server.
|
|
413
|
+
*/
|
|
414
|
+
async tryProcessingNow() {
|
|
415
|
+
try {
|
|
416
|
+
if (!this.instance.logged_in) {
|
|
417
|
+
|
|
418
|
+
this.reset();
|
|
419
|
+
|
|
420
|
+
throw {
|
|
421
|
+
name: "KerioClientSessionError",
|
|
422
|
+
message: `Kerio session invalid. Try logging in again.`,
|
|
423
|
+
type: 'Kerio',
|
|
424
|
+
from: "Kerio.MessageQueues.tryProcessingNow"
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
let try_process_response = await this.sessionedRequest({
|
|
429
|
+
http_method: 'POST',
|
|
430
|
+
api_method: 'Queue.run',
|
|
431
|
+
auth: {
|
|
432
|
+
cookie: this.instance.session_cookie,
|
|
433
|
+
token: this.instance.x_token
|
|
434
|
+
},
|
|
435
|
+
body_params: {
|
|
436
|
+
query: {
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
let response_body = try_process_response._body;
|
|
442
|
+
|
|
443
|
+
if (!response_body.result?.errors && !response_body?.error) {
|
|
444
|
+
|
|
445
|
+
this.instance.logger.debug({
|
|
446
|
+
name: "KerioQueueProcessingNow",
|
|
447
|
+
message: `Force processing messages`,
|
|
448
|
+
type: "Kerio",
|
|
449
|
+
from: "Kerio.MessageQueues.tryProcessingNow"
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
return;
|
|
453
|
+
|
|
454
|
+
} else {
|
|
455
|
+
throw {
|
|
456
|
+
name: "KerioRequestError",
|
|
457
|
+
message: `Error occured while fetching results from API method 'Queue.run'`,
|
|
458
|
+
type: 'Kerio',
|
|
459
|
+
from: "Kerio.MessageQueues.tryProcessingNow"
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
} catch (e) {
|
|
464
|
+
this.instance.logger.error(e);
|
|
465
|
+
throw e;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
}
|