-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
1530 lines (1525 loc) · 76.1 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
*/
declare enum PropertyType {
Literal = "literal",
Number = "number",
Date = "date",
HoursAndMinutes = "hoursandminutes",
Boolean = "boolean",
String = "string",
FilePath = "filepath",
FolderPath = "folderpath",
FileType = "filetype",
FolderPattern = "folderpattern",
Regex = "regex",
OAuthToken = "oauthtoken"
}
declare enum NoYesListPropertyStringValue {
No = "No",
Yes = "Yes",
}
declare enum LogLevel {
Info = "info",
Warning = "warning",
Error = "error",
Debug = "debug"
}
declare enum DatasetModel {
Opaque = "Opaque",
XML = "XML",
XMP = "XMP",
JDF = "JDF",
JSON = "JSON"
}
declare enum AccessLevel {
ReadOnly = "readOnly",
/**
*/
ReadWrite = "readWrite"
}
declare enum Priority {
Low = -100000,
BelowNormal = -10000,
Normal = 0,
AboveNormal = 10000,
High = 100000
}
declare enum Scope {
Element = "element",
Flow = "flow",
FlowElement = "flowElement",
FlowElements = "flowElements",
Global = "global"
}
declare enum EnfocusSwitchPrivateDataTag {
hierarchy = "EnfocusSwitch.hierarchy",
emailAddresses = "EnfocusSwitch.emailAddresses",
emailBody = "EnfocusSwitch.emailBody",
userName = "EnfocusSwitch.userName",
userFullName = "EnfocusSwitch.userFullName",
userEmail = "EnfocusSwitch.userEmail",
origin = "EnfocusSwitch.origin",
initiated = "EnfocusSwitch.initiated",
submittedTo = "EnfocusSwitch.submittedTo",
state = "EnfocusSwitch.state"
}
/**
* An instance of the `Connection` class represents an outgoing connection of the flow element associated with the script.
* Connection objects can be obtained through functions of the `FlowElement` class.
* @class
*/
declare class Connection {
/**
* @description
* The element ID of a particular flow element offers the following fundamental guarantees:
*- It differs from the element ID of any other flow element in any currently active flow.
*- It remains unchanged as long as the flow in which it resides is not edited, even if the flow is deactivated and reactivated and across Switch sessions.
*- The element ID of a connection is never equal to the element ID of a non-connection flow element.
*
* Note that holding or releasing connections or renaming the flow does not count as editing in this context.
* However, exporting and re-importing (or upgrading) a flow, or renaming a flow element inside the flow, does count as editing.
* @returns {string} a string that uniquely identifies the connection (within the limits of the guarantees described below).
* Callers should not rely on the syntax of the returned string as this may change between Switch versions.
*/
getId(): string;
/**
* @description Returns the name of the connection as displayed in the canvas; this may be an empty string.
* @returns {string} the name of the connection as displayed in the canvas; this may be an empty string.
*/
getName(): string;
/**
* @description Returns the type of the connection as one of the following strings: "Move", "Filter", "Traffic-data", Traffic-log", "Traffic-datawithlog".
* @returns {string} the type of connection returned as a string.
*/
getType(): string;
/**
* Returns the value of a custom outgoing connection property as string.
* The property for which to return the value is specified by its property tag.
* @param {string} tag - the tag for which the property value is requested
* @returns the value of a custom outgoing connection property as string.
* @see {FlowElement.getPropertyStringValue}
*/
getPropertyStringValue(tag: string): Promise<string | string[]>;
/**
* Gets the connection property value type.
* @param {string} tag - the tag for which the property type is requested
* @returns {PropertyType} property type
* @see See the {@link PropertyType} enumeration for the possible return values.
*/
getPropertyType(tag: string): PropertyType;
/**
* Returns the name of the property as visible in the user interface. (However, this is an untranslated name.)
* This method is mostly intended to include the property name in a log message.
* @param {string} tag - property tag
* @returns {string} the name of the property as visible in the user interface.
*/
getPropertyDisplayName(tag: string): string;
/**
* @returns {boolean} `true` if a property with the specified tag is available for the connection, otherwise returns `false`.
* @param {string} tag - property tag
*/
hasProperty(tag: string): boolean;
/**
* Returns the number of files currently residing in the folder at the other end of this connection (the originating folder for an incoming connection, the target folder for an outgoing connection)
* If nested is false, only items directly inside the folder are counted (i.e. each file and each subfolder is counted as one item).
* If nested is true, the number of files in subfolders are counted as well, recursively (and subfolders themselves do not contribute to the count).
* @param {boolean} nested - nested files and folders to count
* @returns {number} the name of the property as visible in the user interface.
*/
getFileCount(nested: boolean): Promise<number>;
}
/**
*/
declare namespace Connection {
/**
* Connection.Level is a static field of the Connection instance that represents the traffic light level of the connection.
* It is also available in global scope as EnfocusSwitch.Connection.Level if you need to use it outside of main.js (or .ts).
* It's used to easily provide one of the following supported levels:
* - Connection.Level.Error
* - Connection.Level.Warning
* - Connection.Level.Success.
*/
enum Level {
Success = "success",
Warning = "warning",
Error = "error"
}
}
/**
*/
declare namespace HttpRequest {
/**
* Static field that represents the method of the HTTP(S) request.
* It's used to easily provide one of the following supported methods:
* - HttpRequest.Method.POST
* - HttpRequest.Method.PUT
* - HttpRequest.Method.DELETE
*/
enum Method {
POST = "POST",
PUT = "PUT",
DELETE = "DELETE"
}
}
/**
* The single instance of the FlowElement class is passed as an argument to the script entry points
* that operate in the context of a particular flow element.
* @class
*/
declare class FlowElement {
/**
* Returns the name of the flow element.
* @returns {string} the name of the flow element.
*/
getName(): string;
/**
* Returns the name of the flow.
* @returns {string} the name of the flow.
*/
getFlowName(): string;
/**
* Returns the value of a custom script property as string. The property for which to return the value is specified by its property tag.
* In case of an `OAuthToken` property type, the function resolves with a valid OAuth2 token. It is refreshed automatically if needed.
* The function throws an `"Invalid tag: <tag name>"` error, if the property with the given tag:
* - is not defined in the script declaration OR
* - is a dependent property, which is not visible for the current value of the parent property.
* @param {string} tag - property tag
* @return {Promise<string | string[]>} - value(s) of a custom script property as string.
* @throws an `"Invalid tag: <tag name>"` error (for cases, see the description)
* @see {@link PropertyType}
*/
getPropertyStringValue(tag: string): Promise<string | string[]>;
/**
* Returns the property value type. In case a property value can be entered via different editors, the property value type is required to correctly interpret the property value. The function throws an error if the property with the given tag
* - is not defined in the script declaration OR
* - is a dependent property, which is not visible for the current value of the parent property.
* @param {string} tag - property tag
* @return {PropertyType} - the property value type
*/
getPropertyType(tag: string): PropertyType;
/**
* Returns the untranslated name of the property as visible in the user interface in English.
* This method is mostly intended to include the property name in a log message.
* @param {string} tag - property tag
* @returns {string} the untranslated name of the property as visible in the user interface in English
*/
getPropertyDisplayName(tag: string): string;
/**
* Returns true if a property with the specified tag is available for the flow element, otherwise returns false.
* @param {string} tag - property tag
* @returns {boolean} - `true` if a property with the specified tag is available for the flow element, otherwise `false`
*/
hasProperty(tag: string): boolean;
/**
* Returns a list of Connection instances representing the outgoing connections of the flow element associated with this script.
* The list is in arbitrary order. If there are no outgoing connections, the list is empty.
* @returns {Connection[]} a list of Connection instances representing the outgoing connections of the flow element
*/
getOutConnections(): Connection[];
/**
* Sets the interval, in seconds, between subsequent invocations of the `timerFired` entry point (if it has been declared in the script).
* The implementation guarantees only that the time between invocations will not be less than the specified number of seconds.
* Depending on run-time circumstances the actual interval may be (much) longer.
* The default value for the timer interval is 300 seconds (5 minutes).
* @param {number} seconds - interval between invocations of `timerFired`. Default is 300 seconds.
*/
setTimerInterval(seconds: number): void;
/**
* Logs a message of the specified level for this flow element.
* Returned promise is resolved when the message is successfully logged, otherwise throws an error.
* @param {LogLevel} level - level of the message.
* @param {string} message - the message to be logged
* @param {Array} messageParams - message parameters that are used to substitute (see example)
* @example
* async function() {
* try {
* await flowElement.log(LogLevel.Warning, 'You are reaching the limits: %1 of %2 attempts remaining.', ['only 1', 10]);
* } catch (error) {
* // do something in case of an error
* }
* }
*/
log(level: LogLevel, message: string, messageParams?: (string | number | boolean)[]): Promise<void>;
/**
* Logs a fatal error for this flow element with the specified message
* and puts the element instance in the "problem process" state. `messageParam` is used as a substitute for `%1` in the message.
* @param {string} message - the message to be logged
* @param {string} messageParam - the value to be used as substitute
*/
failProcess(message: string, messageParam?: (string | number | boolean)): void;
/**
* For scripted plug-ins, returns the location of the script resources folder.
* Throws an exception if called for Switch scripts.
* @returns the location of the script resources folder (ONLY for scripted plug-ins).
* @throws `Error` if called for Switch scripts
*/
getPluginResourcesPath(): string;
/**
* For scripted plug-ins, returns the location of the ScriptData folder.
* @returns returns the location of the ScriptData folder.
*/
getScriptDataPath(): string;
/**
* Creates a new job from a file or folder that already exists at the specified path. Returns a job instance
* representing a new job with default values that does not correspond to an incoming job.
* It should be separately routed using sendTo methods.<br/>
* If the new job should inherit the job properties of the input job, then use the method {@link Job.createChild} instead. <br/>
* <b>Note:</b> This method is valid only in `jobArrived` and `timerFired` entry points.<br/>
* <b>Note:</b> The file or folder that was passed to createJob will not automatically be removed by Switch when sending or failing the job.
* Therefore it's up to the script to make sure that temporary files or folders passed to createJob are correctly removed
* after sending or failing the job.
* @param {string} path - the path to the file or folder
* @return {Promise<Job>} a promise containing the new job
* @example
* async function timerFired(s, flowElement) {
* try {
* const newJob...;
* await newJob.sendToSingle();
* } catch(e) {
* //catch the error
* }
* //remove ...
* }
*/
createJob(path: string): Promise<Job>;
/**
* Returns a list of job instances representing all the jobs currently waiting in the input folders for the flow element.
* The list includes all jobs that have "arrived" in the jobArrived entry point, including the job
* passed to the current invocation of the jobArrived entry point. If there are no such jobs, the list is empty.
* <b>Note:</b> For optimal performance of the script and to reduce the load on the server, this
* call should only be used to request up to 10.000 jobs that are known to be ready for
* processing. Job IDs to be passed to this call and data needed to decide when each job
* will be ready to be processed, can be calculated based on the jobArrived notification of
* the particular job and stored as global data to retrieve the result later.<br/>
* This method should be called once per entry point execution.<br/>
* It is NOT allowed to get private data and metadata for jobs returned by the call or for child jobs
* created from jobs that were returned by this call in the same entry point execution. We do allow
* setting private data and setting metadata for jobs returned by get jobs.
* It is not possible to use this call in a jobArrived entry point within a concurrent script. In that
* case, an error will be returned.<br/>
* @param {string[]} ids - IDs of the requested jobs
* @return {Promise<Job[]>} a promise containing requested jobs
* @example
* async function jobArrived(s, flowElement, job) {
* let jobsInfo = await s.getGlobalData(Scope.FlowElement, 'jobsInfo') || {};
* const jobId = job.getId();
* jobsInfo[jobId] = (jobsInfo[jobId] ? jobsInfo[jobId] : new Date().getTime());
* await s.setGlobalData(Scope.FlowElement, 'jobsInfo', jobsInfo); // collect jobs IDs to use them afterwards as parameter for the getJobs call
* }
* async function timerFired(s, flowElement) {
* await flowElement.setTimerInterval(30); // interval for 'holding' jobs
* const jobsInfo = await s.getGlobalData(Scope.FlowElement, 'jobsInfo');
* const currentTimestamp = new Date().getTime();
* let filteredIds = [];
* for (let id in jobsInfo) { // choose only jobs that have been staying in the flow element for at least 1 hour
* if ((jobsInfo[id] + (60 * 60 * 1000)) <= currentTimestamp && filteredIds.length <= 10000) {
* filteredIds.push(id);
* delete jobsInfo[id];
* }
* }
* if (filteredIds.length > 0) {
* const jobs = await flowElement.getJobs(filteredIds); // note: returns max 10000 jobs
* for (let job of jobs) {
* await job.sendToSingle(); // move each job to the outgoing connection
* }
* await s.setGlobalData(Scope.FlowElement, 'jobsInfo', jobsInfo);
* }
* }
*/
getJobs(ids: string[]): Promise<Job[]>;
/**
* Subscribes to the channel, which allows the flow element to receive jobs from it.<br/>
*
* A channel can have only one active subscriber at any given point in time.<br/>
*
* Method can only be called inside a flowStartTriggered entry point.
* @param {string} channelId - ID of the channel to subscribe to
* @param {string} backingFolderPath - path to an existing folder on the server to store incoming jobs
*/
subscribeToChannel(channelId: string, backingFolderPath: string): void;
/**
* Create temp folder for scripters.<br/>
* The method can only be called within all entry points
* If the path already exists we will return an empty string.
* @param {string} name - optional folder name
* @param {boolean} createFolder - true/false for creating folder
*/
createPathWithName(name: string, createFolder?: boolean): Promise<any>;
/**
* Returns the number of files in the active flow.
* If nested is false, only items directly inside the folder are counted (i.e. each file and each subfolder is counted as one item).
* If nested is true, the number of files in subfolders are counted as well, recursively (and subfolders themselves do not contribute to the count).
* @param {boolean} nested - nested files and folders to count
* @returns {number} the name of the property as visible in the user interface.
*/
getFileCount(nested: boolean): Promise<number>;
}
/**
* An instance of the Job class represents a job (file or job folder) waiting to be processed in one of the input folders
* for the flow element associated with the script. The third argument passed to the jobArrived entry point is the newly arrived job that
* triggered the entry point's invocation.
*
* New job objects can be created using the createJob function of the {@link FlowElement} class.
*
* Processing a job in a script usually consists of the following steps:
* - Decide on how to process the job based on file type etc.
* - Get the path to the incoming job using the {@link Job.get}() call with the appropriate access level.
* - Generate a temporary path for one or more output files or folders.
* - Create the output(s) in the temporary location.
* - Create the output job(s) using the {@link Job.createChild}() call.
* - In addition to (or instead of) creating new jobs it is possible to modify the incoming job.
* - Call one of the sendTo functions for each output.
*
* If the incoming job is passed along without change, the `Job.sendTo...()` functions can be called
* directly on the incoming job object, skipping all intermediate steps.
*
* A job remains in the input folder until one of the `Job.sendTo()` or `Job.fail()` functions has been called for the job.
* The jobArrived entry point will be invoked only once for each job, so if the entry point does not call a `sendTo()` or `fail()` function
* for the job, the script should do so at a later time (in a timerFired entry point or in a subsequent invocation of the `jobArrived`
* entry point for a different job).
*
* <b>Note:</b> After the flow restarts, the `jobArrived` entry point will be invoked once again for all jobs in the input folder.
*/
declare class Job {
/**
* Returns the file or folder name for the job, but excluding the unique filename prefix (job ID).
* By default, the returned name includes the file extension. The user can exclude the file extension
* by setting the includeExtension argument to false.
* @param {boolean} [includeExtension=true] - `true` if the name should include the extension, otherwise `false`.
* @returns {string} the file or folder name for the job (with or without extension)
*/
getName(includeExtension?: boolean): string;
/**
* Returns the unique job ID. This is a filename prefix used for the job, without the underscores.
* For example, for a job named "_0G63D_my_job.txt", this function would return "0G63D". <br/>
* Callers should not rely on the syntax of the returned string as this may change between Switch versions.
* @return {string} - the unique job ID.
*/
getId(): string;
/**
* Returns `true` if the job is a single file, `false` otherwise.
*/
isFile(): boolean;
/**
* Returns `true` if the job is a folder, `false` otherwise.
*/
isFolder(): boolean;
/**
* Schedules the job to be processed at a later moment so that jobArrived will be called again for the same job
* and dynamic properties set on the element will be re-evaluated.
* @param {number} seconds - The seconds parameter specifies the minimum time interval after which Switch will schedule the job for processing again. The default value for the interval is 300 seconds (5 minutes). Depending on run-time circumstances the actual interval may be (much) longer.
*/
processLater(seconds: number): Promise<void>;
/**
* Returns the priority of the job
*/
getPriority(): number;
/**
* Sets the priority of the job
*/
setPriority(priority: number): void;
/**
* Marks the job as completed without generating any output.
*/
sendToNull(): Promise<void>;
/**
* Sends the job to the single outgoing 'move' connection. The optional argument `newName` allows renaming the job.
* Throws an error in case there is no outgoing connection.
* @param {string} [newName] - new name for the job (optional)
* @example
* await job.sendToSingle('newName.pdf');
* await job.sendToSingle();
*/
sendToSingle(newName?: string): Promise<void>;
/**
* Sends the job to the specified outgoing connection, regardless of the connection type.<br>
* The optional argument `newName` allows renaming the job.
* @param {Connection} connection - the specified outgoing connection
* @param {string} [newName] - new name for the job (optional)
* @example
* const outConnections = flowElement.getOutConnections();
* for (const connection of outConnections) {
* if (job.isFile() && connection.getName() === 'move') {
* await job.sendTo(connection, "sendTo.txt"); // here it is
* }
* }
*/
sendTo(connection: Connection, newName?: string): Promise<void>;
/**
* Sends the jobs to the outgoing "data" traffic light connections that have the specified connection level property enabled.
* The optional argument `newName` allows renaming the job.<br/>
*
* If the script is not configured to use traffic light connections, this function logs an error and does nothing.<br/>
* If the flow element has no outgoing connections of the specified level, the job is failed with an appropriate error message.
* @param {Connection.Level} level - the specified connection level
* @param {string} [newName] - new name for the job (optional)
* @example
* await job.sendToData(Connection.Level.Warning, 'data_warning.txt');
* await job.sendToData(Connection.Level.Success, 'data_success.txt');
*/
sendToData(level: Connection.Level, newName?: string): Promise<void>;
/**
* Sends the job to the outgoing "log" traffic light connections that have the specified connection level property enabled.
* The optional argument `newName` allows renaming the job.
*
* For "data with log" traffic light connections, the job is attached as a metadata dataset to all "data" jobs,
* that is jobs routed via {@link Job.sendToData}. The `model` argument defines the metadata dataset model
* and the metadata dataset name is taken from the "Dataset name" property of the outgoing connections.
*
* Note that metadata datasets have automatically generated names and defined extensions.
* Therefore after the job is attached as a metadata dataset, its name is lost but the filename extension is preserved.
* If the `newName` argument is defined, the extension of newName will be used for the attached metadata datasets.
*
* If the script is not configured to use traffic light connections, this function logs an error and does nothing.
*
* If the flow element has no outgoing connections of the specified level, the job is discarded.
*
* For possible values of the model argument, see [DatasetModel](DatasetModel).
* If the model argument has an unsupported value, an exception is thrown.
* @param {Connection.Level} level - the specified connection level
* @param {string} [newName] - new name for the job (optional)
* @param {DatasetModel} model - dataset model
* @throws an exception if the model argument has an unsupported value
* @example
* await job.sendToLog(Connection.Level.Error, DatasetModel.XML, 'log_error.xml');
* await job.sendToLog(Connection.Level.Warning, DatasetModel.XML, 'log_warning.xml');
* await job.sendToLog(Connection.Level.Success, DatasetModel.XML, 'log_success.xml');
*/
sendToLog(level: Connection.Level, model: DatasetModel, newName?: string): Promise<void>;
/**
* Sends the job to the specified outgoing channel.
* The optional argument `newName` allows renaming the job.<br/>
*
* If a job is sent to a channel that has no active subscribers, the operation will fail.
* @param {string} channelId - ID of the channel to send the job to
* @param {string} [newName] - new name for the job (optional)
* @example
* await job.sendToChannel('EmailHandlingChannel');
* await job.sendToChannel('EmailHandlingChannel', 'image.jpg');
*/
sendToChannel(channelId: string, newName?: string): Promise<void>;
/**
* Logs a fatal error for the job with the specified message and moves the job to the Problem jobs folder.
* `messageParams` are used as substitutes for `%1`, `%2` etc. in the message.
* Note that newly created jobs are not moved to the Problem jobs folder
* (i.e. a job created using `createChild()` or `createJob()` and failed during the same entry point invocation is not moved).
*
* If the message string contains references to non-existing message parameters, an error is thrown. See {@link Job.log}.
* @param {string} message - the specified message to log alongside with job failing
* @param {(string | number | boolean)[]} [messageParams] - substitutes for `%1`, `%2` etc. in the message (optional)
* @throws an error if the message string contains references to non-existing message parameters
* @example
* job.fail('Something went wrong with the job %1', [job.getName()])
*/
fail(message: string, messageParams?: (string | number | boolean)[]): void;
/**
* Logs a message of the specified level for this job, automatically including the appropriate job information.
*
* If the message string contains references to non-existing message parameters, an error is thrown.
* If you want to log a message that contains '%' , pass it in the message parameters:
*
* `await job.log(LogLevel.Info, '%1', [message]);`
* @param {LogLevel} level - the specified level for the log message
* @param {string} message - the message itself
* @param {(string | number | boolean)[]} messageParams - substitutes for `%1`, `%2` etc. in the message
* @throws an error if the message string contains references to non-existing message parameters
* @example
* async function() {
* try {
* await job.log(LogLevel.Warning, 'Something takes longer for job %1 with name "%2"', [job.getId(), job.getName()])
* } catch (error) {
* // do something in case of an error
* }
* }
*/
log(level: LogLevel, message: string, messageParams?: (string | number | boolean)[]): Promise<void>;
/**
* Returns the value of the private data with the specified tag, or an empty string if no private data with that tag was set for the job.
* @param {string} tag - tag for which to get private data
* @returns the value of the private data with the specified tag, or an empty string if no private data with that tag was set for the job.
*/
getPrivateData(tag: string | EnfocusSwitchPrivateDataTag): Promise<any>;
/**
* Returns:
* - If tags are provided, a list of objects in the format defined above. The result will contain only data for the provided tags.
* If non-existing tags are provided, the result will not contain the data for these tags.
* - If tags are not provided, a list of objects in the format defined above (`{ tag: string, value: any }`).
* The result will contain all available private data for the job.
* @see examples in {@link Job.setPrivateData}.
* @param [tags] - tags for which to get private data (optional)
*/
getPrivateData(tags?: (string | EnfocusSwitchPrivateDataTag)[]): Promise<{
tag: string;
value: any;
}[]>;
/**
* Sets the value of the private data with the specified tag to the specified value.
* If private data with the same tag name exists, the value of the private data will be replaced with the new one.
* <b>Note:</b> Throws an error if no arguments are provided, or if the `value` argument is missing.
* @param tag - the requested tag
* @param value - the value to set
* @throws an error if no arguments are provided, or if the `value` argument is missing.
*/
setPrivateData(tag: string | EnfocusSwitchPrivateDataTag, value: any): Promise<void>;
/**
* Sets the private data values for the specified tags. If private data with the same tag name exists, the value of the private data
* will be replaced with the new one.
* <b>Note:</b> Throws an error if no data is specified or if `privateData` is not an array.
* @param privateData - data to set
* @example
* // Example for getPrivateData and setPrivateData
* const expectedPrivateData = [
* { tag: 'tag1', value: 1 },
* { tag: 'tag2', value: true },
* { tag: 'tag3', value: {key: [2,3,4]} },
* ];
* try {
* await job.setPrivateData('tag4', 'value4');
* await job.setPrivateData(EnfocusSwitchPrivateDataTag.userEmail, 'john.doe@example.com')
* await job.setPrivateData(expectedPrivateData);
* let actual = await job.getPrivateData();
* console.log('get all private data:', actual);
* actual = await job.getPrivateData('tag1');
* console.log('get one existing:', actual);
* actual = await job.getPrivateData(EnfocusSwitchPrivateDataTag.userEmail);
* console.log('get for predefined:', actual);
* actual = await job.getPrivateData('nonExisting');
* console.log('get one non-existing:', actual);
* actual = await job.getPrivateData(['tag2', 'tag3']);
* console.log('get specific:', actual);
* await job.sendToSingle();
* } catch (e) {
* console.log(e);
* job.fail(`${job.getName()} : ${e.message}`, []);
* }
*
* /* Output:
* get all private data: [
* { tag: 'BeingProcessedByRemoteProcessElement_7.2', value:'1' },{ tag: 'tag4', value: 'value4' },
* { tag: 'tag1', value: 1 },
* { tag: 'tag2', value: true },
* { tag: 'tag3', value: {key: [2,3,4]} }
* ]
* get one existing:1
* get for predefined:john.doe@example.com
* get one non-existing:
* get specific: [ { tag: 'tag2', value: true }, { tag: 'tag3', value: {key: [2,3,4]} } ]
* --- End of output
*/
setPrivateData(privateData: {
tag: string | EnfocusSwitchPrivateDataTag;
value: any;
}[]): Promise<void>;
/**
* Removes private data with the specified tag from the job.
* @param {string} tag - tag for which private data should be removed
* @throws an error if no tag is specified
*/
removePrivateData(tag: string | EnfocusSwitchPrivateDataTag): Promise<void>;
/**
* Removes private data with the specified tags from the job.
* @param {string[]} tags - tags for which private data should be removed
* @throws throws an error if the `tags` are not specified, or if the array is empty.
* @example
* try {
* await job.setPrivateData([
* { tag: 'survived1', value: 'value_survived1' },
* { tag: 'survived2', value: 'value_survived2' },
* { tag: 'toBeRemoved1', value: 'value_removed1' },
* { tag: 'toBeRemoved2', value: 'value_removed2' },
* { tag: 'toBeRemoved3', value: 'value_removed3' },
* { tag: EnfocusSwitchPrivateDataTag.userName, value: 'Admin'}
* ]);
* await job.removePrivateData('toBeRemoved1');
* await job.removePrivateData(['toBeRemoved2', 'toBeRemoved3']);
* await job.removePrivateData(EnfocusSwitchPrivateDataTag.userName);
* await job.sendToSingle();
* } catch (e) {
* console.log(e);
* job.fail(`${job.getName()} : ${e.message}`, []);
* }
*/
removePrivateData(tags: (string | EnfocusSwitchPrivateDataTag)[]): Promise<void>;
/**
* Returns the path to the job on the file system. It allows the user to read file/folder contents (if called with `AccessLevel.ReadOnly`)
* and/or to manipulate it (if called with `AccessLevel.ReadWrite`).
* Any file/folder modification will be detected and uploaded automatically on the routing stage (see <u>Routing a job</u> in the scripting documentation)
*
* <b>Note:</b> If job content modification is detected:
* - If called with `AccessLevel.ReadOnly`, an error is thrown.
* - If called with `AccessLevel.ReadWrite`, the job content is updated with the modified content.
*
* The above applies to `Job::sendToSingle`, `Job::sendTo`, `Job::sendToLog` and `Job::sendToData`.
* @param {AccessLevel} accessLevel - an access level to get the path to the job (ReadOnly or ReadWrite)
* @throws an error if unknown `AccessLevel` is provided OR any error that occurs when job content is transferred/accessed
* @example
* // Example 1:
* const fs = require("fs-extra");
* async function jobArrived(s, flowElement, job) {
* // READ-WRITE example
* const tempPath = await job.get(AccessLevel.ReadWrite);
* if (job.isFile()) {
* await fs.copy(sourceFile, tempPath); // i.e. replace job file with another file
* } else {
* // i.e. replace with your own folder structure
* await fs.emptyDir(tempPath);
* await fs.copy(sourceFolder, tempPath);
* }
* await job.sendToSingle(); //at this stage, new job content will be uploaded automatically;
* }
* // Example 2:
* const fs = require("fs-extra");
* async function jobArrived(s, flowElement, job) {
* // READ-ONLY example
* const jobPath = await job.get(AccessLevel.ReadOnly);
* if (job.isFile()) {
* const content = await fs.readFile(jobPath, { encoding: "utf8" }); // i.e. read file content;
* await job.log(LogLevel.Info, "Job content is: " + content);
* } else {
* const folderStructure = await fs.readdir(jobPath); //i.e. read folder structure
* await job.log(LogLevel.Info, "Job content structure is: " + folderStructure);
* }
* await job.sendToSingle();
* }
*/
get(accessLevel: AccessLevel): Promise<string>;
/**
* Creates a child job from a file or folder that already exists at the specified path. Returns a job instance representing a new job
* that inherits the processing history, external metadata and private data from the 'parent' job.
* It should be separately routed using one of the `sendTo` methods.
*
* If the new job should not inherit the properties of the input job, or if there is no input job as is usually the case inside the
* `timerFired` entry point, then use {@link FlowElement.createJob}.
*
* <b>Note:</b> The file or folder that was passed to createChild will not automatically be removed by Switch when sending or failing the job.
* Therefore it's up to the script to make sure that temporary files or folders passed to createChild are correctly removed
* after sending or failing the job.
* @param {string} path - a path to the file/folder to create a child job
* @example
* async function jobArrived(s, flowElement, job) {
* try {
* const reportJob = await job.createChild(<path_to_report_file>);
* await reportJob.sendToLog(Connection.Level.Success, 'XML');
* await job.sendToData(Connection.Level.Success);
* } catch(e) {
* // catch an error
* }
* // remove <path_to_report_file> in case no longer needed
* }
*/
createChild(path: string): Promise<Job>;
/**
* Returns a list of all datasets' names with models and extensions for which a dataset is associated with the job.
*/
listDatasets(): Promise<{
name: string;
model: DatasetModel;
extension: string;
}[]>;
/**
* Creates a new dataset with the specified model and associates it with the specified name. The new dataset will be uploaded when
* any sendTo method for the job is called. When failing the job, the dataset will not be added.
* Changing the name, model or extension of a dataset is only possible by creating a new dataset and removing the old one.
*
* The values allowed for the dataset model are: XML, JDF, XMP, and Opaque.
*
* <b>Note:</b>
* - Throws an error if neither `name`, `filePath`, nor `model` are specified.
* - The file or folder that was passed to `createDataset` will not automatically be removed by Switch when sending or failing the job.
* Therefore it's up to the script to make sure that temporary files or folders passed to `createDataset` are correctly removed
* after sending or failing the job.
* @param {string} name - the name for the new dataset
* @param {string} filePath - the path to the new dataset
* @param {DatasetModel} model - a model for the dataset (see allowed values)
* @throws an error if neither `name`, `filePath`, nor `model` are specified.
*/
createDataset(name: string, filePath: string, model: DatasetModel): Promise<void>;
/**
* Removes the dataset with the specified name for the job.
*
* <b>Note:</b>
* - Throws an error in case the dataset does not exist.
* - Throws an error if no name is specified.
* @param {string} name - name of the dataset to remove
* @throws an Error in case the dataset does not exist OR if no `name` is specified
*/
removeDataset(name: string): Promise<void>;
/**
* Returns the file path for the metadata dataset for the job associated with the specified name.
* When calling any `sendTo` method, the scripting module automatically uploads/replaces the dataset if the dataset was modified.
* This also means that when failing the job, the dataset will not be changed.
*
* <b>Note:</b> If dataset content modification is detected:
* - If called with AccessLevel.ReadOnly, an error is thrown.
* - If called with AccessLevel.ReadWrite, the dataset content is updated with the modified content.
*
* The above applies to `Job.sendToSingle`, `Job.sendTo`, `Job.sendToLog` and `Job.sendToData`.
*
* <b>Important:</b> We strongly advise you not to use AccessLevel.ReadWrite for this call.
* For more information, refer to [this issue](https://www.enfocus.com/en/support/known-issues-and-solutions#!/SupportPortalSolution?id=5012p000001Su4kAAC)
* @param {string} name - dataset name
* @param {AccessLevel} accessLevel - access level for the dataset (`AccessLevel.ReadOnly` or `AccessLevel.ReadWrite`)
* @throws an error if: unknown `AccessLevel` is provided OR any error that occurs when the dataset content is transferred/accessed.
* @example
* const fs = require("fs-extra");
* async function jobArrived(s, flowElement, job) {
* // READ-ONLY example
* const tempPath = await job.getDataset(XMLDataset, AccessLevel.ReadOnly);
* const content = await fs.readFile(jobPath, { encoding: "utf8" }); // i.e. read file content;
* await job.log(LogLevel.Info, "Dataset content is: ", content); // no changes allowed (read-only operation)
* await job.sendToSingle();
* }
*/
getDataset(name: string, accessLevel: AccessLevel): Promise<string>;
/**
* Retrieves the value of a Switch variable as a string.
* @param {string} variable - The name of the Switch variable.
* @returns {Promise<string>} The value of the Switch variable as a string.
*/
getVariableAsString(variable: string): Promise<any>;
/**
* Retrieves the value of a XML as Json Object
* @param {string} path - The name of the Model and where the file has been created.
* @returns {Promise<any>} The value of the method is any format.
*/
getxmlData(path: any, xpathQuery:any): Promise<any>;
/**
* Retrieves the value as Json Object.
* @param {string} metadata - The name of the Model and where the file has been created.
* @returns {Promise<any>} The value of the method is any format.
*/
getJSONData(metadata: any): Promise<any>;
/**
* Retrieves the value as Json Object.
* @param {string} path - The name of the Model and where the file has been created.
* @param {string} xpath - Xpath query that is used to fetch the data from the XMP Document.
* @returns {Promise<any>} The value of the method is any format.
*/
getxmpData(path: any, xpath: any): Promise<any>;
/**
* Retrieves the value of a XMP as a string or Boolean or Number.
* @param {string} path - The name of the Model and where the file has been created.
* @param {string} xpath - Xpath query that is used to fetch the data from the JDF Document.
* @returns {Promise<any>} The value of the method is any format..
*/
getJdfData(path: any, xpath: any): Promise<any>;
}
/**
* The single instance of the Switch class is passed as an argument to the script entry points. It
represents common Switch functionality.
*/
declare class Switch {
/**
* Returns the value of a global data variable with the specified scope and tag, or returns an
* empty string if no global data variable with that scope and tag was set.
* The lock parameter (false by default) is optional and determines whether or not a lock is set on
* global data. A lock can be released by calling the setGlobalData function. If the script doesn't
* update the global data, the data remains locked until the end of the script.
* @param {Scope} scope - the specified scope
* @param {string} tag - the requested tag
* @param {boolean} [lock = false] - Whether or not to set a lock on global data. A lock can be released by calling the setGlobalData function. If the script doesn't update the global data, the lock remains until the end of the script.
* @returns the value of a global data variable with the specified `scope` and `tag`
*/
getGlobalData(scope: Scope, tag: string, lock?: boolean): Promise<any>;
/**
* Returns a list of objects in the format defined above. The result will contain only the data for the
* provided tags. If non-existing tags are provided, the result will not contain the data for these tags.
* The lock parameter (false by default) is optional and determines whether or not a lock is set on
* global data. A lock can be released by calling the setGlobalData function. If the script doesn't
* update the global data, the data remains locked until the end of the script.
* If non-existing tags are provided, the result will not contain the data for these tags.
* @param {Scope} scope - the specified scope
* @param {string[]} tags - the tags requested
* @param {boolean} [lock = false] - Whether or not to set a lock on global data. A lock can be released by calling the setGlobalData function.
* If the script doesn't update the global data, the lock remains until the end of the script.
* @returns a promise that resolves with a list of objects in the format: { tag: string, value: any }[]
*/
getGlobalData(scope: Scope, tags: string[], lock?: boolean): Promise<{
tag: string;
value: any;
}[]>;
/**
* Sets the value of the global data with the specified scope and tag.
* @param {Scope} scope - the specified scope
* @param {string} tag - the specified tag
* @param value - the value to set for the requested tag
*/
setGlobalData(scope: Scope, tag: string, value: any): Promise<void>;
/**
* Sets the global data values for the specified tags and scope.
* If global data with the same tag name exists, the value of the global data will be replaced with the new one.
* @param {Scope} scope - the specified scope
* @param globalData - global data (pairs of tag => value) to set
*/
setGlobalData(scope: Scope, globalData: {
tag: string;
value: any;
}[]): Promise<void>;
/**
* Removes the global data for the specified `scope` and `tag`.
* @param {Scope} scope - the specified scope
* @param {string} tag - the specified tag
* <b>Note:</b> It's recommended to remove global data as soon as it is not needed anymore.
*/
removeGlobalData(scope: Scope, tag: string): Promise<void>;
/**
* Removes the global data for the specified `scope` and `tags`.
* @param {Scope} scope - the specified scope
* @param {string[]} tags - the specified tags
* <b>Note:</b> It's recommended to remove global data as soon as it is not needed anymore.
*/
removeGlobalData(scope: Scope, tags: string[]): Promise<void>;
/**
* Unsubscribes webhook requests.
* @param {HttpRequest.Method} method - HTTP request method that can be used for handling webhooks.
* @param {string} path - relative URL path used for httpRequestSubscribe.
*/
httpRequestUnsubscribe(method: HttpRequest.Method, path: string): Promise<void>;
/**
* Subscribes to incoming webhook requests.
* @param {HttpRequest.Method} method - HTTP request method that can be used for handling webhooks.
* @param {string} path - relative URL path. For the absolute URL that needs to be put in the 3rd application, the relative path needs to be prepended with the location of SwitchWebService, for example https://192.168.0.45:51088/scripting/${path}.
* @param {any[]} args - optional arguments that are provided to be passed to the sync and async callbacks
*/
httpRequestSubscribe(method: HttpRequest.Method, path: string, args: any[]): Promise<void>;
/**
* Sets the value of the abort data. This value will be passed to the abort entry point when the abort timeout has expired.
* @param {Any} abortData - the value of the abort data.
*/
setAbortData(abortData: any): void;
/**
* Retrieves the preference setting based on the provided setting key from the database.
* If only the settingGroup is specified, returns the entire settingGroup object.
* If both settingGroup and settingName are specified, returns the specific setting value.
* @param {string} settingKey - The key of the setting to retrieve in the format "settingGroup" or "settingGroup/settingName".
* @returns {Promise<any>} The entire group data or the value of the setting, or an empty string if not found.
*/
getPreferenceSetting(settingKey: string): Promise<any>;
/**
* Marks a string literal for translation. It allows SwitchScriptTool to recognize the strings which must be gathered for translation.
* @param {string} str - string literal that is marked for translation.
* @returns the same string which was passed into this function as an argument.
*/
static tr(str: string): string;
/**
* Provides the current switch version number.
* @returns the version of switch server where the script is running
*/
getServerVersion(): number;
}
/**
* Represents the arrived webhook request.
*/
declare class HttpRequest {
/**
* Request method.
*/
method: HttpRequest.Method;
/**
* Request path.
*/
path: string;
/**
* Request query.
*/
query: {
[propName: string]: string | string[];
};
/**
* Request headers.
*/
headers: {
[header: string]: string;
};
/**
* Request remote address.
*/
remoteAddress: string;
/**
* Request body.
*/
body: ArrayBuffer | undefined;
/**
* Returns the body of the request as string.
*/
getBodyAsString(): string;
}
/**
* Represents the response to the webhook request.
*/
declare class HttpResponse {
/**
* Sets the status code for the HTTP response.
* @param {number} statusCode - status code of the response.
*/
setStatusCode(statusCode: number): void;
/**
* Sets the header for the HTTP response.
* @param {string} name - header name.
* @param {string} value - header value.
*/
setHeader(name: string, value: string): void;
/**
* Sets the data for the HTTP response.
* @param {ArrayBuffer | string} data - response data.
*/
setBody(data: ArrayBuffer | string): void;
}
/**
* The PdfDocument class allows retrieving certain PDF information about PDF file contents.
* The class does not allow modifying file contents.
*
* Each PdfDocument instance references a particular file, which may be any file on the local file system (whether it is a job or not).
* All the methods in this class might throw an exception, so it is advised to wrap it into a try-catch block.
*/
declare class PdfDocument {
/**
* Constructs a PdfDocument instance associated with a file specified through its absolute file path.
* @param {string} path - absolute path to a PDF file.
* @returns {PdfDocument} An instance of the PdfDocument class.
*/
static open(path: string): PdfDocument;
/**
* Closes the PDF file. This method should be called when an instance of the PdfDocument class is not required anymore.
*/
close(): void;
/**
* Returns the number of pages in the PDF document.
* @returns {number} The number of pages in the PDF document.
*/
getNumberOfPages(): number;
/**
* Returns the number of pages in the PDF document.
* @param {string} path - absolute path to a PDF file.
* @returns {number} The number of pages in the PDF document.
*/
static getNumberOfPages(path: string): number;
/**
* Returns the version of the PDF file format (for example "1.6").