@enfocussw/switch-scripting-context 25.11.0-beta.9 → 25.11.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/CHANGELOG.md +241 -0
  2. package/README.md +44 -35
  3. package/dist/init.d.ts +15 -0
  4. package/dist/init.js +77 -66
  5. package/docs/switch-api/api-versions.md +116 -0
  6. package/docs/switch-api/connection.md +82 -0
  7. package/docs/switch-api/{api-document-classes.md → document-classes.md} +13 -2
  8. package/docs/switch-api/entry-points.md +171 -0
  9. package/docs/switch-api/{api-enums.md → enums.md} +23 -12
  10. package/docs/switch-api/{api-execution-environment.md → execution-environment.md} +39 -12
  11. package/docs/switch-api/{api-flow-element.md → flow-element.md} +23 -7
  12. package/docs/switch-api/{api-http.md → http.md} +10 -1
  13. package/docs/switch-api/job-patterns.md +178 -0
  14. package/docs/switch-api/{api-job.md → job.md} +23 -9
  15. package/docs/switch-api/{api-logging.md → logging.md} +47 -5
  16. package/docs/switch-api/{api-switch.md → switch.md} +68 -4
  17. package/docs/switch-appstore/app-guidelines.md +258 -0
  18. package/docs/switch-appstore/app-manual.md +84 -0
  19. package/docs/switch-appstore/app-store-listing.md +69 -0
  20. package/docs/switch-appstore/app-store-submission.md +83 -0
  21. package/docs/{switch-api/api-debugging.md → switch-project/debugging.md} +9 -0
  22. package/docs/{switch-api/api-logs-and-dataroot.md → switch-project/logs-and-dataroot.md} +10 -1
  23. package/docs/switch-project/project-planning.md +117 -0
  24. package/docs/switch-project/property-documentation.md +75 -0
  25. package/docs/{switch-api/api-property-editors.md → switch-project/property-editors.md} +55 -8
  26. package/docs/{switch-api/api-script-declaration.md → switch-project/script-declaration.md} +47 -13
  27. package/docs/switch-project/script-structure.md +188 -0
  28. package/docs/{switch-api/api-tooling.md → switch-project/tooling.md} +87 -1
  29. package/docs/{switch-api/api-vscode.md → switch-project/vscode.md} +19 -0
  30. package/docs/switch-scripting.md +49 -23
  31. package/package.json +11 -7
  32. package/docs/switch-api/api-connection.md +0 -63
  33. package/docs/switch-api/api-entry-points.md +0 -82
  34. package/docs/switch-api/api-job-patterns.md +0 -79
  35. package/docs/switch-api/api-script-structure.md +0 -85
@@ -0,0 +1,116 @@
1
+ ---
2
+ id: api-versions
3
+ category: switch-api
4
+ order: 25
5
+ summary: "Which Switch release added each scripting API class, method, and enum value; API availability follows the running Switch, not `manifest.xml`"
6
+ triggers:
7
+ - "Writing or reviewing code for a script or app that must run on a Switch version older than the latest, or when the user names a minimum Switch version"
8
+ ---
9
+
10
+ # API availability by Switch version
11
+
12
+ ## The running Switch decides which methods exist
13
+
14
+ Each Switch installation ships one copy of the scripting module, and every bundled Node.js version
15
+ uses that same copy. So which API methods a script can call depends on the Switch Server the script
16
+ runs on, not on anything in the script package. A script whose `manifest.xml` says `20.1` runs on
17
+ Node.js 12 in Switch 26.07, and it still gets the full 26.07 API.
18
+
19
+ The two versions are independent:
20
+
21
+ | Depends on | Decided by |
22
+ |---|---|
23
+ | Node.js version (language features, Node built-ins) | `SwitchVersion` in `manifest.xml`, looked up by the running Switch. See [script-structure.md § Node.js version per Switch version](../switch-project/script-structure.md#nodejs-version-per-switch-version) |
24
+ | Scripting API (classes, methods, enum values below) | The version of the Switch Server the script runs on |
25
+
26
+ When code must run on an older Switch, check every API call against the tables below for the
27
+ **oldest** Switch version the script or app must support. For an app, that is the version baseline
28
+ from [project-planning.md § Switch version baseline](../switch-project/project-planning.md#switch-version-baseline-apps-only).
29
+
30
+ ### Checking at runtime
31
+
32
+ `s.getServerVersion()` (Switch 24.0+) returns the running Switch version as a number, e.g. `25.11`.
33
+ It doesn't exist on older Switch versions, so it can't detect those. To use a newer method when
34
+ available and fall back otherwise, test for the method itself:
35
+
36
+ ```ts
37
+ if (typeof job.getVariableAsString === 'function') {
38
+ // Switch 24.0+
39
+ } else {
40
+ // fallback for older Switch versions
41
+ }
42
+ ```
43
+
44
+ ## Release names
45
+
46
+ | `SwitchVersion` | Release |
47
+ |---|---|
48
+ | `20.0` | Switch 2020 Spring |
49
+ | `20.1` | Switch 2020 Fall |
50
+ | `21.0` | Switch 2021 Spring |
51
+ | `21.1` | Switch 2021 Fall |
52
+ | `22.0` | Switch 2022 Spring |
53
+ | `22.1` | Switch 2022 Fall |
54
+ | `23.1` | Switch 2023 Fall |
55
+ | `24.0` | Switch 2024 Spring |
56
+ | `24.1` | Switch 2024 Fall |
57
+ | `25.07` | Switch 25.07 |
58
+ | `25.11` | Switch 25.11 |
59
+ | `26.03` | Switch 26.03 |
60
+ | `26.07` | Switch 26.07 |
61
+
62
+ ## Source and limits of this list
63
+
64
+ The list comes from Enfocus's published type declarations
65
+ (`github.com/enfocus-switch/types-switch-scripting`), diffed from one release's tags to the next.
66
+ Several tags for one release (for example 22.1.0 and 22.1.1) are corrections to the declarations
67
+ for that release, not API changes, so they count as one release. A release with no tag added
68
+ nothing.
69
+
70
+ - The first tags (1.0.0 and 1.0.1, October 2020) are the baseline. The declarations don't separate
71
+ Switch 2020 Spring from 2020 Fall, so treat the baseline as available in every Switch version
72
+ that runs Node.js scripts.
73
+ - Tag 1.1.0 (May 2021) is Switch 2021 Spring. The later tags carry the release number (21.1.x,
74
+ 22.0.x, 22.1.x, 24.0.x, 24.1.x).
75
+ - The declarations end at v24.1.1-final (Switch 2024 Fall). SwitchScriptTool 26.07 still scaffolds
76
+ that version. A check of the Switch 26.07 scripting module found no public class, method, or enum
77
+ value that v24.1.1 lacks. So nothing was added in 23.1, 25.07, 25.11, 26.03, or 26.07.
78
+ - Entry points aren't part of the type declarations, so this list doesn't record when each entry
79
+ point appeared. The webhook entry points (`httpRequestTriggeredSync`/`Async`) need
80
+ `s.httpRequestSubscribe()`, so they can't be used before Switch 21.1 either.
81
+
82
+ ## Baseline (every Switch version with Node.js scripting)
83
+
84
+ | Class | Members |
85
+ |---|---|
86
+ | `Switch` | `getGlobalData`, `setGlobalData`, `removeGlobalData` (including the `lock` parameter) |
87
+ | `FlowElement` | `getPropertyStringValue`, `getPropertyType`, `getPropertyDisplayName`, `hasProperty`, `getOutConnections`, `setTimerInterval`, `log`, `failProcess`, `createJob`, `getPluginResourcesPath` |
88
+ | `Job` | `getName`, `getId`, `isFile`, `isFolder`, `get`, `sendToNull`, `sendToSingle`, `sendTo`, `sendToData`, `sendToLog`, `fail`, `log`, `createChild`, `getPrivateData`, `setPrivateData`, `removePrivateData`, `listDatasets`, `createDataset`, `getDataset`, `removeDataset` |
89
+ | `Connection` | `getId`, `getName`, `getPropertyStringValue`, `getPropertyType`, `getPropertyDisplayName`, `hasProperty` |
90
+ | Enums | `AccessLevel` (all), `Connection.Level` (all), `PropertyType` (all), `LogLevel.Info`/`Warning`/`Error`, `DatasetModel.Opaque`/`XML`/`XMP`/`JDF`, `Scope.Element`/`FlowElement`/`Global` |
91
+
92
+ ## Added per release
93
+
94
+ | Release | Added |
95
+ |---|---|
96
+ | 21.0 | `flowElement.getJobs()`; `PdfDocument` and `PdfPage` (whole classes); `EnfocusSwitchPrivateDataTag` with `hierarchy`, `emailAddresses`, `emailBody`, `userName`, `userFullName`, `userEmail`, `origin`; `LogLevel.Debug` |
97
+ | 21.1 | `flowElement.getName()`; `HttpRequest` and `HttpResponse` (whole classes, including `HttpRequest.Method`); `s.httpRequestSubscribe()`, `s.httpRequestUnsubscribe()`; `ImageDocument` (whole class, including `ImageDocument.ColorMode` and `ImageDocument.ColorSpace`); `EnfocusSwitchPrivateDataTag.initiated`, `.submittedTo` |
98
+ | 22.0 | `flowElement.getFlowName()`; `Switch.tr()`; `XmlDocument` (whole class); `Scope.Flow`, `Scope.FlowElements`; `DatasetModel.JSON` |
99
+ | 22.1 | `job.getPriority()`, `job.setPriority()`, `Priority` enum; `job.sendToChannel()`, `flowElement.subscribeToChannel()`; `job.processLater()`; `s.setAbortData()`; `XmpDocument` (whole class), `pdfDocument.getXMP()`; `EnfocusSwitchPrivateDataTag.state` |
100
+ | 23.1 | Nothing |
101
+ | 24.0 | `flowElement.getScriptDataPath()`, `flowElement.createPathWithName()`; `job.getVariableAsString()`, `job.getxmlData()`, `job.getxmpData()`, `job.getJdfData()`, `job.getJSONData()`; `s.getPreferenceSetting()`, `s.getServerVersion()`; `NoYesListPropertyStringValue` |
102
+ | 24.1 | `connection.getType()`, `connection.getFileCount()`, `flowElement.getFileCount()` |
103
+ | 25.07, 25.11, 26.03, 26.07 | Nothing |
104
+
105
+ ## Declaration changes to existing methods
106
+
107
+ These signatures changed between releases in the declarations. The declarations don't say whether
108
+ older runtimes enforced the older signature, so when targeting a release before the change, write
109
+ code that satisfies both.
110
+
111
+ - Before 21.0, private data and global data values were declared as `string`; from 21.0 they are
112
+ `any`. On 20.x, store strings (for example `JSON.stringify` the value) and parse them on read.
113
+ - Before 21.0, `job.fail()` declared `messageParams` as required. On 20.x, pass an array, even an
114
+ empty one.
115
+ - Before 22.1, `flowElement.failProcess()` declared `messageParam` as a required `string`. On an
116
+ older Switch, pass a string.
@@ -0,0 +1,82 @@
1
+ ---
2
+ id: connection
3
+ category: switch-api
4
+ order: 6
5
+ summary: "`Connection`: type, properties, file count"
6
+ triggers:
7
+ - "Routing to specific connections or reading connection properties"
8
+ ---
9
+
10
+ # Connection Class
11
+
12
+ A `Connection` represents an outgoing connection from the flow element. Obtain instances via `flowElement.getOutConnections()`.
13
+
14
+ ## Identity
15
+
16
+ ```ts
17
+ connection.getId(): string
18
+ ```
19
+ Unique ID for the connection. Stable across deactivate/reactivate, Switch restarts, holding/releasing connections, and renaming the flow itself. Changes on export/re-import, a flow upgrade, or renaming the flow *element* (not the flow).
20
+
21
+ ```ts
22
+ connection.getName(): string
23
+ ```
24
+ Display name as shown on the canvas. May be an empty string.
25
+
26
+ ```ts
27
+ // Switch 24.1+
28
+ connection.getType(): string
29
+ ```
30
+ Connection type. One of: `"Move"`, `"Filter"`, `"Traffic-data"`, `"Traffic-log"`, `"Traffic-datawithlog"`.
31
+
32
+ ## Connection properties
33
+
34
+ Connection properties are declared in the script's XML declaration (`ConnectionFields`) and configured per-connection in the canvas. See [script-declaration.md](../switch-project/script-declaration.md) for how to declare them (via SwitchScripter).
35
+
36
+ ```ts
37
+ connection.getPropertyStringValue(tag: string): Promise<string | string[]>
38
+ ```
39
+ Returns the connection property value as a string. Throws `"Invalid tag: <tag>"` if the tag is unknown **or if it's a `Dependency` dependent currently hidden by its master's value** — see [script-declaration.md § Dependency](../switch-project/script-declaration.md#custom-property-elements-elementfields). Before fetching a dependent property, confirm its condition holds (from the already-read master value, or via `hasProperty(tag)` below) rather than fetching it unconditionally.
40
+
41
+ This is **not** how to check which traffic light level(s) a connection accepts before calling `job.sendToData()` — `"Success"`/`"Warning"`/`"Error"` are not property tags, so passing one throws the same invalid-tag error. There is no supported way to check in advance; see [Connection.Level enum](#connectionlevel-enum) below.
42
+
43
+ ```ts
44
+ connection.getPropertyType(tag: string): PropertyType
45
+ ```
46
+ Returns the `PropertyType` of the property.
47
+
48
+ ```ts
49
+ connection.getPropertyDisplayName(tag: string): string
50
+ ```
51
+ Returns the English display name of the property (for use in log messages).
52
+
53
+ ```ts
54
+ connection.hasProperty(tag: string): boolean
55
+ ```
56
+ Returns `true` if the property exists and is visible for the current configuration. Use this to guard `getPropertyStringValue(tag)` calls on `Dependency` dependents — see the note above.
57
+
58
+ ## File count
59
+
60
+ ```ts
61
+ // Switch 24.1+
62
+ connection.getFileCount(nested?: boolean): Promise<number>
63
+ ```
64
+ Returns the number of files in the folder at the other end of this connection. If `nested` is `false`, counts only direct children; if `true` (the default, so it can be omitted), counts recursively (subfolders themselves are not counted).
65
+
66
+ ## Connection.Level enum
67
+
68
+ Used with `job.sendToData()` and `job.sendToLog()` to select which traffic light connection a job routes to.
69
+
70
+ | Value | String |
71
+ |---|---|
72
+ | `Connection.Level.Success` | `"success"` |
73
+ | `Connection.Level.Warning` | `"warning"` |
74
+ | `Connection.Level.Error` | `"error"` |
75
+
76
+ Available as `EnfocusSwitch.Connection.Level.*` outside `main.ts`.
77
+
78
+ **Traffic light levels are not a readable connection property.** `flowElement.getOutConnections()`
79
+ returns the outgoing `Connection` objects, but the supported API has no way to determine which
80
+ level(s) a given connection accepts. Don't call `connection.getPropertyStringValue("Success")`, `"Warning"`, or `"Error"` expecting to
81
+ read this back; those are not valid property tags for a traffic light connection. To route
82
+ optionally, see [job-patterns.md § Sending jobs](job-patterns.md#sending-jobs).
@@ -1,7 +1,18 @@
1
+ ---
2
+ id: document-classes
3
+ category: switch-api
4
+ order: 9
5
+ summary: "`PdfDocument`, `PdfPage`, `ImageDocument`, `XmlDocument`, `XmpDocument`: read-only file introspection"
6
+ triggers:
7
+ - "Inspecting PDF, image, XML, or XMP file contents"
8
+ ---
9
+
1
10
  # Document Classes
2
11
 
3
12
  Read-only document introspection utilities. All methods may throw — wrap in `try/catch`. Load this file when working with PDF, image, XML, or XMP documents.
4
13
 
14
+ Each class needs a minimum Switch version: `PdfDocument` and `PdfPage` 21.0+, `ImageDocument` 21.1+, `XmlDocument` 22.0+, `XmpDocument` and `doc.getXMP()` 22.1+.
15
+
5
16
  ## PdfDocument
6
17
 
7
18
  Open a PDF to inspect metadata and page geometry.
@@ -31,7 +42,7 @@ doc.getSecurityMethod(): string
31
42
  PdfDocument.getSecurityMethod(path: string): string
32
43
 
33
44
  doc.getPage(pageNumber?: number): PdfPage // 1-based; defaults to page 1
34
- doc.getXMP(): XmpDocument
45
+ doc.getXMP(): XmpDocument // Switch 22.1+
35
46
  ```
36
47
 
37
48
  ### Static page dimension methods
@@ -121,7 +132,7 @@ img.getSamplesPerPixel(): number
121
132
  ImageDocument.getSamplesPerPixel(path: string): Promise<number>
122
133
  ```
123
134
 
124
- See [api-enums.md](api-enums.md) for `ImageDocument.ColorMode` and `ImageDocument.ColorSpace` values.
135
+ See [enums.md](enums.md) for `ImageDocument.ColorMode` and `ImageDocument.ColorSpace` values.
125
136
 
126
137
  ---
127
138
 
@@ -0,0 +1,171 @@
1
+ ---
2
+ id: entry-points
3
+ category: switch-api
4
+ order: 2
5
+ summary: "All entry point signatures, constraints, and when each is called"
6
+ triggers:
7
+ - "Scaffolding a script, adding/editing an entry point, or making any edit to main.ts/main.js"
8
+ ---
9
+
10
+ # Switch Script Entry Points
11
+
12
+ Entry points are top-level `async` functions with specific names. They are **not exported**. Switch calls them automatically based on flow events.
13
+
14
+ ## Entry-point scanner constraints
15
+
16
+ Switch discovers a script's entry points by regex, not by parsing. Before matching
17
+ `function\s+(name)\s*\(` it strips comments and literals with a regex that doesn't understand JS
18
+ escaping. Certain source shapes make that strip regex delete large spans of real code — and every
19
+ `function` declaration inside the deleted span becomes invisible to Switch, whether or not that
20
+ function is itself well-formed.
21
+
22
+ This applies to **every** entry point on this page, not only the four checked below — a swallowed
23
+ `validateProperties` or `getLibraryForProperty` fails silently (the callback just never runs, no
24
+ error anywhere), which is worse than the loud failure the four below produce. The one exception is
25
+ `calculateScriptExpression`: it's invoked directly at runtime rather than through this scanner, so
26
+ it isn't at risk.
27
+
28
+ If none of `jobArrived`, `timerFired`, `flowStopTriggered`, `httpRequestTriggeredAsync` survives,
29
+ Switch fails with `Cannot open script '<name>': no entry points found` — `httpRequestTriggeredSync`
30
+ alone does not satisfy this check. Both the packed `.sscript` (the entry-point list is baked in at
31
+ pack time) and the unpacked script folder (`main.js` is rescanned by this same scanner every time
32
+ Switch loads it, e.g. running or debugging from Designer) are affected. Packing does not validate
33
+ or warn about any of this — a script that packs cleanly can still fail to load.
34
+
35
+ **Rules for writing entry points in `main.ts`/`main.js`:**
36
+
37
+ 1. Never write a string literal whose content ends with a backslash: `"\\"`, `'\\'`, `` `\\` ``,
38
+ `"C:\\Temp\\"`. This is the highest-frequency trigger — the strip regex hunts for the next
39
+ matching quote character anywhere later in the file to close the literal (a backslash right
40
+ before the real closing quote makes it skip past that quote), and deletes everything in between.
41
+ Use `"\x5c"`, `"\u005C"`, `String.fromCharCode(92)`, or restructure (e.g.
42
+ `JSON.stringify(v).slice(1, -1)` for backslash/quote escaping) instead. A backslash elsewhere in
43
+ the literal is fine: `"\\n is newline"`, `"a\\b"`.
44
+ 2. Avoid regex literals — including ones that look properly closed, like `/[^/]+/` (a character
45
+ class containing an unescaped `/`). The strip regex doesn't understand character classes, so it
46
+ closes the "literal" early at the inner `/` and leaves a dangling `/` that swallows forward to
47
+ the next `/` anywhere later in the file. Use `new RegExp("...")` instead.
48
+ 3. Avoid division that isn't in the plain `word / word` shape. `a / b` is recognised and stripped
49
+ safely; `) / 2`, `] / 2`, and `/=` are not, and the leftover `/` swallows forward exactly like an
50
+ unclosed regex literal. Rewrite as `Math.floor(x / y)` with plain identifiers, or hoist to a
51
+ named variable first.
52
+ 4. Declare every entry point with the literal `function` keyword at top level:
53
+ `function jobArrived(...)` or `async function jobArrived(...)`. Arrow functions,
54
+ `exports.jobArrived = function (...)`, and class methods are invisible to the scanner.
55
+ 5. Entry-point names are matched case-sensitively. `JobArrived` is silently dropped during
56
+ extraction — if another valid entry point is also present the script packs and loads without
57
+ error, the misnamed function just never runs.
58
+
59
+ See [tooling.md § Verify entry points before packing](../switch-project/tooling.md#verify-entry-points-before-packing)
60
+ for a script to catch this before it reaches Switch.
61
+
62
+ ## Flow lifecycle
63
+
64
+ ```ts
65
+ async function flowStartTriggered(s: Switch, flowElement: FlowElement): Promise<void>
66
+ ```
67
+ Called when the flow starts. Use to subscribe to webhooks (`s.httpRequestSubscribe`) or channels (`flowElement.subscribeToChannel`). Cannot coexist with `timerFired` or `jobArrived` as the sole entry point. May execute in parallel for concurrent elements. Not available for debugging.
68
+
69
+ ```ts
70
+ async function flowStopTriggered(s: Switch, flowElement: FlowElement): Promise<void>
71
+ ```
72
+ Called when the flow stops. May execute in parallel for concurrent elements. Not available for debugging.
73
+
74
+ ## Timer
75
+
76
+ ```ts
77
+ async function timerFired(s: Switch, flowElement: FlowElement): Promise<void>
78
+ ```
79
+ Called on a recurring timer. First fires after `flowStartTriggered`. Set the interval via `flowElement.setTimerInterval(seconds)`. Cannot coexist with `flowStartTriggered` as the sole entry point.
80
+
81
+ Required when `IncomingConnections="No"`; optional (alongside `jobArrived`) when
82
+ `IncomingConnections="Yes"`. Never leave it present but empty — remove it entirely if it does
83
+ nothing.
84
+
85
+ ## Job processing
86
+
87
+ ```ts
88
+ async function jobArrived(s: Switch, flowElement: FlowElement, job: Job): Promise<void>
89
+ ```
90
+ Called when a job arrives. Must eventually call a `job.sendTo*()` or `job.fail()`. Can run concurrently if configured in the script XML declaration.
91
+
92
+ `jobArrived` and `timerFired` presence must match the declared connections — present when
93
+ `IncomingConnections="Yes"` (`timerFired` may additionally be present); when
94
+ `IncomingConnections="No"`, `timerFired` must be present instead. See
95
+ [script-declaration.md](../switch-project/script-declaration.md#built-in-elementfields). Never leave an empty
96
+ `jobArrived` or `timerFired` in the script — remove the function entirely if it does nothing.
97
+
98
+ **Gotcha: a flow restart replays every queued job through `jobArrived` again.** This includes a job
99
+ whose real processing was deferred elsewhere, such as a job registered in global data and actually
100
+ handled later in `timerFired`. `jobArrived` does not skip a job just because it was already
101
+ registered on a previous run; if the element still has a large backlog queued when the flow
102
+ restarts, every one of those jobs fires `jobArrived` again, and working through a long backlog this
103
+ way can take a long time even when each invocation only needs to recognize the job as already
104
+ registered and return. A script that defers processing this way must check global data at the top
105
+ of `jobArrived` and return immediately for a job already registered there, rather than assuming
106
+ `jobArrived` fires exactly once per job.
107
+
108
+ ```ts
109
+ async function abort(s: Switch, flowElement: FlowElement, job: Job, abortData: any): Promise<void>
110
+ ```
111
+ Called when an entry point exceeds its configured timeout. The `abortData` value was set beforehand via `s.setAbortData()` (Switch 22.1+). Maximum execution: 60 seconds, after which the script executor is killed. Applies to: `jobArrived`, `timerFired`, `httpRequestTriggeredSync`, `httpRequestTriggeredAsync`, `flowStartTriggered`, `flowStopTriggered`.
112
+
113
+ ## Webhooks
114
+
115
+ Both webhook entry points need Switch 21.1+, the first release with `s.httpRequestSubscribe()`.
116
+
117
+ ```ts
118
+ async function httpRequestTriggeredSync(request: HttpRequest, args: any[], response: HttpResponse, s: Switch): Promise<void>
119
+ ```
120
+ Synchronous webhook handler. A response **must** be sent before the function returns. Registered via `s.httpRequestSubscribe()` in `flowStartTriggered`. Executes in concurrent mode. Request body limit: 1 MB (HTTP 413). Queue limit: 10,000 pending requests (HTTP 429). Execution timeout: 1 minute (HTTP 524). Default response if none set: HTTP 200 with `{"status": true}`.
121
+
122
+ ```ts
123
+ async function httpRequestTriggeredAsync(request: HttpRequest, args: any[], s: Switch, flowElement: FlowElement): Promise<void>
124
+ ```
125
+ Asynchronous webhook handler. No response is required. Registered via `s.httpRequestSubscribe()` in `flowStartTriggered`. Only invoked if `httpRequestTriggeredSync` is not defined, or if the sync handler returned a 2xx status.
126
+
127
+ ## Script expression
128
+
129
+ ```ts
130
+ async function calculateScriptExpression(s: Switch, flowElement: FlowElement, job: Job): Promise<string | number | boolean>
131
+ ```
132
+ Called to evaluate a script expression for the flow element. The return value is used as the expression result.
133
+
134
+ ## Property UI callbacks
135
+
136
+ Not available for debugging.
137
+
138
+ ```ts
139
+ async function getLibraryForProperty(s: Switch, flowElement: FlowElement, tag: string): Promise<string[]>
140
+ ```
141
+ Returns a dynamic list of values for a property's library dropdown. Mandatory if any property uses
142
+ the `askplugin`/`askplugin2` editor (see
143
+ [property-editors.md](../switch-project/property-editors.md#modal-editors)). Log an error via `flowElement.log()`
144
+ if the list would otherwise come back empty, so the user can see why the dropdown has nothing in it.
145
+
146
+ ```ts
147
+ async function getLibraryForConnectionProperty(s: Switch, flowElement: FlowElement, c: Connection, tag: string): Promise<string[]>
148
+ ```
149
+ Returns a dynamic list of values for a connection property's library dropdown. Same guidance as
150
+ `getLibraryForProperty` above, for connection fields using `askplugin`/`askplugin2`.
151
+
152
+ ```ts
153
+ async function validateProperties(s: Switch, flowElement: FlowElement, tags: string[]): Promise<{ tag: string, valid: boolean }[]>
154
+ ```
155
+ Validates one or more property values. Return one result object per tag. Mandatory if any property
156
+ declares `Validation="Custom"` or `"Standard and custom"` (see
157
+ [script-declaration.md](../switch-project/script-declaration.md#custom-property-elements-elementfields)). Log
158
+ an error via `flowElement.log()` for any tag returned with `valid: false`, so the user sees why.
159
+
160
+ ```ts
161
+ async function validateConnectionProperties(s: Switch, flowElement: FlowElement, c: Connection, tags: string[]): Promise<{ tag: string, valid: boolean }[]>
162
+ ```
163
+ Validates one or more connection property values. Same guidance as `validateProperties` above, for
164
+ connection fields declaring `Validation="Custom"`/`"Standard and custom"`.
165
+
166
+ ```ts
167
+ async function findExternalEditorPath(s: Switch, flowElement: FlowElement, tag: string): Promise<string>
168
+ ```
169
+ Resolves the path to an external editor for a property. Required whenever the
170
+ `external`/`external2`/… editor is used, unless the dependent `Application` property is non-empty —
171
+ see [property-editors.md § Notes](../switch-project/property-editors.md#notes).
@@ -1,6 +1,15 @@
1
+ ---
2
+ id: enums
3
+ category: switch-api
4
+ order: 8
5
+ summary: "All enums with string values (`LogLevel`, `AccessLevel`, `DatasetModel`, `Scope`, `Priority`, `Connection.Level`, etc.)"
6
+ triggers:
7
+ - "Looking up enum values"
8
+ ---
9
+
1
10
  # Switch Scripting Enums
2
11
 
3
- All enums are available globally in `main.ts`. They are also accessible via `EnfocusSwitch.*` when used outside `main.ts` (e.g. in imported modules).
12
+ All enums are available globally in `main.ts`. They are also accessible via `EnfocusSwitch.*` when used outside `main.ts` (e.g. in imported modules). Enums and values without a Switch version below exist in every Switch version with Node.js scripting; see [api-versions.md](api-versions.md).
4
13
 
5
14
  ## LogLevel
6
15
 
@@ -11,7 +20,7 @@ Used with `job.log()` and `flowElement.log()`.
11
20
  | `LogLevel.Info` | `"info"` |
12
21
  | `LogLevel.Warning` | `"warning"` |
13
22
  | `LogLevel.Error` | `"error"` |
14
- | `LogLevel.Debug` | `"debug"` |
23
+ | `LogLevel.Debug` | `"debug"` (Switch 21.0+) |
15
24
 
16
25
  ## AccessLevel
17
26
 
@@ -32,7 +41,7 @@ Used with `job.createDataset()`, `job.sendToLog()`, and `job.listDatasets()`.
32
41
  | `DatasetModel.XML` | `"XML"` |
33
42
  | `DatasetModel.XMP` | `"XMP"` |
34
43
  | `DatasetModel.JDF` | `"JDF"` |
35
- | `DatasetModel.JSON` | `"JSON"` |
44
+ | `DatasetModel.JSON` | `"JSON"` (Switch 22.0+) |
36
45
 
37
46
  ## Scope
38
47
 
@@ -41,14 +50,14 @@ Used with `s.getGlobalData()`, `s.setGlobalData()`, `s.removeGlobalData()`.
41
50
  | Value | String |
42
51
  |---|---|
43
52
  | `Scope.Element` | `"element"` |
44
- | `Scope.Flow` | `"flow"` |
53
+ | `Scope.Flow` | `"flow"` (Switch 22.0+) |
45
54
  | `Scope.FlowElement` | `"flowElement"` |
46
- | `Scope.FlowElements` | `"flowElements"` |
55
+ | `Scope.FlowElements` | `"flowElements"` (Switch 22.0+) |
47
56
  | `Scope.Global` | `"global"` |
48
57
 
49
58
  ## Priority
50
59
 
51
- Used with `job.setPriority()` / `job.getPriority()`.
60
+ Used with `job.setPriority()` / `job.getPriority()`. Switch 22.1+.
52
61
 
53
62
  | Value | Number |
54
63
  |---|---|
@@ -68,11 +77,13 @@ Used with `job.sendToData()` and `job.sendToLog()` for traffic light connections
68
77
  | `Connection.Level.Warning` | `"warning"` |
69
78
  | `Connection.Level.Error` | `"error"` |
70
79
 
71
- Also available as `EnfocusSwitch.Connection.Level.*` outside `main.ts`.
80
+ Also available as `EnfocusSwitch.Connection.Level.*` outside `main.ts`. It selects which level to
81
+ route to; it is not a property you can read back from a `Connection` object, see
82
+ [connection.md § Connection.Level enum](connection.md#connectionlevel-enum).
72
83
 
73
84
  ## HttpRequest.Method
74
85
 
75
- Used with `s.httpRequestSubscribe()` and `s.httpRequestUnsubscribe()`.
86
+ Used with `s.httpRequestSubscribe()` and `s.httpRequestUnsubscribe()`. Switch 21.1+.
76
87
 
77
88
  | Value | String |
78
89
  |---|---|
@@ -103,7 +114,7 @@ Returned by `flowElement.getPropertyType()` and `connection.getPropertyType()`.
103
114
 
104
115
  ## NoYesListPropertyStringValue
105
116
 
106
- Convenience for `Boolean`-typed properties returned as strings.
117
+ Convenience for `Boolean`-typed properties returned as strings. Switch 24.0+.
107
118
 
108
119
  | Value | String |
109
120
  |---|---|
@@ -112,7 +123,7 @@ Convenience for `Boolean`-typed properties returned as strings.
112
123
 
113
124
  ## EnfocusSwitchPrivateDataTag
114
125
 
115
- Well-known tags for `job.getPrivateData()` / `job.setPrivateData()`.
126
+ Well-known tags for `job.getPrivateData()` / `job.setPrivateData()`. The enum needs Switch 21.0+; `initiated` and `submittedTo` need 21.1+, and `state` needs 22.1+.
116
127
 
117
128
  | Value | String |
118
129
  |---|---|
@@ -129,7 +140,7 @@ Well-known tags for `job.getPrivateData()` / `job.setPrivateData()`.
129
140
 
130
141
  ## ImageDocument.ColorMode
131
142
 
132
- Used with `ImageDocument.getColorMode()`. Available as `EnfocusSwitch.ImageDocument.ColorMode.*` outside `main.ts`.
143
+ Used with `ImageDocument.getColorMode()`. Available as `EnfocusSwitch.ImageDocument.ColorMode.*` outside `main.ts`. Switch 21.1+.
133
144
 
134
145
  | Value | String |
135
146
  |---|---|
@@ -145,7 +156,7 @@ Used with `ImageDocument.getColorMode()`. Available as `EnfocusSwitch.ImageDocum
145
156
 
146
157
  ## ImageDocument.ColorSpace
147
158
 
148
- Used with `ImageDocument.getColorSpace()`. Available as `EnfocusSwitch.ImageDocument.ColorSpace.*` outside `main.ts`.
159
+ Used with `ImageDocument.getColorSpace()`. Available as `EnfocusSwitch.ImageDocument.ColorSpace.*` outside `main.ts`. Switch 21.1+.
149
160
 
150
161
  | Value | String |
151
162
  |---|---|
@@ -1,13 +1,38 @@
1
+ ---
2
+ id: execution-environment
3
+ category: switch-api
4
+ order: 17
5
+ summary: "Execution modes (`Concurrent`/`Serialized`, `ExecutionGroup`, `NumberOfSlots`), process/concurrency model, state persistence across job invocations, unhandled-rejection behavior, npm/native module constraints"
6
+ triggers:
7
+ - "Choosing or changing an execution mode, relying on module-level state across jobs, handling errors/rejections, or using third-party npm packages"
8
+ ---
9
+
1
10
  # Execution Environment
2
11
 
3
- How the Node.js process a script runs in behaves, beyond the entry point API itself. These are
4
- consequences of the host process model, not things a script configures — understanding them avoids
5
- subtle bugs around state persistence and error handling.
12
+ How the Node.js process a script runs in behaves, beyond the entry point API itself. Apart from the
13
+ execution mode below, these are consequences of the host process model rather than things a script
14
+ configures — understanding them avoids subtle bugs around state persistence and error handling.
15
+
16
+ ## Execution modes
17
+
18
+ Set in the XML declaration via SwitchScripter, or by editing it directly (see
19
+ [script-declaration.md](../switch-project/script-declaration.md#built-in-elementfields)). Applies to all
20
+ instances of the script.
21
+
22
+ **Concurrent** — entry points for the same or different instances may run in parallel. Scripts must
23
+ synchronize access to any shared resources. `NumberOfSlots` is only meaningful in this mode.
24
+
25
+ **Serialized** — entry points within the same **execution group** are never concurrent. Instances
26
+ in different execution groups may still run in parallel.
27
+
28
+ **Execution group** — only relevant for Serialized mode. Should be a reverse-domain string (e.g.
29
+ `com.mycompany.myScript`) to avoid collisions. Defaults to the Script ID if left empty.
30
+
31
+ Neither setting maps to a count of Node.js OS processes — see below.
6
32
 
7
33
  ## Two independent concurrency tiers
8
34
 
9
- `NumberOfSlots`/`ExecutionGroup` (see
10
- [Execution modes](api-script-structure.md#execution-modes)) and the pool of Node.js processes that
35
+ `NumberOfSlots`/`ExecutionGroup` (above) and the pool of Node.js processes that
11
36
  actually run script code are governed completely separately — there is no one-to-one mapping between
12
37
  them:
13
38
 
@@ -23,7 +48,7 @@ them:
23
48
  whichever pooled executor is free (or a new one is spawned if none are); executors are reused
24
49
  across many jobs and across different flow elements running the same Node.js version, until
25
50
  recycled (see
26
- [Executor cleanup thresholds](api-job-patterns.md#executor-cleanup-thresholds)).
51
+ [Executor cleanup thresholds](job-patterns.md#executor-cleanup-thresholds)).
27
52
 
28
53
  ## Module-level state persists across jobs on the same executor
29
54
 
@@ -46,25 +71,27 @@ underlying executor process is **not** killed and continues serving subsequent j
46
71
  including for other flow elements pooled onto the same executor. Don't rely on an unhandled
47
72
  rejection to surface as a hard failure of the whole executor; always catch and handle errors
48
73
  explicitly (e.g. via `job.fail()`/`flowElement.failProcess()` — see
49
- [api-logging.md](api-logging.md)) rather than letting a promise reject unhandled.
74
+ [logging.md](logging.md)) rather than letting a promise reject unhandled.
50
75
 
51
76
  ## Third-party npm modules: file-based scripts only
52
77
 
53
78
  A script **expression** (entered inline in a flow element property, not a file-based script/app —
54
- see [Script expression](api-entry-points.md#script-expression)) cannot use third-party npm modules
79
+ see [Script expression](entry-points.md#script-expression)) cannot use third-party npm modules
55
80
  at all; only Node.js built-ins are available via `require`. A file-based script/app can use
56
81
  third-party modules from its own `node_modules` folder (see
57
- [Script folder files](api-script-structure.md#script-folder-files)).
82
+ [Script folder files](../switch-project/script-structure.md#script-folder-files)).
58
83
 
59
84
  ## Native (binary) addons are not supported
60
85
 
61
- Scripts with ESM dependencies are bundled before execution; this bundling path does not support
86
+ Scripts with ESM dependencies are bundled before execution, when `SwitchVersion` in `manifest.xml`
87
+ is `24.0` or higher (see
88
+ [script-structure.md § Other effects of `SwitchVersion`](../switch-project/script-structure.md#other-effects-of-switchversion)); this bundling path does not support
62
89
  native/binary Node addons (`.node` files). Stick to pure-JavaScript/TypeScript dependencies.
63
90
 
64
91
  ## No explicit CPU or memory cap beyond the documented thresholds
65
92
 
66
93
  Beyond the entry-point abort timeout and executor recycling thresholds already documented (see
67
- [Job processing](api-entry-points.md#job-processing) and
68
- [Executor cleanup thresholds](api-job-patterns.md#executor-cleanup-thresholds)), there is no
94
+ [Job processing](entry-points.md#job-processing) and
95
+ [Executor cleanup thresholds](job-patterns.md#executor-cleanup-thresholds)), there is no
69
96
  additional CPU-time or memory limit enforced on a script's own code. A runaway loop or leak is
70
97
  bounded only by those thresholds, not stopped proactively.