@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.
- package/CHANGELOG.md +241 -0
- package/README.md +44 -35
- package/dist/init.d.ts +15 -0
- package/dist/init.js +77 -66
- package/docs/switch-api/api-versions.md +116 -0
- package/docs/switch-api/connection.md +82 -0
- package/docs/switch-api/{api-document-classes.md → document-classes.md} +13 -2
- package/docs/switch-api/entry-points.md +171 -0
- package/docs/switch-api/{api-enums.md → enums.md} +23 -12
- package/docs/switch-api/{api-execution-environment.md → execution-environment.md} +39 -12
- package/docs/switch-api/{api-flow-element.md → flow-element.md} +23 -7
- package/docs/switch-api/{api-http.md → http.md} +10 -1
- package/docs/switch-api/job-patterns.md +178 -0
- package/docs/switch-api/{api-job.md → job.md} +23 -9
- package/docs/switch-api/{api-logging.md → logging.md} +47 -5
- package/docs/switch-api/{api-switch.md → switch.md} +68 -4
- package/docs/switch-appstore/app-guidelines.md +258 -0
- package/docs/switch-appstore/app-manual.md +84 -0
- package/docs/switch-appstore/app-store-listing.md +69 -0
- package/docs/switch-appstore/app-store-submission.md +83 -0
- package/docs/{switch-api/api-debugging.md → switch-project/debugging.md} +9 -0
- package/docs/{switch-api/api-logs-and-dataroot.md → switch-project/logs-and-dataroot.md} +10 -1
- package/docs/switch-project/project-planning.md +117 -0
- package/docs/switch-project/property-documentation.md +75 -0
- package/docs/{switch-api/api-property-editors.md → switch-project/property-editors.md} +55 -8
- package/docs/{switch-api/api-script-declaration.md → switch-project/script-declaration.md} +47 -13
- package/docs/switch-project/script-structure.md +188 -0
- package/docs/{switch-api/api-tooling.md → switch-project/tooling.md} +87 -1
- package/docs/{switch-api/api-vscode.md → switch-project/vscode.md} +19 -0
- package/docs/switch-scripting.md +49 -23
- package/package.json +11 -7
- package/docs/switch-api/api-connection.md +0 -63
- package/docs/switch-api/api-entry-points.md +0 -82
- package/docs/switch-api/api-job-patterns.md +0 -79
- package/docs/switch-api/api-script-structure.md +0 -85
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: vscode
|
|
3
|
+
category: switch-project
|
|
4
|
+
order: 13
|
|
5
|
+
summary: "Type declarations, tsconfig for TypeScript 6, ESLint rules"
|
|
6
|
+
triggers:
|
|
7
|
+
- "Setting up VS Code or fixing type errors"
|
|
8
|
+
---
|
|
9
|
+
|
|
1
10
|
# VS Code Setup
|
|
2
11
|
|
|
3
12
|
## Type declarations
|
|
@@ -14,6 +23,16 @@ Enables autocomplete and type checking for `Switch`, `Job`, `FlowElement` and al
|
|
|
14
23
|
|
|
15
24
|
> `SwitchScriptTool --create` sets this up automatically for new TypeScript script folders.
|
|
16
25
|
|
|
26
|
+
v24.1.1-final is the last published version and matches the API of every Switch release from 24.1
|
|
27
|
+
to 26.07. It declares every method without marking which Switch release added it, so the compiler
|
|
28
|
+
won't flag a call that an older target Switch lacks. Check those against
|
|
29
|
+
[api-versions.md](../switch-api/api-versions.md).
|
|
30
|
+
|
|
31
|
+
SwitchScriptTool 26.07 also scaffolds `@types/node` 24.x whatever Node.js version the script will
|
|
32
|
+
run on. When the package will run on an older Node.js (see
|
|
33
|
+
[script-structure.md § Node.js version per Switch version](script-structure.md#nodejs-version-per-switch-version)),
|
|
34
|
+
pin `@types/node` to that major version so the compiler flags newer Node.js APIs.
|
|
35
|
+
|
|
17
36
|
## TypeScript 6 / VS Code 1.114+
|
|
18
37
|
|
|
19
38
|
From VS Code 1.114, TypeScript 6 is used. Ambient/global types are no longer auto-included — without explicit configuration, `@types/node` and `@types/switch-scripting` globals (`Switch`, `Job`, etc.) will not be recognised.
|
package/docs/switch-scripting.md
CHANGED
|
@@ -3,38 +3,64 @@ Enfocus Switch workflow automation scripts written in TypeScript/Node.js.
|
|
|
3
3
|
|
|
4
4
|
## Execution environment
|
|
5
5
|
- Entry points are top-level `async` functions with specific names — **not exported** — executed in a `node:vm.Script()` context.
|
|
6
|
-
- ESM is supported: if ES modules are present the script is bundled with ESBuild before running.
|
|
7
|
-
- Type declarations are in `node_modules/@types/switch-scripting/index.d.ts` and must be followed precisely.
|
|
6
|
+
- ESM is supported: if ES modules are present the script is bundled with ESBuild before running (when `SwitchVersion` in `manifest.xml` is `24.0` or higher).
|
|
7
|
+
- Type declarations are in `node_modules/@types/switch-scripting/index.d.ts` and must be followed precisely. They list every method up to Switch 24.1 without saying which release added it.
|
|
8
|
+
- The Node.js version comes from `SwitchVersion` in `manifest.xml`; the available API methods come from the Switch version the script runs on. See `switch-project/script-structure.md` and `switch-api/api-versions.md`.
|
|
8
9
|
|
|
9
10
|
## API reference
|
|
10
|
-
Detailed
|
|
11
|
+
Detailed docs live in three folders, alongside this file: `switch-api/` (the scripting API itself),
|
|
12
|
+
`switch-project/` (script/app project structure and tooling), and `switch-appstore/` (Appstore
|
|
13
|
+
publishing guidance).
|
|
11
14
|
|
|
15
|
+
<!-- docs-index:table begin -->
|
|
12
16
|
| File | Contents | Load when |
|
|
13
17
|
|---|---|---|
|
|
14
|
-
| `switch-
|
|
15
|
-
| `switch-api/
|
|
16
|
-
| `switch-api/
|
|
17
|
-
| `switch-api/
|
|
18
|
-
| `switch-api/
|
|
19
|
-
| `switch-api/
|
|
20
|
-
| `switch-api/
|
|
21
|
-
| `switch-api/
|
|
22
|
-
| `switch-api/
|
|
23
|
-
| `switch-
|
|
24
|
-
| `switch-
|
|
25
|
-
| `switch-
|
|
26
|
-
| `switch-
|
|
27
|
-
| `switch-
|
|
28
|
-
| `switch-
|
|
29
|
-
| `switch-api/
|
|
30
|
-
| `switch-api/
|
|
31
|
-
| `switch-api/
|
|
18
|
+
| `switch-project/project-planning.md` | Pre-scaffolding checklist: Script vs App, job-processing approach, target OS, Switch version baseline, concurrency, native/binary npm dependencies, Appstore competition risk | Starting a new script or app, before scaffolding any files |
|
|
19
|
+
| `switch-api/entry-points.md` | All entry point signatures, constraints, and when each is called | Scaffolding a script, adding/editing an entry point, or making any edit to main.ts/main.js |
|
|
20
|
+
| `switch-api/switch.md` | `Switch` (`s`): global data, webhooks, abort, server utilities | Using global data, webhooks, abort, or server settings |
|
|
21
|
+
| `switch-api/flow-element.md` | `FlowElement`: properties, connections, job creation, logging | Reading properties, creating jobs, logging, connections |
|
|
22
|
+
| `switch-api/job.md` | `Job` **signatures**: routing, file access, child jobs, private data, datasets | Looking up what a `job.*` method takes, returns, or throws |
|
|
23
|
+
| `switch-api/connection.md` | `Connection`: type, properties, file count | Routing to specific connections or reading connection properties |
|
|
24
|
+
| `switch-api/http.md` | `HttpRequest` / `HttpResponse` + webhook pattern | Handling incoming HTTP webhooks |
|
|
25
|
+
| `switch-api/enums.md` | All enums with string values (`LogLevel`, `AccessLevel`, `DatasetModel`, `Scope`, `Priority`, `Connection.Level`, etc.) | Looking up enum values |
|
|
26
|
+
| `switch-api/document-classes.md` | `PdfDocument`, `PdfPage`, `ImageDocument`, `XmlDocument`, `XmpDocument`: read-only file introspection | Inspecting PDF, image, XML, or XMP file contents |
|
|
27
|
+
| `switch-project/script-structure.md` | What files a script folder contains, `manifest.xml` format, how `SwitchVersion` selects the Node.js version and which tools overwrite it, Script vs App | Setting up a new script project, converting a Script to an App, or working out which Node.js version a script or app will run on |
|
|
28
|
+
| `switch-project/tooling.md` | SwitchScriptTool commands and install paths, folder vs `.sscript` trade-offs, deployment | Running SwitchScriptTool: transpiling, packing, unpacking, or deploying |
|
|
29
|
+
| `switch-project/debugging.md` | Enabling debug mode in Switch Designer, debuggable entry points, VS Code attach | Debugging a script |
|
|
30
|
+
| `switch-project/vscode.md` | Type declarations, tsconfig for TypeScript 6, ESLint rules | Setting up VS Code or fixing type errors |
|
|
31
|
+
| `switch-project/script-declaration.md` | XML declaration reference: properties, connections, execution config; agents may edit this file directly | Understanding, adding, or editing script properties/connections/execution config |
|
|
32
|
+
| `switch-project/property-editors.md` | Property editor types, string return values, literal editors, dropdowns | Defining property editors in XML or reading property values in code |
|
|
33
|
+
| `switch-api/job-patterns.md` | `Job` **rules and gotchas**: file access semantics, temp cleanup, which `sendTo*()` suits which connection type, dataset/child ordering, executor limits | Writing or reviewing job-handling code. Pair with `job.md` when you also need signatures |
|
|
34
|
+
| `switch-api/execution-environment.md` | Execution modes (`Concurrent`/`Serialized`, `ExecutionGroup`, `NumberOfSlots`), process/concurrency model, state persistence across job invocations, unhandled-rejection behavior, npm/native module constraints | Choosing or changing an execution mode, relying on module-level state across jobs, handling errors/rejections, or using third-party npm packages |
|
|
35
|
+
| `switch-api/logging.md` | Log level semantics, logging practice, `console.log` limitation, common gotchas | Adding or reviewing `job.log()`/`flowElement.log()`/`job.fail()`/`failProcess()` calls |
|
|
36
|
+
| `switch-project/logs-and-dataroot.md` | Locating the Application Data Root, querying `ServerLogs.db3` directly | Diagnosing or validating a script from its actual log output rather than by reading the code |
|
|
37
|
+
| `switch-appstore/app-guidelines.md` | Pre-publish checklist for Appstore apps: property naming/tooltips/editors, entry point and sendTo consistency, logging quality, packaging, and the app-only submission rules (localization, signed universal macOS binaries) | Preparing a script for publication as an app, or reviewing one against Appstore submission criteria |
|
|
38
|
+
| `switch-project/property-documentation.md` | Writing guidance for `Tooltip` and `DetailedInfo` content on properties/connections | Writing or reviewing the text in a property's or connection's `Tooltip`/`DetailedInfo` |
|
|
39
|
+
| `switch-appstore/app-store-listing.md` | Writing guidance for the declaration's Appstore listing fields: `Description`, `Compatibility`, `SupportInfo`, `AppDiscovery`, `Connections` | Writing or reviewing the app's Appstore listing text |
|
|
40
|
+
| `switch-appstore/app-manual.md` | Writing guidance for the separate app manual document uploaded during Appstore review (`documentation-app_name.docx` template) | Preparing the app manual document for Appstore submission |
|
|
41
|
+
| `switch-appstore/app-store-submission.md` | Writing guidance for the Create Appstore App / Create Appstore App Version web forms: Short Description, What's new, Eula, icon specs, and which fields reuse content already written elsewhere | Preparing content for the Appstore website submission forms |
|
|
42
|
+
| `switch-api/api-versions.md` | Which Switch release added each scripting API class, method, and enum value; API availability follows the running Switch, not `manifest.xml` | 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 |
|
|
43
|
+
<!-- docs-index:table end -->
|
|
32
44
|
|
|
33
45
|
## Key rules
|
|
46
|
+
- Before scaffolding a new script or app, work through `switch-project/project-planning.md` with the user.
|
|
34
47
|
- Always consult the API reference files above before writing or modifying script code.
|
|
35
|
-
-
|
|
48
|
+
- If the script or app must run on a Switch version older than the latest, check each API call
|
|
49
|
+
against `switch-api/api-versions.md`. The API files mark anything newer than the baseline with
|
|
50
|
+
"Switch X+" (a `// Switch X+` comment above a signature, or a note in the text), meaning that
|
|
51
|
+
version or later.
|
|
52
|
+
- To find documented behavioural pitfalls before writing code in an area, grep the `switch-api/`,
|
|
53
|
+
`switch-project/`, and `switch-appstore/` folders alongside this file for `known issue`, `gotcha`,
|
|
54
|
+
`quirk`, `caveat` (case-insensitive) — every documented pitfall uses one of these four terms.
|
|
55
|
+
- Do not `export` entry point functions. Declare them with the literal `function` keyword at top
|
|
56
|
+
level — arrow functions, `exports.name = ...`, and class methods are invisible to Switch.
|
|
57
|
+
- Switch discovers entry points with a regex, not a parser. Never write a string literal whose
|
|
58
|
+
content ends with a backslash, a regex literal, or division outside the plain `word / word`
|
|
59
|
+
shape — each silently deletes a span of real code, and every entry point inside that span
|
|
60
|
+
disappears with no error anywhere. Read `switch-api/entry-points.md` §
|
|
61
|
+
Entry-point scanner constraints before editing `main.ts`/`main.js`.
|
|
36
62
|
- Every `jobArrived` invocation must end with exactly one `job.sendTo*()` or `job.fail()` call — either in the same invocation or deferred to `timerFired` via job information stored in global data.
|
|
37
63
|
- Use `AccessLevel.ReadOnly` for `job.get()` unless the file content will be modified.
|
|
38
64
|
- Use VS Code snippets (`.vscode/switch.code-snippets`, prefix `switch…`) to scaffold entry points.
|
|
39
65
|
- After calling `createJob()`, `createChild()`, or `createDataset()` with a file path, the script must delete the source file/folder after routing — Switch does not auto-remove it.
|
|
40
|
-
- The XML declaration (`<ScriptID>.xml`) can be edited directly — read `switch-
|
|
66
|
+
- The XML declaration (`<ScriptID>.xml`) can be edited directly — read `switch-project/script-declaration.md` first and follow its rules exactly (no schema validates this format, so mistakes fail silently). Never change an existing script's `Name`. Bump `Version` on every declaration edit. Leave `manifest.xml` edits (package type, declaration filename, program files) to the user unless explicitly asked.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enfocussw/switch-scripting-context",
|
|
3
|
-
"version": "25.11.
|
|
3
|
+
"version": "25.11.1-beta.0",
|
|
4
4
|
"description": "AI coding assistant context for Enfocus Switch scripting (Node.js/TypeScript)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"switch",
|
|
@@ -27,20 +27,24 @@
|
|
|
27
27
|
"docs/",
|
|
28
28
|
"!docs/superpowers",
|
|
29
29
|
"!docs/temp",
|
|
30
|
+
"!docs/adr",
|
|
30
31
|
"CHANGELOG.md"
|
|
31
32
|
],
|
|
32
33
|
"scripts": {
|
|
33
34
|
"build": "tsc -p tsconfig.json",
|
|
34
35
|
"build:test": "tsc src/init.test.ts --outDir dist --target ES2020 --module commonjs --lib ES2020 --types node --strict --esModuleInterop --skipLibCheck",
|
|
35
|
-
"test": "npm run build && npm run build:test && node dist/init.test.js",
|
|
36
|
-
"prepack": "npm run build",
|
|
37
|
-
"postpack": "node -e \"const fs=require('fs');const version=process.env.npm_package_version;const scoped=process.env.npm_package_name.replace(/^@/,'').replace('/','-')+'-'+version+'.tgz';const unscoped=process.env.npm_package_name.replace(/^@[^/]+\\//,'')+'-'+version+'.tgz';if(scoped!==unscoped&&fs.existsSync(scoped))fs.renameSync(scoped,unscoped);\""
|
|
36
|
+
"test": "npm run build && npm run build:test && node dist/init.test.js && node scripts/check-prose.js && node scripts/check-gotcha-tags.js && node scripts/generate-docs-index.js --check",
|
|
37
|
+
"prepack": "npm run build && node scripts/readme-links.js --publish",
|
|
38
|
+
"postpack": "node scripts/readme-links.js --restore && node -e \"const fs=require('fs');const version=process.env.npm_package_version;const scoped=process.env.npm_package_name.replace(/^@/,'').replace('/','-')+'-'+version+'.tgz';const unscoped=process.env.npm_package_name.replace(/^@[^/]+\\//,'')+'-'+version+'.tgz';if(scoped!==unscoped&&fs.existsSync(scoped))fs.renameSync(scoped,unscoped);\"",
|
|
39
|
+
"lint:prose": "node scripts/check-prose.js",
|
|
40
|
+
"lint:gotchas": "node scripts/check-gotcha-tags.js",
|
|
41
|
+
"docs:generate": "node scripts/generate-docs-index.js"
|
|
38
42
|
},
|
|
39
43
|
"author": "Sam Wallace",
|
|
40
44
|
"license": "ISC",
|
|
41
45
|
"repository": {
|
|
42
46
|
"type": "git",
|
|
43
|
-
"url": "git+https://github.com/
|
|
47
|
+
"url": "git+https://github.com/esko-bv/enf-switch-scripting-context.git"
|
|
44
48
|
},
|
|
45
49
|
"publishConfig": {
|
|
46
50
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -50,9 +54,9 @@
|
|
|
50
54
|
"@types/node": "^20.0.0",
|
|
51
55
|
"typescript": "^5.0.0"
|
|
52
56
|
},
|
|
53
|
-
"homepage": "https://github.com/
|
|
57
|
+
"homepage": "https://github.com/esko-bv/enf-switch-scripting-context#readme",
|
|
54
58
|
"bugs": {
|
|
55
|
-
"url": "https://github.com/
|
|
59
|
+
"url": "https://github.com/esko-bv/enf-switch-scripting-context/issues"
|
|
56
60
|
},
|
|
57
61
|
"engines": {
|
|
58
62
|
"node": ">=18"
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# Connection Class
|
|
2
|
-
|
|
3
|
-
A `Connection` represents an outgoing connection from the flow element. Obtain instances via `flowElement.getOutConnections()`.
|
|
4
|
-
|
|
5
|
-
## Identity
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
connection.getId(): string
|
|
9
|
-
```
|
|
10
|
-
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).
|
|
11
|
-
|
|
12
|
-
```ts
|
|
13
|
-
connection.getName(): string
|
|
14
|
-
```
|
|
15
|
-
Display name as shown on the canvas. May be an empty string.
|
|
16
|
-
|
|
17
|
-
```ts
|
|
18
|
-
connection.getType(): string
|
|
19
|
-
```
|
|
20
|
-
Connection type. One of: `"Move"`, `"Filter"`, `"Traffic-data"`, `"Traffic-log"`, `"Traffic-datawithlog"`.
|
|
21
|
-
|
|
22
|
-
## Connection properties
|
|
23
|
-
|
|
24
|
-
Connection properties are declared in the script's XML declaration (`ConnectionFields`) and configured per-connection in the canvas. See [api-script-declaration.md](api-script-declaration.md) for how to declare them (via SwitchScripter).
|
|
25
|
-
|
|
26
|
-
```ts
|
|
27
|
-
connection.getPropertyStringValue(tag: string): Promise<string | string[]>
|
|
28
|
-
```
|
|
29
|
-
Returns the connection property value as a string.
|
|
30
|
-
|
|
31
|
-
```ts
|
|
32
|
-
connection.getPropertyType(tag: string): PropertyType
|
|
33
|
-
```
|
|
34
|
-
Returns the `PropertyType` of the property.
|
|
35
|
-
|
|
36
|
-
```ts
|
|
37
|
-
connection.getPropertyDisplayName(tag: string): string
|
|
38
|
-
```
|
|
39
|
-
Returns the English display name of the property (for use in log messages).
|
|
40
|
-
|
|
41
|
-
```ts
|
|
42
|
-
connection.hasProperty(tag: string): boolean
|
|
43
|
-
```
|
|
44
|
-
Returns `true` if the property exists and is visible for the current configuration.
|
|
45
|
-
|
|
46
|
-
## File count
|
|
47
|
-
|
|
48
|
-
```ts
|
|
49
|
-
connection.getFileCount(nested?: boolean): Promise<number>
|
|
50
|
-
```
|
|
51
|
-
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).
|
|
52
|
-
|
|
53
|
-
## Connection.Level enum
|
|
54
|
-
|
|
55
|
-
Used with `job.sendToData()` and `job.sendToLog()` for traffic light connections.
|
|
56
|
-
|
|
57
|
-
| Value | String |
|
|
58
|
-
|---|---|
|
|
59
|
-
| `Connection.Level.Success` | `"success"` |
|
|
60
|
-
| `Connection.Level.Warning` | `"warning"` |
|
|
61
|
-
| `Connection.Level.Error` | `"error"` |
|
|
62
|
-
|
|
63
|
-
Available as `EnfocusSwitch.Connection.Level.*` outside `main.ts`.
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
# Switch Script Entry Points
|
|
2
|
-
|
|
3
|
-
Entry points are top-level `async` functions with specific names. They are **not exported**. Switch calls them automatically based on flow events.
|
|
4
|
-
|
|
5
|
-
## Flow lifecycle
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
async function flowStartTriggered(s: Switch, flowElement: FlowElement): Promise<void>
|
|
9
|
-
```
|
|
10
|
-
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.
|
|
11
|
-
|
|
12
|
-
```ts
|
|
13
|
-
async function flowStopTriggered(s: Switch, flowElement: FlowElement): Promise<void>
|
|
14
|
-
```
|
|
15
|
-
Called when the flow stops. May execute in parallel for concurrent elements. Not available for debugging.
|
|
16
|
-
|
|
17
|
-
## Timer
|
|
18
|
-
|
|
19
|
-
```ts
|
|
20
|
-
async function timerFired(s: Switch, flowElement: FlowElement): Promise<void>
|
|
21
|
-
```
|
|
22
|
-
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.
|
|
23
|
-
|
|
24
|
-
## Job processing
|
|
25
|
-
|
|
26
|
-
```ts
|
|
27
|
-
async function jobArrived(s: Switch, flowElement: FlowElement, job: Job): Promise<void>
|
|
28
|
-
```
|
|
29
|
-
Called when a job arrives. Must eventually call a `job.sendTo*()` or `job.fail()`. Can run concurrently if configured in the script XML declaration.
|
|
30
|
-
|
|
31
|
-
```ts
|
|
32
|
-
async function abort(s: Switch, flowElement: FlowElement, job: Job, abortData: any): Promise<void>
|
|
33
|
-
```
|
|
34
|
-
Called when an entry point exceeds its configured timeout. The `abortData` value was set beforehand via `s.setAbortData()`. Maximum execution: 60 seconds, after which the script executor is killed. Applies to: `jobArrived`, `timerFired`, `httpRequestTriggeredSync`, `httpRequestTriggeredAsync`, `flowStartTriggered`, `flowStopTriggered`.
|
|
35
|
-
|
|
36
|
-
## Webhooks
|
|
37
|
-
|
|
38
|
-
```ts
|
|
39
|
-
async function httpRequestTriggeredSync(request: HttpRequest, args: any[], response: HttpResponse, s: Switch): Promise<void>
|
|
40
|
-
```
|
|
41
|
-
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}`.
|
|
42
|
-
|
|
43
|
-
```ts
|
|
44
|
-
async function httpRequestTriggeredAsync(request: HttpRequest, args: any[], s: Switch, flowElement: FlowElement): Promise<void>
|
|
45
|
-
```
|
|
46
|
-
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.
|
|
47
|
-
|
|
48
|
-
## Script expression
|
|
49
|
-
|
|
50
|
-
```ts
|
|
51
|
-
async function calculateScriptExpression(s: Switch, flowElement: FlowElement, job: Job): Promise<string | number | boolean>
|
|
52
|
-
```
|
|
53
|
-
Called to evaluate a script expression for the flow element. The return value is used as the expression result.
|
|
54
|
-
|
|
55
|
-
## Property UI callbacks
|
|
56
|
-
|
|
57
|
-
Not available for debugging.
|
|
58
|
-
|
|
59
|
-
```ts
|
|
60
|
-
async function getLibraryForProperty(s: Switch, flowElement: FlowElement, tag: string): Promise<string[]>
|
|
61
|
-
```
|
|
62
|
-
Returns a dynamic list of values for a property's library dropdown.
|
|
63
|
-
|
|
64
|
-
```ts
|
|
65
|
-
async function getLibraryForConnectionProperty(s: Switch, flowElement: FlowElement, c: Connection, tag: string): Promise<string[]>
|
|
66
|
-
```
|
|
67
|
-
Returns a dynamic list of values for a connection property's library dropdown.
|
|
68
|
-
|
|
69
|
-
```ts
|
|
70
|
-
async function validateProperties(s: Switch, flowElement: FlowElement, tags: string[]): Promise<{ tag: string, valid: boolean }[]>
|
|
71
|
-
```
|
|
72
|
-
Validates one or more property values. Return one result object per tag.
|
|
73
|
-
|
|
74
|
-
```ts
|
|
75
|
-
async function validateConnectionProperties(s: Switch, flowElement: FlowElement, c: Connection, tags: string[]): Promise<{ tag: string, valid: boolean }[]>
|
|
76
|
-
```
|
|
77
|
-
Validates one or more connection property values.
|
|
78
|
-
|
|
79
|
-
```ts
|
|
80
|
-
async function findExternalEditorPath(s: Switch, flowElement: FlowElement, tag: string): Promise<string>
|
|
81
|
-
```
|
|
82
|
-
Resolves the path to an external editor for a property.
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
# Job Patterns and Behavioral Rules
|
|
2
|
-
|
|
3
|
-
Common behavioral rules for file access, routing, temp file cleanup, and child jobs. These are the most frequent sources of bugs.
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## File access semantics
|
|
8
|
-
|
|
9
|
-
`job.get(accessLevel)` and `job.getDataset(name, accessLevel)` behave differently depending on the access level:
|
|
10
|
-
|
|
11
|
-
| Access level | What it returns | Modification |
|
|
12
|
-
|---|---|---|
|
|
13
|
-
| `AccessLevel.ReadOnly` | Path in the element's **input folder** | Throws if the file is modified |
|
|
14
|
-
| `AccessLevel.ReadWrite` | Path in a **temp location** (copy) | Auto-uploaded to the output folder when `sendTo*()` is called |
|
|
15
|
-
|
|
16
|
-
Always use `AccessLevel.ReadOnly` unless you need to modify the file content.
|
|
17
|
-
|
|
18
|
-
---
|
|
19
|
-
|
|
20
|
-
## Temp file cleanup
|
|
21
|
-
|
|
22
|
-
Switch does **not** automatically clean up files you create or pass to job-creation methods. The script is responsible:
|
|
23
|
-
|
|
24
|
-
- Files/folders passed to `flowElement.createJob(path)` — delete after routing.
|
|
25
|
-
- Files/folders passed to `job.createChild(path)` — delete after routing.
|
|
26
|
-
- Files/folders passed to `job.createDataset(name, filePath, model)` — delete after routing.
|
|
27
|
-
|
|
28
|
-
> Files accumulate between executor refreshes if not cleaned up. The executor is refreshed after 5 min idle, 5,000 tasks, 150 MB memory, or 1,024 open file handles — at which point accumulated files are removed automatically, but do not rely on this.
|
|
29
|
-
|
|
30
|
-
---
|
|
31
|
-
|
|
32
|
-
## Sending jobs
|
|
33
|
-
|
|
34
|
-
After calling any `job.sendTo*()`:
|
|
35
|
-
- Only further `sendTo*()` calls and `job.fail()` are allowed on that job object.
|
|
36
|
-
- An **unmodified** incoming job can be sent to multiple connections (call `sendTo*()` multiple times).
|
|
37
|
-
- A **modified** job (ReadWrite access used) must use `job.createChild()` to produce additional copies for routing to other connections.
|
|
38
|
-
|
|
39
|
-
```ts
|
|
40
|
-
// Route unmodified job to two connections — OK
|
|
41
|
-
await job.sendToData(Connection.Level.Success);
|
|
42
|
-
await job.sendToData(Connection.Level.Warning); // only if job was not modified
|
|
43
|
-
|
|
44
|
-
// Route modified content to multiple connections — use createChild
|
|
45
|
-
const child = await job.createChild(tempPath);
|
|
46
|
-
await job.sendTo(conn1);
|
|
47
|
-
await child.sendTo(conn2);
|
|
48
|
-
// Clean up tempPath after routing
|
|
49
|
-
await fs.promises.rm(tempPath);
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
---
|
|
53
|
-
|
|
54
|
-
## processLater
|
|
55
|
-
|
|
56
|
-
`job.processLater()` defers the job for the next `timerFired` invocation.
|
|
57
|
-
|
|
58
|
-
Constraints:
|
|
59
|
-
- Minimum deferral: **10 seconds** from the time `jobArrived` was called.
|
|
60
|
-
- Cannot be called on jobs created with `createJob()` or `createChild()`.
|
|
61
|
-
- Private data changes made before `processLater()` are preserved.
|
|
62
|
-
- New datasets created before `processLater()` are **discarded**.
|
|
63
|
-
|
|
64
|
-
---
|
|
65
|
-
|
|
66
|
-
## Executor cleanup thresholds
|
|
67
|
-
|
|
68
|
-
The Node.js executor process is recycled when any of the following thresholds is reached:
|
|
69
|
-
|
|
70
|
-
| Threshold | Value |
|
|
71
|
-
|---|---|
|
|
72
|
-
| Idle time | 5 minutes |
|
|
73
|
-
| Tasks processed | 5,000 |
|
|
74
|
-
| Memory consumption | 150 MB |
|
|
75
|
-
| Open file handles | 1,024 |
|
|
76
|
-
|
|
77
|
-
On cleanup, any files/folders created in the temp area are removed. Always close file handles and database connections before the entry point returns.
|
|
78
|
-
|
|
79
|
-
See [api-execution-environment.md](api-execution-environment.md) for how this process model affects state persistence and error handling across job invocations.
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
# Script Project Structure
|
|
2
|
-
|
|
3
|
-
A Switch script project lives in a **script folder** during development and is distributed as a `.sscript` package (ZIP).
|
|
4
|
-
|
|
5
|
-
> **Agent editing policy**: Edit TypeScript/JavaScript source files (`main.ts`, `main.js`) and the XML declaration (`<ScriptID>.xml`) freely — see [api-script-declaration.md](api-script-declaration.md) for the declaration's rules. Leave `manifest.xml` to the user unless explicitly asked.
|
|
6
|
-
|
|
7
|
-
## Script folder files
|
|
8
|
-
|
|
9
|
-
| File | Required | Notes |
|
|
10
|
-
|---|---|---|
|
|
11
|
-
| `manifest.xml` | Yes | Switch internal use only. Do not edit manually. |
|
|
12
|
-
| `<ScriptID>.xml` | Yes | Script declaration (properties, connections, execution config). See [api-script-declaration.md](api-script-declaration.md). |
|
|
13
|
-
| `main.ts` | Yes (TypeScript) | Source file. Edit this. |
|
|
14
|
-
| `main.js` | Yes | Compiled output executed by Switch. Generated by transpiling `main.ts`. |
|
|
15
|
-
| `main.js.map` | No | Source map, generated alongside `main.js`. |
|
|
16
|
-
| `package.json` | Yes (TypeScript) | NPM config for type declarations. |
|
|
17
|
-
| `tsconfig.json` | Yes (TypeScript) | TypeScript transpilation options. |
|
|
18
|
-
| `<IconFileName>.png` | No | 32×32 px, RGB, not interlaced. Extension must be `.png`. |
|
|
19
|
-
| `node_modules/` | No | Local npm packages. |
|
|
20
|
-
| `Resources/` | No | Extra resource files bundled when packing with SwitchScriptTool. |
|
|
21
|
-
| `<LanguageCode>.ts` | No | Translation files (Switch App SDK). |
|
|
22
|
-
| `.vscode/launch.json` | No | Debug config (created by SwitchScriptTool). |
|
|
23
|
-
| `.vscode/switch.code-snippets` | No | Entry point snippets (TypeScript only). |
|
|
24
|
-
|
|
25
|
-
> After editing `main.ts`, transpile with SwitchScriptTool to regenerate `main.js` before testing in Switch.
|
|
26
|
-
|
|
27
|
-
## manifest.xml format
|
|
28
|
-
|
|
29
|
-
```xml
|
|
30
|
-
<Manifest>
|
|
31
|
-
<ScripterInstanceName>myScript</ScripterInstanceName>
|
|
32
|
-
<SwitchVersion>24.0</SwitchVersion>
|
|
33
|
-
<ScriptPackageFormatVersion>1.0</ScriptPackageFormatVersion>
|
|
34
|
-
<ScriptPasswordProtected>No</ScriptPasswordProtected>
|
|
35
|
-
<ScriptPackageType>Script</ScriptPackageType>
|
|
36
|
-
<ScriptDeclarationFile>myScript.xml</ScriptDeclarationFile>
|
|
37
|
-
<ScriptProgramFiles>
|
|
38
|
-
<ScriptProgramFile ScriptLanguage="NodeJSScript">main.ts</ScriptProgramFile>
|
|
39
|
-
</ScriptProgramFiles>
|
|
40
|
-
<ScriptIconFile>myScript_32.png</ScriptIconFile>
|
|
41
|
-
<LocalizationItems/>
|
|
42
|
-
</Manifest>
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
`ScriptPackageType` is either `Script` (regular) or `App` (scripted plug-in).
|
|
46
|
-
|
|
47
|
-
## Node.js version per Switch version
|
|
48
|
-
|
|
49
|
-
`SwitchVersion` in `manifest.xml` determines which Node.js version executes the script — Switch uses the **latest** Node.js version bundled with the Switch release that created the script.
|
|
50
|
-
|
|
51
|
-
| Switch version | `SwitchVersion` | Node.js used |
|
|
52
|
-
|---|---|---|
|
|
53
|
-
| Switch 2020 Spring | `20.0` | 12 |
|
|
54
|
-
| Switch 2020 Fall | `20.1` | 12 |
|
|
55
|
-
| Switch 2021 Spring | `21.0` | 14 |
|
|
56
|
-
| Switch 2021 Fall | `21.1` | 16 |
|
|
57
|
-
| Switch 2022 Spring | `22.0` | 16 |
|
|
58
|
-
| Switch 2022 Fall | `22.1` | 16 |
|
|
59
|
-
| Switch 2023 Fall | `23.1` | 18 |
|
|
60
|
-
| Switch 2024 Spring | `24.0` | 18 |
|
|
61
|
-
| Switch 2024 Fall | `24.1` | 20 |
|
|
62
|
-
| Switch 25.11 | `25.11` | 20 |
|
|
63
|
-
|
|
64
|
-
> **Mac (Apple Silicon):** For scripts created in Switch 2021 Fall or later, Switch runs the native ARM build of Node.js on Apple Silicon. Scripts created in earlier versions run under Rosetta using the Intel Node.js build. If a script bundles platform-specific binaries, ship both Intel and ARM variants.
|
|
65
|
-
|
|
66
|
-
## Script vs App
|
|
67
|
-
|
|
68
|
-
| | Script | App |
|
|
69
|
-
|---|---|---|
|
|
70
|
-
| `ScriptPackageType` | `Script` | `App` |
|
|
71
|
-
| Appears in Elements pane | No (used via Script element) | Yes, as its own element |
|
|
72
|
-
| Distribution | Freely | Enfocus Appstore only |
|
|
73
|
-
| Position in pane | — | Configured via `PositionInElementPane` in XML |
|
|
74
|
-
|
|
75
|
-
## Execution modes
|
|
76
|
-
|
|
77
|
-
Set in the XML declaration via SwitchScripter. Applies to all instances of the script.
|
|
78
|
-
|
|
79
|
-
**Concurrent** — entry points for the same or different instances may run in parallel. Scripts must synchronize access to any shared resources.
|
|
80
|
-
|
|
81
|
-
**Serialized** — entry points within the same **execution group** are never concurrent. Instances in different execution groups may still run in parallel.
|
|
82
|
-
|
|
83
|
-
**Execution group** — only relevant for Serialized mode. Should be a reverse-domain string (e.g. `com.mycompany.myScript`) to avoid collisions. Defaults to the Script ID if left empty.
|
|
84
|
-
|
|
85
|
-
See [api-execution-environment.md](api-execution-environment.md#two-independent-concurrency-tiers) — neither `NumberOfSlots` nor execution group maps to a count of Node.js OS processes; they gate job dispatch on the Switch Server, separate from the pooled executor processes that actually run script code.
|