@cxtms/cx-schema 1.0.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 (133) hide show
  1. package/README.md +384 -0
  2. package/dist/cli.d.ts +6 -0
  3. package/dist/cli.d.ts.map +1 -0
  4. package/dist/cli.js +1523 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/index.d.ts +7 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +11 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/types.d.ts +111 -0
  11. package/dist/types.d.ts.map +1 -0
  12. package/dist/types.js +6 -0
  13. package/dist/types.js.map +1 -0
  14. package/dist/utils/schemaLoader.d.ts +17 -0
  15. package/dist/utils/schemaLoader.d.ts.map +1 -0
  16. package/dist/utils/schemaLoader.js +134 -0
  17. package/dist/utils/schemaLoader.js.map +1 -0
  18. package/dist/validator.d.ts +64 -0
  19. package/dist/validator.d.ts.map +1 -0
  20. package/dist/validator.js +380 -0
  21. package/dist/validator.js.map +1 -0
  22. package/dist/workflowValidator.d.ts +64 -0
  23. package/dist/workflowValidator.d.ts.map +1 -0
  24. package/dist/workflowValidator.js +410 -0
  25. package/dist/workflowValidator.js.map +1 -0
  26. package/package.json +50 -0
  27. package/schemas/actions/all.json +26 -0
  28. package/schemas/actions/confirm.json +21 -0
  29. package/schemas/actions/consoleLog.json +16 -0
  30. package/schemas/actions/dialog.json +25 -0
  31. package/schemas/actions/fileDownload.json +16 -0
  32. package/schemas/actions/forEach.json +31 -0
  33. package/schemas/actions/if.json +12 -0
  34. package/schemas/actions/mutation.json +25 -0
  35. package/schemas/actions/navigate.json +18 -0
  36. package/schemas/actions/navigateBack.json +22 -0
  37. package/schemas/actions/navigateBackOrClose.json +21 -0
  38. package/schemas/actions/notification.json +19 -0
  39. package/schemas/actions/openBarcodeScanner.json +104 -0
  40. package/schemas/actions/query.json +32 -0
  41. package/schemas/actions/refresh.json +13 -0
  42. package/schemas/actions/resetDirtyState.json +22 -0
  43. package/schemas/actions/setFields.json +21 -0
  44. package/schemas/actions/setStore.json +13 -0
  45. package/schemas/actions/validateForm.json +15 -0
  46. package/schemas/actions/workflow.json +24 -0
  47. package/schemas/components/README.md +147 -0
  48. package/schemas/components/appComponent.json +50 -0
  49. package/schemas/components/barcodeScanner.json +69 -0
  50. package/schemas/components/button.json +123 -0
  51. package/schemas/components/calendar.json +489 -0
  52. package/schemas/components/card.json +176 -0
  53. package/schemas/components/collection.json +54 -0
  54. package/schemas/components/dataGrid.json +119 -0
  55. package/schemas/components/datasource.json +151 -0
  56. package/schemas/components/dropdown.json +57 -0
  57. package/schemas/components/field-collection.json +618 -0
  58. package/schemas/components/field.json +265 -0
  59. package/schemas/components/form.json +234 -0
  60. package/schemas/components/index.json +68 -0
  61. package/schemas/components/layout.json +69 -0
  62. package/schemas/components/module.json +138 -0
  63. package/schemas/components/navDropdown.json +36 -0
  64. package/schemas/components/navbar.json +78 -0
  65. package/schemas/components/navbarItem.json +28 -0
  66. package/schemas/components/navbarLink.json +36 -0
  67. package/schemas/components/row.json +31 -0
  68. package/schemas/components/tab.json +34 -0
  69. package/schemas/components/tabs.json +35 -0
  70. package/schemas/components/timeline.json +172 -0
  71. package/schemas/components/timelineGrid.json +324 -0
  72. package/schemas/fields/README.md +66 -0
  73. package/schemas/fields/attachment.json +156 -0
  74. package/schemas/fields/autocomplete-googleplaces.json +130 -0
  75. package/schemas/fields/checkbox.json +82 -0
  76. package/schemas/fields/date.json +88 -0
  77. package/schemas/fields/datetime.json +75 -0
  78. package/schemas/fields/email.json +75 -0
  79. package/schemas/fields/index.json +53 -0
  80. package/schemas/fields/number.json +91 -0
  81. package/schemas/fields/password.json +70 -0
  82. package/schemas/fields/radio.json +94 -0
  83. package/schemas/fields/rangedatetime.json +56 -0
  84. package/schemas/fields/select-async.json +334 -0
  85. package/schemas/fields/select.json +115 -0
  86. package/schemas/fields/tel.json +79 -0
  87. package/schemas/fields/text.json +86 -0
  88. package/schemas/fields/textarea.json +95 -0
  89. package/schemas/fields/time.json +91 -0
  90. package/schemas/fields/url.json +74 -0
  91. package/schemas/schema.graphql +10492 -0
  92. package/schemas/schemas.json +598 -0
  93. package/schemas/workflows/activity.json +111 -0
  94. package/schemas/workflows/common/condition.json +48 -0
  95. package/schemas/workflows/common/expression.json +76 -0
  96. package/schemas/workflows/common/mapping.json +134 -0
  97. package/schemas/workflows/input.json +76 -0
  98. package/schemas/workflows/output.json +41 -0
  99. package/schemas/workflows/schedule.json +26 -0
  100. package/schemas/workflows/tasks/accounting-transaction.json +95 -0
  101. package/schemas/workflows/tasks/all.json +34 -0
  102. package/schemas/workflows/tasks/attachment.json +94 -0
  103. package/schemas/workflows/tasks/charge.json +90 -0
  104. package/schemas/workflows/tasks/commodity.json +89 -0
  105. package/schemas/workflows/tasks/contact.json +82 -0
  106. package/schemas/workflows/tasks/csv.json +79 -0
  107. package/schemas/workflows/tasks/document-render.json +105 -0
  108. package/schemas/workflows/tasks/document-send.json +84 -0
  109. package/schemas/workflows/tasks/email-send.json +110 -0
  110. package/schemas/workflows/tasks/error.json +72 -0
  111. package/schemas/workflows/tasks/export.json +90 -0
  112. package/schemas/workflows/tasks/foreach.json +69 -0
  113. package/schemas/workflows/tasks/generic.json +47 -0
  114. package/schemas/workflows/tasks/graphql.json +78 -0
  115. package/schemas/workflows/tasks/httpRequest.json +119 -0
  116. package/schemas/workflows/tasks/job.json +88 -0
  117. package/schemas/workflows/tasks/log.json +73 -0
  118. package/schemas/workflows/tasks/map.json +58 -0
  119. package/schemas/workflows/tasks/order.json +87 -0
  120. package/schemas/workflows/tasks/payment.json +85 -0
  121. package/schemas/workflows/tasks/setVariable.json +76 -0
  122. package/schemas/workflows/tasks/switch.json +75 -0
  123. package/schemas/workflows/tasks/template.json +73 -0
  124. package/schemas/workflows/tasks/validation.json +90 -0
  125. package/schemas/workflows/tasks/while.json +53 -0
  126. package/schemas/workflows/tasks/workflow-execute.json +82 -0
  127. package/schemas/workflows/trigger.json +86 -0
  128. package/schemas/workflows/variable.json +46 -0
  129. package/schemas/workflows/workflow.json +172 -0
  130. package/scripts/postinstall.js +161 -0
  131. package/scripts/setup-vscode.js +80 -0
  132. package/templates/module.yaml +83 -0
  133. package/templates/workflow.yaml +100 -0
package/README.md ADDED
@@ -0,0 +1,384 @@
1
+ # @cxtms/cx-schema
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@cxtms/cx-schema.svg)](https://www.npmjs.com/package/@cxtms/cx-schema)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@cxtms/cx-schema.svg)](https://www.npmjs.com/package/@cxtms/cx-schema)
5
+ [![Build Status](https://github.com/cargoxplorer/cx-schema/workflows/Publish%20to%20npm/badge.svg)](https://github.com/cargoxplorer/cx-schema/actions)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ Schema validation package for CargoXplorer YAML modules and workflows. This package provides comprehensive validation for YAML-based configurations used in the CargoXplorer Transportation Management System (TMS).
9
+
10
+ ## Features
11
+
12
+ - **Module & Workflow Validation**: Validate both UI modules and workflow definitions
13
+ - **CLI Tool**: Full-featured command-line interface with multiple commands
14
+ - **Project Scaffolding**: `init` command to bootstrap new projects
15
+ - **Template Generation**: `create` command to generate modules and workflows from templates
16
+ - **Report Generation**: Generate validation reports in HTML, Markdown, or JSON formats
17
+ - **Auto-Detection**: Automatically detects file type (module vs workflow)
18
+ - **TypeScript Support**: Full TypeScript types and declarations included
19
+ - **VS Code Integration**: Optional setup for YAML schema validation in VS Code
20
+ - **Detailed Error Reporting**: Clear error messages with paths and suggestions
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ npm install @cxtms/cx-schema
26
+ ```
27
+
28
+ ## Quick Start
29
+
30
+ ```bash
31
+ # Initialize a new project
32
+ npx cx-validate init
33
+
34
+ # Create a new module
35
+ npx cx-validate create module orders
36
+
37
+ # Create a new workflow
38
+ npx cx-validate create workflow invoice-processor
39
+
40
+ # Validate files
41
+ npx cx-validate modules/*.yaml workflows/*.yaml
42
+
43
+ # Generate validation report
44
+ npx cx-validate report modules/*.yaml --report report.html
45
+ ```
46
+
47
+ ## CLI Commands
48
+
49
+ ### validate (default)
50
+
51
+ Validate YAML file(s) against JSON Schema definitions.
52
+
53
+ ```bash
54
+ cx-validate [files...]
55
+ cx-validate validate [files...]
56
+
57
+ # Examples
58
+ cx-validate modules/orders-module.yaml
59
+ cx-validate modules/*.yaml workflows/*.yaml
60
+ cx-validate --verbose modules/orders-module.yaml
61
+ cx-validate --format json modules/orders-module.yaml
62
+ ```
63
+
64
+ ### init
65
+
66
+ Initialize a new CX project with configuration files.
67
+
68
+ ```bash
69
+ cx-validate init
70
+ ```
71
+
72
+ Creates:
73
+ - `app.yaml` - Project configuration
74
+ - `README.md` - Project documentation
75
+ - `AGENTS.md` - AI assistant instructions for validation
76
+ - `modules/` - Directory for module files
77
+ - `workflows/` - Directory for workflow files
78
+
79
+ ### create
80
+
81
+ Create a new module or workflow from template.
82
+
83
+ ```bash
84
+ cx-validate create <type> <name>
85
+
86
+ # Examples
87
+ cx-validate create module orders
88
+ cx-validate create workflow invoice-generator
89
+ ```
90
+
91
+ Generated files include:
92
+ - Unique UUID identifiers
93
+ - `fileName` property for GitHub repo tracking
94
+ - Sample structure with common patterns
95
+
96
+ ### report
97
+
98
+ Generate validation report for multiple files.
99
+
100
+ ```bash
101
+ cx-validate report [files...] --report <output-file>
102
+
103
+ # Examples
104
+ cx-validate report modules/*.yaml --report report.html
105
+ cx-validate report workflows/*.yaml --report report.md
106
+ cx-validate report modules/*.yaml workflows/*.yaml --report results.json
107
+ ```
108
+
109
+ Report formats (auto-detected from extension):
110
+ - **HTML** - Styled report with summary cards and detailed errors
111
+ - **Markdown** - Documentation-friendly tables and lists
112
+ - **JSON** - Machine-readable for CI/CD pipelines
113
+
114
+ ### schema
115
+
116
+ Display the JSON Schema definition for a component or task.
117
+
118
+ ```bash
119
+ cx-validate schema <name>
120
+
121
+ # Examples
122
+ cx-validate schema form
123
+ cx-validate schema dataGrid
124
+ cx-validate schema workflow
125
+ cx-validate schema foreach
126
+ ```
127
+
128
+ ### example
129
+
130
+ Show example YAML for a component or task.
131
+
132
+ ```bash
133
+ cx-validate example <name>
134
+
135
+ # Examples
136
+ cx-validate example form
137
+ cx-validate example workflow
138
+ ```
139
+
140
+ ### list
141
+
142
+ List all available schemas for validation.
143
+
144
+ ```bash
145
+ cx-validate list
146
+ cx-validate list --type module
147
+ cx-validate list --type workflow
148
+ ```
149
+
150
+ ## CLI Options
151
+
152
+ | Option | Short | Description |
153
+ |--------|-------|-------------|
154
+ | `--help` | `-h` | Show help message |
155
+ | `--version` | `-v` | Show version number |
156
+ | `--type <type>` | `-t` | Validation type: `module`, `workflow`, or `auto` (default: `auto`) |
157
+ | `--format <format>` | `-f` | Output format: `pretty`, `json`, or `compact` (default: `pretty`) |
158
+ | `--schemas <path>` | `-s` | Path to custom schemas directory |
159
+ | `--verbose` | | Show detailed output with schema paths |
160
+ | `--quiet` | `-q` | Only show errors, suppress other output |
161
+ | `--report <file>` | `-r` | Generate report to file (html, md, or json) |
162
+ | `--report-format <fmt>` | | Report format: `html`, `markdown`, or `json` |
163
+
164
+ ## Output Formats
165
+
166
+ ### Pretty (default)
167
+
168
+ Human-readable output with colored formatting and detailed error info.
169
+
170
+ ```
171
+ ╔═══════════════════════════════════════════════════════════════════╗
172
+ ║ CX SCHEMA VALIDATION REPORT ║
173
+ ╚═══════════════════════════════════════════════════════════════════╝
174
+
175
+ File: modules/my-module.yaml
176
+ Type: module
177
+ Status: ✓ PASSED
178
+ Errors: 0
179
+ Warnings:0
180
+ ```
181
+
182
+ ### Compact
183
+
184
+ Minimal output for batch processing.
185
+
186
+ ```
187
+ PASS modules/orders-module.yaml
188
+ PASS modules/contacts-module.yaml
189
+ FAIL modules/broken-module.yaml (3 errors)
190
+ ```
191
+
192
+ ### JSON
193
+
194
+ JSON output for programmatic processing.
195
+
196
+ ```json
197
+ {
198
+ "isValid": true,
199
+ "errors": [],
200
+ "warnings": [],
201
+ "summary": {
202
+ "file": "modules/my-module.yaml",
203
+ "status": "PASSED",
204
+ "errorCount": 0
205
+ }
206
+ }
207
+ ```
208
+
209
+ ## Programmatic API
210
+
211
+ ```typescript
212
+ import { ModuleValidator, WorkflowValidator } from '@cxtms/cx-schema';
213
+
214
+ // Validate a module
215
+ const moduleValidator = new ModuleValidator({
216
+ schemasPath: './.cx-schema'
217
+ });
218
+ const moduleResult = await moduleValidator.validateModule('modules/orders.yaml');
219
+
220
+ // Validate a workflow
221
+ const workflowValidator = new WorkflowValidator({
222
+ schemasPath: './.cx-schema/workflows'
223
+ });
224
+ const workflowResult = await workflowValidator.validateWorkflow('workflows/process.yaml');
225
+
226
+ if (moduleResult.isValid) {
227
+ console.log('✓ Module is valid');
228
+ } else {
229
+ moduleResult.errors.forEach(error => {
230
+ console.error(`${error.type}: ${error.message} at ${error.path}`);
231
+ });
232
+ }
233
+ ```
234
+
235
+ ## Templates
236
+
237
+ Templates are stored in the `templates/` directory and use placeholder syntax:
238
+
239
+ | Placeholder | Description |
240
+ |-------------|-------------|
241
+ | `{{name}}` | Sanitized name (lowercase, dashes) |
242
+ | `{{displayName}}` | Title case display name |
243
+ | `{{uuid}}` | Generated UUID |
244
+ | `{{fileName}}` | Relative path to the file |
245
+
246
+ ### Module Template
247
+
248
+ Generated modules include:
249
+ - Module metadata with `appModuleId` and `fileName`
250
+ - Sample entities and permissions
251
+ - Routes for list and detail views
252
+ - Layout components with dataGrid and form
253
+
254
+ ### Workflow Template
255
+
256
+ Generated workflows include:
257
+ - Workflow metadata with `workflowId` and `fileName`
258
+ - Sample inputs, outputs, and variables
259
+ - Activity with common task examples (Log, Query/GraphQL, switch)
260
+ - Manual trigger
261
+
262
+ ## Available Schemas
263
+
264
+ ### Module Schemas
265
+
266
+ **Components:** layout, form, dataGrid, tabs, tab, field, button, collection, dropdown, datasource, calendar, card, navbar, timeline
267
+
268
+ **Fields:** text, textarea, number, select, select-async, date, datetime, time, checkbox, radio, attachment, autocomplete-googleplaces
269
+
270
+ **Actions:** navigate, navigateBack, mutation, query, notification, dialog, workflow, setFields, setStore, validateForm
271
+
272
+ ### Workflow Schemas
273
+
274
+ **Core:** workflow, activity, input, output, variable, trigger, schedule
275
+
276
+ **Control Flow:** foreach, switch, while, validation
277
+
278
+ **Utilities:** map, setVariable, httpRequest, log, error, csv, export, template
279
+
280
+ **Entities:** order, contact, commodity, job, attachment, charge, payment
281
+
282
+ **Communication:** email-send, document-render, document-send
283
+
284
+ **Query:** graphql (Query/GraphQL, Query/GraphQL@1)
285
+
286
+ ## Exit Codes
287
+
288
+ | Code | Description |
289
+ |------|-------------|
290
+ | `0` | Validation passed (no errors) |
291
+ | `1` | Validation failed (errors found) |
292
+ | `2` | CLI error (invalid arguments, file not found, etc.) |
293
+
294
+ ## CI/CD Integration
295
+
296
+ ### GitHub Actions
297
+
298
+ ```yaml
299
+ - name: Validate YAML files
300
+ run: |
301
+ npx cx-validate --format compact modules/*.yaml workflows/*.yaml
302
+
303
+ - name: Generate validation report
304
+ run: |
305
+ npx cx-validate report modules/*.yaml workflows/*.yaml --report validation-report.html
306
+
307
+ - name: Upload report
308
+ uses: actions/upload-artifact@v3
309
+ with:
310
+ name: validation-report
311
+ path: validation-report.html
312
+ ```
313
+
314
+ ### GitLab CI
315
+
316
+ ```yaml
317
+ validate:
318
+ script:
319
+ - npx cx-validate --format json modules/*.yaml > validation-results.json
320
+ artifacts:
321
+ paths:
322
+ - validation-results.json
323
+ ```
324
+
325
+ ### Pre-commit Hook
326
+
327
+ ```bash
328
+ #!/bin/bash
329
+ # .git/hooks/pre-commit
330
+
331
+ staged_files=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(yaml|yml)$')
332
+
333
+ if [ -n "$staged_files" ]; then
334
+ npx cx-validate --format compact $staged_files
335
+ if [ $? -ne 0 ]; then
336
+ echo "Validation failed. Please fix errors before committing."
337
+ exit 1
338
+ fi
339
+ fi
340
+ ```
341
+
342
+ ## VS Code Integration
343
+
344
+ To enable YAML schema validation and autocomplete in VS Code:
345
+
346
+ ```bash
347
+ node node_modules/@cxtms/cx-schema/scripts/setup-vscode.js
348
+ ```
349
+
350
+ This creates/updates `.vscode/settings.json` with schema associations.
351
+
352
+ ## Environment Variables
353
+
354
+ | Variable | Description |
355
+ |----------|-------------|
356
+ | `CX_SCHEMA_PATH` | Default path to schemas directory |
357
+ | `NO_COLOR` | Disable colored output |
358
+
359
+ ## Development
360
+
361
+ ### Building from Source
362
+
363
+ ```bash
364
+ git clone <repository>
365
+ cd cx-schema
366
+ npm install
367
+ npm run build
368
+ ```
369
+
370
+ ### Testing Locally
371
+
372
+ ```bash
373
+ npm pack
374
+ # In another project:
375
+ npm install /path/to/cxtms-cx-schema-1.0.0.tgz
376
+ ```
377
+
378
+ ## License
379
+
380
+ MIT
381
+
382
+ ## Support
383
+
384
+ For issues and questions, please visit the [GitHub repository](https://github.com/cargoxplorer/cx-schema/issues).
package/dist/cli.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * CX Schema Validator CLI - Unified validation for YAML modules and workflows
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA;;GAEG"}