@cxtms/cx-schema 1.8.1 → 1.9.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 (72) hide show
  1. package/README.md +34 -34
  2. package/dist/cli.js +2408 -177
  3. package/dist/cli.js.map +1 -1
  4. package/dist/types.d.ts +2 -0
  5. package/dist/types.d.ts.map +1 -1
  6. package/dist/validator.d.ts +8 -0
  7. package/dist/validator.d.ts.map +1 -1
  8. package/dist/validator.js +54 -2
  9. package/dist/validator.js.map +1 -1
  10. package/dist/workflowValidator.d.ts +4 -0
  11. package/dist/workflowValidator.d.ts.map +1 -1
  12. package/dist/workflowValidator.js +28 -2
  13. package/dist/workflowValidator.js.map +1 -1
  14. package/package.json +2 -2
  15. package/schemas/components/appComponent.json +8 -0
  16. package/schemas/components/module.json +31 -2
  17. package/schemas/components/timelineGrid.json +4 -0
  18. package/schemas/schemas.json +12 -0
  19. package/schemas/workflows/tasks/authentication.json +26 -12
  20. package/schemas/workflows/workflow.json +0 -4
  21. package/scripts/postinstall.js +16 -13
  22. package/{.claude/skills/cx-core → skills/cxtms-developer}/SKILL.md +16 -14
  23. package/skills/cxtms-developer/ref-cli-auth.md +120 -0
  24. package/{.claude/skills/cx-core → skills/cxtms-developer}/ref-entity-accounting.md +7 -0
  25. package/{.claude/skills/cx-core → skills/cxtms-developer}/ref-entity-commodity.md +12 -0
  26. package/{.claude/skills/cx-core → skills/cxtms-developer}/ref-entity-contact.md +10 -0
  27. package/{.claude/skills/cx-core → skills/cxtms-developer}/ref-entity-geography.md +34 -1
  28. package/{.claude/skills/cx-core → skills/cxtms-developer}/ref-entity-order-sub.md +13 -0
  29. package/{.claude/skills/cx-core → skills/cxtms-developer}/ref-entity-order.md +14 -0
  30. package/{.claude/skills/cx-core → skills/cxtms-developer}/ref-entity-rate.md +8 -0
  31. package/{.claude/skills/cx-core → skills/cxtms-developer}/ref-entity-shared.md +9 -0
  32. package/{.claude/skills/cx-core → skills/cxtms-developer}/ref-entity-warehouse.md +5 -0
  33. package/skills/cxtms-developer/ref-graphql-query.md +320 -0
  34. package/{.claude/skills/cx-module → skills/cxtms-module-builder}/SKILL.md +112 -37
  35. package/{.claude/skills/cx-module → skills/cxtms-module-builder}/ref-components-data.md +7 -0
  36. package/{.claude/skills/cx-module → skills/cxtms-module-builder}/ref-components-display.md +17 -0
  37. package/{.claude/skills/cx-module → skills/cxtms-module-builder}/ref-components-forms.md +7 -1
  38. package/{.claude/skills/cx-module → skills/cxtms-module-builder}/ref-components-interactive.md +11 -0
  39. package/{.claude/skills/cx-module → skills/cxtms-module-builder}/ref-components-layout.md +11 -0
  40. package/{.claude/skills/cx-module → skills/cxtms-module-builder}/ref-components-specialized.md +50 -0
  41. package/{.claude/skills/cx-workflow → skills/cxtms-workflow-builder}/SKILL.md +139 -30
  42. package/{.claude/skills/cx-workflow → skills/cxtms-workflow-builder}/ref-communication.md +8 -0
  43. package/{.claude/skills/cx-workflow → skills/cxtms-workflow-builder}/ref-entity.md +43 -0
  44. package/skills/cxtms-workflow-builder/ref-expressions-ncalc.md +128 -0
  45. package/skills/cxtms-workflow-builder/ref-expressions-template.md +159 -0
  46. package/{.claude/skills/cx-workflow → skills/cxtms-workflow-builder}/ref-flow.md +8 -1
  47. package/{.claude/skills/cx-workflow → skills/cxtms-workflow-builder}/ref-other.md +9 -0
  48. package/templates/module-configuration.yaml +23 -89
  49. package/templates/module-form.yaml +3 -3
  50. package/templates/module-grid.yaml +3 -3
  51. package/templates/module-select.yaml +3 -3
  52. package/templates/module.yaml +3 -2
  53. package/templates/workflow-api-tracking.yaml +1 -1
  54. package/templates/workflow-basic.yaml +1 -1
  55. package/templates/workflow-document.yaml +1 -1
  56. package/templates/workflow-entity-trigger.yaml +1 -1
  57. package/templates/workflow-ftp-edi.yaml +1 -1
  58. package/templates/workflow-ftp-tracking.yaml +1 -1
  59. package/templates/workflow-mcp-tool.yaml +1 -1
  60. package/templates/workflow-public-api.yaml +1 -1
  61. package/templates/workflow-scheduled.yaml +1 -1
  62. package/templates/workflow-utility.yaml +1 -1
  63. package/templates/workflow-webhook.yaml +1 -1
  64. package/templates/workflow.yaml +1 -1
  65. package/.claude/skills/cx-workflow/ref-expressions.md +0 -272
  66. /package/{.claude/skills/cx-core → skills/cxtms-developer}/ref-entity-job.md +0 -0
  67. /package/{.claude/skills/cx-core → skills/cxtms-developer}/ref-entity-notification.md +0 -0
  68. /package/{.claude/skills/cx-core → skills/cxtms-developer}/ref-entity-organization.md +0 -0
  69. /package/{.claude/skills/cx-workflow → skills/cxtms-workflow-builder}/ref-accounting.md +0 -0
  70. /package/{.claude/skills/cx-workflow → skills/cxtms-workflow-builder}/ref-filetransfer.md +0 -0
  71. /package/{.claude/skills/cx-workflow → skills/cxtms-workflow-builder}/ref-query.md +0 -0
  72. /package/{.claude/skills/cx-workflow → skills/cxtms-workflow-builder}/ref-utilities.md +0 -0
@@ -1,27 +1,36 @@
1
1
  ---
2
- name: cx-workflow
3
- description: Generate schema-valid CargoXplorer workflow YAML files (standard process and Flow state machine workflows)
2
+ name: cxtms-workflow-builder
3
+ description: >
4
+ Works with CXTMS workflow YAML files — creates, modifies, fixes, validates, and deploys standard process and Flow state machine workflows.
5
+ Use when the user asks to create, modify, or fix a workflow YAML file, references workflow/*.yaml files, or asks about workflow tasks/triggers/activities in a CX project.
6
+ Not for module YAML files, TypeScript code, or non-YAML tasks.
4
7
  argument-hint: <description of what to build>
5
8
  ---
6
9
 
7
10
  You are a CargoXplorer workflow YAML builder. You generate schema-valid YAML for CX workflows — both standard process workflows (activities, steps, triggers) and Flow state machine workflows (entity lifecycle, states, transitions). All output must conform to the JSON schemas in `.cx-schema/`.
8
11
 
9
- **IMPORTANT — use `cx-cli` for all workflow operations:**
10
- - **Scaffold**: `npx cx-cli create workflow <name> --template <template>` — generates a schema-valid YAML file. ALWAYS run this first, then read the generated file, then customize. Do NOT write YAML from scratch or copy templates manually.
11
- - **Validate**: `npx cx-cli <file.yaml>` — run after every change
12
- - **Schema lookup**: `npx cx-cli schema <task>` — e.g., `cx-cli schema graphql`, `cx-cli schema foreach`, `cx-cli schema action-event`. Schema names use kebab-case file names. Case-insensitive: `ActionEvent` resolves to `action-event`.
13
- - **Examples**: `npx cx-cli example <task>` — show example YAML for a task
14
- - **List schemas**: `npx cx-cli list --type workflow` — shows all available task schemas in the Tasks section
15
- - **Feature folder**: `npx cx-cli create workflow <name> --template <template> --feature <feature-name>`
12
+ **IMPORTANT — use `cxtms` for all workflow operations:**
13
+ - **Scaffold**: `npx cxtms create workflow <name> --template <template>` — generates a schema-valid YAML file. ALWAYS run this first, then read the generated file, then customize. Do NOT write YAML from scratch or copy templates manually.
14
+ - **Validate**: `npx cxtms <file.yaml>` — run after every change
15
+ - **Schema lookup**: `npx cxtms schema <task>` — e.g., `cxtms schema graphql`, `cxtms schema foreach`, `cxtms schema action-event`. Schema names use kebab-case file names. Case-insensitive: `ActionEvent` resolves to `action-event`.
16
+ - **Examples**: `npx cxtms example <task>` — show example YAML for a task
17
+ - **List schemas**: `npx cxtms list --type workflow` — shows all available task schemas in the Tasks section
18
+ - **Feature folder**: `npx cxtms create workflow <name> --template <template> --feature <feature-name>`
19
+ - **Deploy to server**: `npx cxtms workflow deploy <file.yaml> --org <id>` — creates or updates workflow on the CX server
20
+ - **Undeploy from server**: `npx cxtms workflow undeploy <workflowId> --org <id>` — removes a workflow by UUID
21
+ - **Execute**: `npx cxtms workflow execute <workflowId|file.yaml> --org <id> [--vars '<json>'] [--file varName=path]` — trigger a workflow execution (--file uploads a local file and passes the URL as a variable)
22
+ - **List logs**: `npx cxtms workflow logs <workflowId|file.yaml> --org <id> [--from YYYY-MM-DD] [--to YYYY-MM-DD]` — list executions with log availability
23
+ - **Download log**: `npx cxtms workflow log <executionId> --org <id> [--json] [--console] [--output <file>]` — download execution log
24
+ - **Publish all**: `npx cxtms publish [--feature <name>] --org <id>` — deploy all modules and workflows to the server
16
25
 
17
26
  ## Generation Workflow
18
27
 
19
28
  ### Step 1: Scaffold via CLI — MANDATORY
20
29
 
21
- **You MUST run `cx-cli create workflow` to generate the initial file.** Do not skip this step. Do not write YAML from scratch. Do not read template files and copy them manually. The CLI generates correct UUIDs, file paths, and structure.
30
+ **You MUST run `cxtms create workflow` to generate the initial file.** Do not skip this step. Do not write YAML from scratch. Do not read template files and copy them manually. The CLI generates correct UUIDs, file paths, and structure.
22
31
 
23
32
  ```bash
24
- npx cx-cli create workflow <name> --template <template>
33
+ npx cxtms create workflow <name> --template <template>
25
34
  ```
26
35
 
27
36
  | Template | Use Case |
@@ -66,12 +75,12 @@ npx cx-cli create workflow <name> --template <template>
66
75
 
67
76
  **All templates** include workflow-level `events` (`onWorkflowStarted`, `onWorkflowExecuted`, `onWorkflowFailed`) and activity-level `events` (`onActivityStarted`, `onActivityCompleted`, `onActivityFailed`) with Log steps. Replace/extend these with notification tasks (Email/Send, HttpRequest, Workflow/Execute) as needed.
68
77
 
69
- **Flow workflows** — scaffold with `basic` then set `workflowType: Flow`, remove `activities`/`triggers`, add `entity`, `states`, `transitions`, `aggregations`. Load Flow reference: `!cat .claude/skills/cx-workflow/ref-flow.md`
78
+ **Flow workflows** — scaffold with `basic` then set `workflowType: Flow`, remove `activities`/`triggers`, add `entity`, `states`, `transitions`, `aggregations`. Load Flow reference: `!cat skills/cxtms-workflow-builder/ref-flow.md`
70
79
 
71
80
  ### Step 4: Validate
72
81
 
73
82
  ```bash
74
- npx cx-cli <generated-file.yaml>
83
+ npx cxtms <generated-file.yaml>
75
84
  ```
76
85
 
77
86
  ### File Placement
@@ -182,7 +191,8 @@ events: # Workflow-level event handlers
182
191
 
183
192
  ## Variable References (quick summary)
184
193
 
185
- For full reference: `!cat .claude/skills/cx-workflow/ref-expressions.md`
194
+ For template expressions and value directives: see [ref-expressions-template.md](skills/cxtms-workflow-builder/ref-expressions-template.md)
195
+ For NCalc conditions and functions: see [ref-expressions-ncalc.md](skills/cxtms-workflow-builder/ref-expressions-ncalc.md)
186
196
 
187
197
  **`{{ path }}`** — in step inputs. Single `{{ }}` returns raw object. Multiple returns string interpolation.
188
198
  **`[variable]`** — in conditions and `expression:` directives. NCalc syntax.
@@ -269,24 +279,25 @@ Implicit variable: `iteration` (zero-based).
269
279
 
270
280
  | Category | Tasks | Load Reference |
271
281
  |----------|-------|----------------|
272
- | Utilities | SetVariable, Log, Error, HttpRequest, Map, Template, Import, Export, CsvParse, UnzipFile | `!cat .claude/skills/cx-workflow/ref-utilities.md` |
273
- | Query & Workflow | Query/GraphQL, Validation, Workflow/Execute | `!cat .claude/skills/cx-workflow/ref-query.md` |
274
- | Entity CRUD | Order, Contact, Commodity, Job, Charge, Discount, Inventory, Movement, Transmission | `!cat .claude/skills/cx-workflow/ref-entity.md` |
275
- | Communication | Email/Send, Document/Render, Attachment, PdfDocument/Merge | `!cat .claude/skills/cx-workflow/ref-communication.md` |
276
- | File Transfer | Connect, Disconnect, ListFiles, Download, Upload, Move, Delete | `!cat .claude/skills/cx-workflow/ref-filetransfer.md` |
277
- | Accounting | AccountingTransaction, Payment, Number/Generate, SequenceNumber | `!cat .claude/skills/cx-workflow/ref-accounting.md` |
278
- | Other | User, Auth, Caching, X12/Parse, EDIFACT, Flow/Transition, Notes, AppModule, ActionEvent | `!cat .claude/skills/cx-workflow/ref-other.md` |
282
+ | Utilities | SetVariable, Log, Error, HttpRequest, Map, Template, Import, Export, CsvParse, UnzipFile | `!cat skills/cxtms-workflow-builder/ref-utilities.md` |
283
+ | Query & Workflow | Query/GraphQL, Validation, Workflow/Execute | `!cat skills/cxtms-workflow-builder/ref-query.md` |
284
+ | Entity CRUD | Order, Contact, Commodity, Job, Charge, Discount, Inventory, Movement, Transmission | `!cat skills/cxtms-workflow-builder/ref-entity.md` |
285
+ | Communication | Email/Send, Document/Render, Attachment, PdfDocument/Merge | `!cat skills/cxtms-workflow-builder/ref-communication.md` |
286
+ | File Transfer | Connect, Disconnect, ListFiles, Download, Upload, Move, Delete | `!cat skills/cxtms-workflow-builder/ref-filetransfer.md` |
287
+ | Accounting | AccountingTransaction, Payment, Number/Generate, SequenceNumber | `!cat skills/cxtms-workflow-builder/ref-accounting.md` |
288
+ | Other | User, Auth, Caching, X12/Parse, EDIFACT, Flow/Transition, Notes, AppModule, ActionEvent | `!cat skills/cxtms-workflow-builder/ref-other.md` |
279
289
 
280
- ## Entity Field Reference (cx-core)
290
+ ## Entity Field Reference (cxtms-developer)
281
291
 
282
- !cat .claude/skills/cx-core/SKILL.md
292
+ !cat skills/cxtms-developer/SKILL.md
283
293
 
284
294
  ## Additional References (load on demand)
285
295
 
286
296
  | Reference | Load |
287
297
  |-----------|------|
288
- | Expressions & Functions | `!cat .claude/skills/cx-workflow/ref-expressions.md` |
289
- | Flow Workflows (state machines) | `!cat .claude/skills/cx-workflow/ref-flow.md` |
298
+ | Template Expressions & Value Directives | `!cat skills/cxtms-workflow-builder/ref-expressions-template.md` |
299
+ | NCalc Expressions & Functions | `!cat skills/cxtms-workflow-builder/ref-expressions-ncalc.md` |
300
+ | Flow Workflows (state machines) | `!cat skills/cxtms-workflow-builder/ref-flow.md` |
290
301
 
291
302
  ## Dynamic Schema Access (load on demand)
292
303
 
@@ -307,19 +318,117 @@ Implicit variable: `iteration` (zero-based).
307
318
 
308
319
  ---
309
320
 
310
- ## Debugging Workflow Executions
321
+ ## Server Workflow Commands
311
322
 
312
- When TMS MCP returns gzip file URLs for workflow execution logs, decompress with:
323
+ Deploy, undeploy, and release commands are listed in the CLI section at the top of this file. For authentication setup (login, PAT tokens, org management): see [cxtms-developer/ref-cli-auth.md](skills/cxtms-developer/ref-cli-auth.md)
324
+
325
+ ### Releasing App to GitHub
326
+
327
+ Use `app release` to release modified workflows and modules from the CX server to a GitHub repository. This creates a branch and pull request — it does NOT push directly to the target branch.
313
328
 
314
329
  ```bash
315
- node -e "const https=require('https'),zlib=require('zlib'),fs=require('fs');https.get(process.argv[1],r=>r.pipe(zlib.createGunzip()).pipe(fs.createWriteStream(process.argv[2])))" "<url>" "<output-file>"
330
+ # Release all unpublished changes to GitHub (creates a PR) message is required
331
+ npx cxtms app release -m "Add order notification workflow"
332
+
333
+ # Release specific workflows and/or modules by YAML file
334
+ npx cxtms app release -m "Fix tracking workflow" workflows/my-workflow.yaml
335
+ npx cxtms app release -m "Update shipping" workflows/a.yaml modules/b.yaml
336
+
337
+ # Force release all workflows and modules (not just unpublished ones)
338
+ npx cxtms app release -m "Full republish" --force
339
+
340
+ # Release with explicit org
341
+ npx cxtms app release -m "Add order notification workflow" --org 42
316
342
  ```
317
343
 
344
+ **What `app release` does:**
345
+ 1. Reads `app.yaml` for the `id` (appManifestId), repository, and branch
346
+ 2. Increments the app version (patch bump)
347
+ 3. Creates a `publish/{app-name}-v{version}-{timestamp}` branch on GitHub
348
+ 4. Commits `app.yaml` + selected workflow/module YAML files to the branch
349
+ 5. Creates a pull request from the publish branch to the target branch
350
+ 6. Marks published workflows and modules as `hasUnpublishedChanges: false`
351
+
352
+ **This is a release-to-git operation** — it commits the current server-side YAML directly to GitHub via the API. No local git repo is involved. The workflows and modules being released are taken from the CX server database, not from local files. The YAML file arguments only identify *which* items to include by their IDs.
353
+
354
+ **Important:** Workflows and modules must be deployed to the TMS server before they can be released. Use `cxtms workflow deploy` or `cxtms appmodule deploy` first, then `cxtms app release` to commit them to GitHub.
355
+
356
+ **Do NOT run `app release` automatically.** Only release when the user explicitly requests it. Releasing creates a branch and PR on GitHub, so it should be done once when all changes are ready — not after every deploy.
357
+
358
+ **Prerequisites:**
359
+ - `app.yaml` must exist with a valid `id` field
360
+ - The app manifest must be installed on the server (`app install` first)
361
+ - The server must have a GitHub token configured for the organization
362
+ - The repository and branch must be set on the app manifest
363
+
364
+ **Related commands:**
365
+ - `npx cxtms app install` — install/refresh app from GitHub into the server
366
+ - `npx cxtms app install --force` — force reinstall even if same version
367
+ - `npx cxtms app install --branch develop` — install from a specific branch
368
+ - `npx cxtms app install --skip-changed` — skip modules with local changes
369
+ - `npx cxtms app list` — list installed app manifests on the server
370
+
371
+ ### Execute
372
+
373
+ ```bash
374
+ # Execute a workflow by UUID or YAML file
375
+ npx cxtms workflow execute <workflowId>
376
+ npx cxtms workflow execute workflows/my-workflow.yaml
377
+
378
+ # Pass input variables as JSON
379
+ npx cxtms workflow execute <workflowId> --vars '{"city": "London", "count": 5}'
380
+
381
+ # Upload a local file and pass its URL as a workflow variable
382
+ npx cxtms workflow execute workflow.yaml --file importFile=/path/to/data.csv
383
+
384
+ # Combine variables and file uploads
385
+ npx cxtms workflow execute workflow.yaml --vars '{"mode": "preview"}' --file importFile=data.csv --file templateFile=template.xlsx
386
+ ```
387
+
388
+ `--file varName=path` uploads the local file to the server via presigned URL and sets the resulting URL as the named variable. Can be specified multiple times.
389
+
390
+ Returns execution result including `executionId`, `isAsync`, `outputs` (for Sync workflows).
391
+
392
+ ### Execution Logs
393
+
394
+ ```bash
395
+ # List executions with log availability (sorted desc by date)
396
+ npx cxtms workflow logs <workflowId|file.yaml>
397
+
398
+ # Filter by date range
399
+ npx cxtms workflow logs <workflowId> --from 2026-01-01 --to 2026-01-31
400
+
401
+ # Download a specific execution log (saves to temp dir by default)
402
+ npx cxtms workflow log <executionId>
403
+
404
+ # Save to specific file
405
+ npx cxtms workflow log <executionId> --output mylog.txt
406
+
407
+ # Print to stdout
408
+ npx cxtms workflow log <executionId> --console
409
+
410
+ # Download JSON log (richer data: inputs, outputs, timing, metadata)
411
+ npx cxtms workflow log <executionId> --json
412
+
413
+ # JSON log to stdout
414
+ npx cxtms workflow log <executionId> --json --console
415
+ ```
416
+
417
+ `workflow logs` shows a table with execution status, date, duration, user, and log availability indicators (filled/empty circle). `workflow log` downloads the actual log content from the server (gzip-compressed S3 URLs).
418
+
419
+ ### Debugging Tips
420
+
421
+ - Use `--json` for detailed structured data (ExecutionId, Inputs, Outputs, Exception, timing)
422
+ - Text logs show step-by-step execution trace with timestamps
423
+ - Sync workflow executions may not appear in `workflow logs` — they return results inline
424
+ - Use `workflow execute --vars` to test workflows with specific inputs
425
+ - Use `workflow execute --file varName=path` to upload local files for workflows that expect file URL inputs
426
+
318
427
  ---
319
428
 
320
429
  ## Generation Rules
321
430
 
322
- 1. **Always scaffold via `cx-cli create workflow` first** — never write YAML from scratch, never copy templates manually
431
+ 1. **Always scaffold via `cxtms create workflow` first** — never write YAML from scratch, never copy templates manually
323
432
  2. **Naming conventions**: step names PascalCase, variables camelCase, states PascalCase, transitions camelCase
324
433
  3. **Template expressions** use `{{ expression }}` — NCalc conditions use `[variable]`
325
434
  4. **Do not change `workflowId` or `filePath`** — set correctly by CLI scaffold
@@ -327,4 +436,4 @@ node -e "const https=require('https'),zlib=require('zlib'),fs=require('fs');http
327
436
  6. **Flow workflows** require `entity`, `states`, `transitions` (no `activities`)
328
437
  7. **Entity triggers** require `entityName` and `eventType`
329
438
  8. **Always use null-safe `?`** on variable paths — `Activity?.Step?.output?` — unless referencing guaranteed system variables (see Variable References section)
330
- 9. **Always validate** the final YAML: `npx cx-cli <file.yaml>`
439
+ 9. **Always validate** the final YAML: `npx cxtms <file.yaml>`
@@ -1,5 +1,13 @@
1
1
  # Communication & Document Tasks Reference
2
2
 
3
+ ## Contents
4
+ - Email/Send task (send emails with templates and attachments)
5
+ - Email/VerifyCode task (send and verify email verification codes)
6
+ - Document/Render task (render PDF or Excel from HTML templates)
7
+ - Document/Send task (send a previously rendered document)
8
+ - Attachment tasks (Create, Update, Thumbnail, PdfThumbnail, RegenerateThumbnails)
9
+ - PdfDocument/Merge task (merge multiple PDFs into one)
10
+
3
11
  ## Email/Send
4
12
 
5
13
  Sends emails with optional templates and attachments.
@@ -1,7 +1,50 @@
1
1
  # Entity CRUD Tasks Reference
2
2
 
3
+ ## Contents
4
+ - Entity/Change task (generic entity modification in Before triggers)
5
+ - Order tasks (Create, Update, Delete, Get, Copy, Split, Import, etc.)
6
+ - Contact tasks (Create, Update, Delete)
7
+ - ContactAddress tasks (Create, Update, Delete, Import)
8
+ - ContactPaymentMethod tasks (Create, Update, SendChargedAmount, VerifyChargedAmount)
9
+ - Commodity tasks (Create, Update, Split, Repack, Unpack)
10
+ - CommodityTrackingNumber tasks (Create, Update, Delete)
11
+ - Job tasks (Create, Update, Delete, Assign, Unassign)
12
+ - Charge tasks (Create, Update, Delete, DynamicUpdate, Calculate)
13
+ - Discount task (Update)
14
+ - Order sub-entity tasks (OrderCommodity, OrderCharge, OrderDocument, OrderTrackingEvent, OrderEntity)
15
+ - Inventory tasks (InventoryItem Create, Update, Delete)
16
+ - Other entity tasks (Movement, Country, Cities, Rate, TrackingEvent/Import)
17
+ - Note tasks (Create, Update, Delete, Import, Export, RenameThread)
18
+ - AccountingTransaction/ApplyCredit task
19
+
3
20
  All entity tasks follow the `Namespace/Operation@Version` pattern. Outputs are stored as `ActivityName.StepName.outputKey`.
4
21
 
22
+ ## PostalCodes
23
+
24
+ | Task | Description |
25
+ |------|-------------|
26
+ | `PostalCodes/Import@1` | Import postal codes from file URL, stream, or inline data |
27
+
28
+ ### PostalCodes/Import@1
29
+
30
+ Imports postal codes (CSV, JSON, Excel). Supports upsert via `matchByFields`.
31
+
32
+ ```yaml
33
+ - task: "PostalCodes/Import@1"
34
+ name: ImportPostalCodes
35
+ inputs:
36
+ organizationId: "{{ int inputs.organizationId }}"
37
+ fileUrl: "{{ inputs.fileUrl }}"
38
+ matchByFields: ["code", "countryCode"]
39
+ outputs:
40
+ - name: importResult
41
+ mapping: "result?"
42
+ ```
43
+
44
+ **Inputs:** `organizationId` (int, required), `fileUrl` (string?), `fileType` (FileType?), `stream` (Stream?), `postalCodes` (List?), `matchByFields` (string[]?)
45
+ **Outputs:** `result.success`, `result.added`, `result.updated`, `result.errors`, `result.totalProcessed`, `result.hasErrors`
46
+ Input priority: `stream` > `fileUrl` > `postalCodes`. Task catches exceptions and returns them in `result.errors`.
47
+
5
48
  ## Generic Entity Change
6
49
 
7
50
  | Task | Description |
@@ -0,0 +1,128 @@
1
+ # NCalc Expressions & Functions
2
+
3
+ ## Contents
4
+ - NCalc expression syntax `[variable]` (in conditions and expression directives)
5
+ - Operators (comparison, logical, arithmetic, ternary, membership)
6
+ - Iterator variables (`[each.*]` and `[item.*]`)
7
+ - Collection functions (any, all, count, sum, first, last, distinct, groupBy, join, etc.)
8
+ - String functions (isNullOrEmpty, length, lower, upper, replace, format, base64, etc.)
9
+ - Date functions (now, parseDate, addDays, formatDate, dateFromUnix, etc.)
10
+ - Math functions (Abs, Ceiling, Floor, Round, Min, Max, etc.)
11
+ - Domain functions (convertWeight, convertDimension)
12
+
13
+ For template expressions `{{ path }}` used in step inputs, see [ref-expressions-template.md](ref-expressions-template.md).
14
+
15
+ ## NCalc Expressions: `[variable]` (in conditions and expression directives)
16
+
17
+ Used in `conditions[].expression`, `switch` case `when`, and `expression:` value directives. Variables use **square bracket** `[name]` syntax.
18
+
19
+ ```yaml
20
+ conditions:
21
+ - expression: "[status] = 'Active' AND [amount] > 100"
22
+ - expression: "isNullOrEmpty([Data.GetOrder.order?]) = false"
23
+ - expression: "any([changes], [each.key] = 'Status') = true"
24
+ ```
25
+
26
+ **Parameter resolution rules**:
27
+ - Empty strings are converted to `null` (so `""` is treated as no value)
28
+ - Numeric strings are auto-converted to `decimal` when needed (e.g., `[price] > 100` works even if price is the string `"150"`)
29
+ - Dot paths resolve deep: `[Activity.Step.output.nested.field]`
30
+ - Optional suffix `?` prevents errors: `[order.customer?.name?]`
31
+
32
+ ### Operators
33
+
34
+ | Type | Operators |
35
+ |------|-----------|
36
+ | Comparison | `=`, `!=`, `<>`, `<`, `>`, `<=`, `>=` |
37
+ | Logical | `AND`, `OR`, `NOT` (also `&&`, `\|\|`, `!`) |
38
+ | Arithmetic | `+`, `-`, `*`, `/`, `%` |
39
+ | Ternary | `if(condition, trueVal, falseVal)` |
40
+ | Membership | `in(value, val1, val2, ...)` |
41
+
42
+ ### Iterator Variables
43
+
44
+ Functions use two iterator variable names:
45
+ - **`[each.*]`** -- used by: `any`, `all`, `sum`, `join` (3-arg)
46
+ - **`[item.*]`** -- used by: `first`, `last`, `groupBy`
47
+
48
+ ### Collection Functions
49
+
50
+ | Function | Description |
51
+ |----------|-------------|
52
+ | `any([items], [each.prop] = 'val')` | True if any item matches expression. Without expression: checks if collection contains the value |
53
+ | `all([items], [each.prop] > 0)` | True if all items match. Returns `false` for null/empty collections |
54
+ | `count([items])` | Count items in list or JToken. Returns `0` for non-collections |
55
+ | `sum([items], [each.amount])` | Sum values as `decimal`. Optional `[each.*]` accessor. Skips nulls |
56
+ | `first([items])` or `first([items], [item.name])` | First item or evaluate expression on first item. Returns `""` if empty |
57
+ | `last([items])` or `last([items], [item.name])` | Last item or evaluate expression on last item. Returns `""` if empty |
58
+ | `distinct([items])` | Remove duplicates. Uses deep comparison for dictionaries |
59
+ | `reverse([items])` | Reverse collection or string |
60
+ | `contains([source], 'needle')` | String contains, JArray contains, list contains, or dict key/value contains |
61
+ | `removeEmpty([items])` | Remove null and whitespace-only items |
62
+ | `concat([list1], [list2], ...)` | Concatenate multiple collections into flat list. Variadic args. Skips nulls |
63
+ | `groupBy([items], [item.cat])` | Group by one or more key expressions. Returns `[{key, items}]`. Multi-key: keys joined with `\|` |
64
+ | `join([items], [each.name], ',')` | Join collection with `[each.*]` accessor and separator (3-arg) |
65
+ | `join([items], ',')` | Join collection directly with separator (2-arg) |
66
+ | `split([str], ' ')` | Split string by first character of separator. Returns `List<string>` |
67
+ | `elementAt([items], 0)` | Get element at index (zero-based) from list |
68
+
69
+ ### String Functions
70
+
71
+ | Function | Description |
72
+ |----------|-------------|
73
+ | `isNullOrEmpty([var])` | True if null, empty string, or empty list |
74
+ | `length([var])` | String length or collection count. `0` for null strings and non-collections |
75
+ | `lower([name])` / `upper([code])` | Case conversion. Handles string, JToken, any `.ToString()` |
76
+ | `left([code], 3)` / `right([code], 3)` | Left/right N characters. Returns full string if shorter than N |
77
+ | `substring([str], 0, 5)` | Extract substring starting at position for given length |
78
+ | `replace([str], 'old', 'new')` | String replacement. Returns null if any arg is null |
79
+ | `trim([value])` | Trim whitespace. Returns `""` for null |
80
+ | `format('{0}-{1}', [prefix], [id])` | String.Format style. Variadic args. Returns null if format is null |
81
+ | `base64([value])` / `fromBase64([encoded])` | Base64 encode/decode. Handles string, byte[], JToken |
82
+ | `bool([value])` | Convert to boolean: null->`false`, empty string->`false`, "true"/"false"->parsed, non-zero number->`true`, any object->`true` |
83
+ | `transliterate([value])` | Unicode to ASCII (Unidecode). Returns `""` for null |
84
+ | `transliterateUa([value])` | Ukrainian-specific transliteration. Returns `""` for null |
85
+ | `parseAddress([address])` | Parse address -> `{StreetNumber, StreetName}`. Handles US and EU formats |
86
+
87
+ ### Date Functions
88
+
89
+ | Function | Description |
90
+ |----------|-------------|
91
+ | `parseDate([str])` | Parse date string to DateTime. Supports common formats (ISO, US, etc.) |
92
+ | `now()` | Current UTC `DateTime` |
93
+ | `now('yyyy-MM-dd', 'en-US')` | Formatted current time as string |
94
+ | `addDays([date], 30)` | Add days (decimal, can be negative). Accepts DateTime, DateTimeOffset, string |
95
+ | `addHours([date], 2)` | Add hours (decimal, can be negative). Same type handling |
96
+ | `formatDate([date], 'dd/MM/yyyy', 'en-US')` | Format date with culture. Accepts DateTime or string |
97
+ | `dateFromUnix([unixTime])` | Unix timestamp (seconds) -> `DateTimeOffset`. Accepts int, long, decimal, string |
98
+ | `dateToUtc([date])` or `dateToUtc([date], 'en-US')` | Convert to UTC. Optional culture for string parsing |
99
+ | `toLocalTime([date], 'America/Chicago')` | Convert UTC datetime to local time in IANA timezone. Returns `null` if date or timezone is invalid |
100
+
101
+ ### Business Date Math (in Lucene filter expressions)
102
+
103
+ The filter engine (`FilterBy`) supports business-aware date math units in Lucene date expressions:
104
+
105
+ | Unit | Aliases | Description |
106
+ |------|---------|-------------|
107
+ | `BHOUR` | `BHOURS` | Add/subtract business hours (respects weekly schedule + holidays) |
108
+ | `BDAY` | `BDAYS` | Add/subtract business days (skips non-working days) |
109
+
110
+ **Usage**: These units are used in **Lucene filter strings** (not NCalc expressions). They require an `IBusinessDateMathResolver` and are resolved via the organization's business calendar.
111
+
112
+ ```
113
+ dueDate: [NOW TO NOW+3BDAYS]
114
+ pickupDate: [* TO NOW-8BHOURS]
115
+ ```
116
+
117
+ ### Math Functions (NCalc built-in)
118
+
119
+ `Abs(x)`, `Ceiling(x)`, `Floor(x)`, `Round(x, decimals)`, `Min(x, y)`, `Max(x, y)`, `Pow(x, y)`, `Sqrt(x)`, `Truncate(x)`
120
+
121
+ Custom: `ceiling([value])` -- same as `Ceiling` but handles type conversion to double.
122
+
123
+ ### Domain Functions
124
+
125
+ | Function | Description |
126
+ |----------|-------------|
127
+ | `convertWeight([weight], 'Kg', 'Lb')` | Weight unit conversion. Returns `decimal` rounded to 5 places |
128
+ | `convertDimension([length], 'Cm', 'In')` | Dimension unit conversion. Returns `decimal` rounded to 3 places |
@@ -0,0 +1,159 @@
1
+ # Template Expressions & Value Directives
2
+
3
+ ## Contents
4
+ - Template expression syntax `{{ path }}` (in step inputs)
5
+ - Type converters (int, decimal, bool, fromJson, toJson, etc.)
6
+ - Value directives (expression, coalesce, foreach, switch, extends, $raw, $eval, encrypt/decrypt)
7
+ - Property path syntax (dot paths, array indexing, wildcards, filters, projections)
8
+
9
+ There are **two distinct syntaxes** for referencing variables, used in different contexts. This file covers **template expressions** used in step inputs. For NCalc conditions and functions, see [ref-expressions-ncalc.md](ref-expressions-ncalc.md).
10
+
11
+ ## Template Expressions: `{{ path }}` (in step inputs)
12
+
13
+ Used in step `inputs` values. Resolves variable paths from scoped variables.
14
+
15
+ ```yaml
16
+ inputs:
17
+ orderId: "{{ inputs.orderId }}" # Simple reference
18
+ url: "{{ chopinConfig.baseUrl }}/api/v1" # String interpolation
19
+ order: "{{ Data.GetOrder.order }}" # Raw object (single {{ }})
20
+ name: "Order {{ Data.GetOrder.order.orderNumber }}" # String interpolation (multiple)
21
+ ```
22
+
23
+ **Key behavior**: A single `{{ path }}` returns the **raw object** (preserving type). Multiple `{{ }}` in a string returns string interpolation (each resolved value is `.ToString()`).
24
+
25
+ ### Type Converters (prefix in {{ }})
26
+
27
+ ```yaml
28
+ organizationId: "{{ int organizationId }}"
29
+ amount: "{{ decimal totalAmount }}"
30
+ isActive: "{{ bool isActive }}"
31
+ flag: "{{ boolOrFalse someFlag }}" # null -> false
32
+ flagOn: "{{ boolOrTrue someFlag }}" # null -> true
33
+ notes: "{{ emptyIfNull notes }}" # null -> ""
34
+ notes: "{{ nullIfEmpty notes }}" # "" or whitespace -> null
35
+ config: "{{ fromJson configJsonString }}" # JSON string -> dict/array
36
+ payload: "{{ toJson someObject }}" # object -> JSON string
37
+ name: "{{ trim value }}"
38
+ search: "{{ luceneString query }}" # escape & quote for Lucene
39
+ ```
40
+
41
+ | Converter | Returns | Null handling |
42
+ |-----------|---------|---------------|
43
+ | `string` | `string` | null. Reads `Stream` to string if value is Stream |
44
+ | `int` | `int` | Throws on null |
45
+ | `decimal` | `decimal` | Throws on null |
46
+ | `bool` | `bool` | Throws on null |
47
+ | `boolOrFalse` | `bool` | `false` if null |
48
+ | `boolOrTrue` | `bool` | `true` if null |
49
+ | `datetime` | `DateTime` | Throws on null |
50
+ | `emptyIfNull` | same type | `""` if null, `0` for int?, `0m` for decimal? |
51
+ | `nullIfEmpty` | same type | `null` if empty/whitespace string or empty collection |
52
+ | `luceneString` | `string` | null |
53
+ | `transliterate` | `string` | null (Unicode -> ASCII via Unidecode) |
54
+ | `transliterateUa` | `string` | null (Ukrainian-specific rules) |
55
+ | `fromJson` | `dict` or `array` | null. Empty string -> empty dict |
56
+ | `toJson` | `string` | `""` if null |
57
+ | `trim` | `string` | null |
58
+ | `toLocalTime` | `DateTime` or `string` | null. Syntax: `{{ toLocalTime path 'TimezoneId' 'format?' }}` |
59
+
60
+ ### Value Directives (in YAML input mappings)
61
+
62
+ **`expression`** -- Evaluate NCalc expression as a value:
63
+ ```yaml
64
+ amount:
65
+ expression: "[price] * [quantity]"
66
+ ```
67
+
68
+ **`coalesce`** -- First non-null value from a list:
69
+ ```yaml
70
+ displayName:
71
+ coalesce:
72
+ - "{{ customer.name? }}"
73
+ - "{{ customer.email? }}"
74
+ - "Unknown"
75
+ ```
76
+
77
+ **`foreach`** (value context) -- Transform collections inline:
78
+ ```yaml
79
+ commodities:
80
+ foreach: "sourceCommodities"
81
+ item: "item" # default: "item"
82
+ conditions: "[item.isActive] = true" # optional NCalc filter per item
83
+ continueOnError: false # optional, skip errors
84
+ mapping: # dict -> List<dict>, string -> List<object>
85
+ name: "{{ item.name }}"
86
+ quantity: "{{ item.qty }}"
87
+ ```
88
+
89
+ **`switch`** (value context) -- Value-based switch (case-insensitive match):
90
+ ```yaml
91
+ perLb:
92
+ switch: "{{ contact.commissionTier }}"
93
+ cases:
94
+ "tier1": "{{ rate.customValues.commission_per_lb_tier1 }}"
95
+ "tier2": "{{ rate.customValues.commission_per_lb_tier2 }}"
96
+ default: "0"
97
+ ```
98
+
99
+ **`extends`** -- Extend/merge an existing object or array:
100
+ ```yaml
101
+ orderData:
102
+ extends: "{{ existingOrder }}" # base object or array
103
+ defaultIfNull: {} # fallback if extends is null
104
+ mapping: # dict: merge overrides. array: append items
105
+ status: "Updated"
106
+ notes: "{{ newNotes }}"
107
+ ```
108
+
109
+ **`resolve`** -- Entity ID lookup by querying a GraphQL collection:
110
+ ```yaml
111
+ customerId:
112
+ resolve:
113
+ entity: "Contact" # Entity type (auto-pluralized for query)
114
+ filter: "name:{{ customerName }}" # Lucene filter (template-parsed)
115
+ field: "contactId" # Field to return (default: <entity>Id)
116
+ ```
117
+ Results are batched and cached per unique `entity|filter|field` combination by `ResolvePreProcessor` before step execution. Cache misses return `null`. Useful inside `foreach` mappings where many items reference the same entity — only one query per unique filter value.
118
+
119
+ **`$raw`** -- Prevent template parsing (pass as-is):
120
+ ```yaml
121
+ template:
122
+ $raw: "This {{ won't }} be parsed"
123
+ ```
124
+
125
+ **`$eval`** -- Parse JSON string then evaluate as template:
126
+ ```yaml
127
+ dynamicConfig:
128
+ $eval: "{{ configJsonString }}"
129
+ ```
130
+
131
+ **`decrypt`** / **`encrypt`** -- AES-CBC encryption (optional key/IV, has defaults):
132
+ ```yaml
133
+ apiKey:
134
+ decrypt:
135
+ encryptedValue: "{{ encryptedApiKey }}"
136
+ key: "{{ encryptionKey }}" # optional Base64 AES key
137
+ initializationVector: "{{ iv }}" # optional Base64 IV
138
+ ```
139
+
140
+ ---
141
+
142
+ ## Property Path Syntax (in collection, mapping, variable paths)
143
+
144
+ Used in `collection:` (foreach), `mapping:` (outputs), and variable resolution.
145
+
146
+ | Pattern | Description | Example |
147
+ |---------|-------------|---------|
148
+ | `a.b.c` | Dot-separated nested path | `order.customer.name` |
149
+ | `prop?` | Optional access (null if missing) | `order.customer?.name?` |
150
+ | `list[0]` | Array index | `items[0]` |
151
+ | `list[^1]` | Index from end (last item) | `items[^1]` |
152
+ | `list[*]` | Flatten/wildcard (all items) | `containers[*].commodities` |
153
+ | `list[**]` | Recursive flatten (all depths) | `containerCommodities[**]` |
154
+ | `list[-1]` | Depth filter (leaves only) | `tree[**][-1]` |
155
+ | `list[condition]` | Filter by condition | `items[status=Active]` |
156
+ | `dict['key']` | Dictionary key access | `customValues['myField']` |
157
+ | `list[*].{f1 f2}` | Field selector (projection) | `items[*].{name description}` |
158
+ | `list[*].{alias:source}` | Field selector with alias | `items[*].{id:commodityId}` |
159
+ | `list[*].{alias:_.parent}` | Field selector referencing parent | `items[*].{parentId:_.orderId}` |
@@ -1,5 +1,12 @@
1
1
  # Flow Workflow YAML Reference
2
2
 
3
+ ## Contents
4
+ - Flow top-level structure (workflowType, entity, states, transitions, aggregations)
5
+ - Flow entity section (entity name, type, includes, query)
6
+ - Flow states section (initial, final, parent hierarchy, onEnter/onExit steps)
7
+ - Flow transitions section (manual, auto, event triggers; from/to states; conditions)
8
+ - Flow aggregations section (reusable collection expressions: all, any, sum, count)
9
+
3
10
  Flow workflows are declarative state machines for entity lifecycle management. Use `workflowType: Flow` in the workflow section.
4
11
 
5
12
  ## Top-Level Structure
@@ -86,7 +93,7 @@ states:
86
93
 
87
94
  ### State Rules
88
95
  - **name**: Required, must be unique across all states
89
- - **isInitial**: At most one state can be initial
96
+ - **isInitial**: At most one state can be initial. When an entity has null status, the engine resolves it to the initial state automatically.
90
97
  - **isFinal**: Final states cannot be transition sources
91
98
  - **parent**: References another state; parent cannot be initial or final; children inherit parent transitions
92
99
 
@@ -1,5 +1,14 @@
1
1
  # Other Tasks Reference
2
2
 
3
+ ## Contents
4
+ - User & Auth tasks (User CRUD, verification codes, OAuth2 authentication)
5
+ - Caching tasks (SetCache and GetCache for in-memory key-value storage)
6
+ - EDI & Structured File Parsing tasks (EDI/Parse for X12/EDIFACT, StructuredFile/Parse)
7
+ - Flow/Transition task (trigger state machine transitions programmatically)
8
+ - Note tasks (Create, Update, Delete, NoteThread/Rename, bulk Import/Export)
9
+ - AppModule tasks (Create, Update, Delete app modules)
10
+ - ActionEvent/Create task (trigger UI notifications or webhooks)
11
+
3
12
  ## User & Auth
4
13
 
5
14
  | Task | Description |