@rglabs/butterfly 2.0.1

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 (117) hide show
  1. package/CLAUDE.md +201 -0
  2. package/README.md +371 -0
  3. package/dist/commands/add.d.ts +23 -0
  4. package/dist/commands/add.js +303 -0
  5. package/dist/commands/code.d.ts +11 -0
  6. package/dist/commands/code.js +72 -0
  7. package/dist/commands/create-object.d.ts +6 -0
  8. package/dist/commands/create-object.js +293 -0
  9. package/dist/commands/create-report.d.ts +6 -0
  10. package/dist/commands/create-report.js +154 -0
  11. package/dist/commands/diff.d.ts +4 -0
  12. package/dist/commands/diff.js +238 -0
  13. package/dist/commands/download.d.ts +4 -0
  14. package/dist/commands/download.js +374 -0
  15. package/dist/commands/layout.d.ts +12 -0
  16. package/dist/commands/layout.js +83 -0
  17. package/dist/commands/record.d.ts +21 -0
  18. package/dist/commands/record.js +483 -0
  19. package/dist/commands/run-poc.d.ts +3 -0
  20. package/dist/commands/run-poc.js +18 -0
  21. package/dist/commands/setup.d.ts +3 -0
  22. package/dist/commands/setup.js +66 -0
  23. package/dist/commands/start-poc.d.ts +3 -0
  24. package/dist/commands/start-poc.js +55 -0
  25. package/dist/commands/sync-docs.d.ts +3 -0
  26. package/dist/commands/sync-docs.js +27 -0
  27. package/dist/commands/translate.d.ts +13 -0
  28. package/dist/commands/translate.js +401 -0
  29. package/dist/commands/upload.d.ts +3 -0
  30. package/dist/commands/upload.js +150 -0
  31. package/dist/commands/workflow-info.d.ts +13 -0
  32. package/dist/commands/workflow-info.js +161 -0
  33. package/dist/components/ConflictResolver.d.ts +12 -0
  34. package/dist/components/ConflictResolver.js +77 -0
  35. package/dist/components/DiffView.d.ts +11 -0
  36. package/dist/components/DiffView.js +101 -0
  37. package/dist/components/DownloadProgress.d.ts +11 -0
  38. package/dist/components/DownloadProgress.js +29 -0
  39. package/dist/components/RecordPreview.d.ts +11 -0
  40. package/dist/components/RecordPreview.js +91 -0
  41. package/dist/components/SetupForm.d.ts +8 -0
  42. package/dist/components/SetupForm.js +56 -0
  43. package/dist/components/UploadProgress.d.ts +13 -0
  44. package/dist/components/UploadProgress.js +42 -0
  45. package/dist/diff/adapters/index.d.ts +8 -0
  46. package/dist/diff/adapters/index.js +18 -0
  47. package/dist/diff/adapters/objectsAdapter.d.ts +13 -0
  48. package/dist/diff/adapters/objectsAdapter.js +177 -0
  49. package/dist/diff/adapters/reportsAdapter.d.ts +14 -0
  50. package/dist/diff/adapters/reportsAdapter.js +212 -0
  51. package/dist/diff/adapters/types.d.ts +19 -0
  52. package/dist/diff/adapters/types.js +2 -0
  53. package/dist/diff/engine.d.ts +19 -0
  54. package/dist/diff/engine.js +57 -0
  55. package/dist/diff/types.d.ts +34 -0
  56. package/dist/diff/types.js +110 -0
  57. package/dist/index.d.ts +3 -0
  58. package/dist/index.js +117 -0
  59. package/dist/types/index.d.ts +18 -0
  60. package/dist/types/index.js +2 -0
  61. package/dist/utils/api.d.ts +85 -0
  62. package/dist/utils/api.js +1031 -0
  63. package/dist/utils/auth.d.ts +4 -0
  64. package/dist/utils/auth.js +22 -0
  65. package/dist/utils/bfySplitter.d.ts +12 -0
  66. package/dist/utils/bfySplitter.js +151 -0
  67. package/dist/utils/docs.d.ts +16 -0
  68. package/dist/utils/docs.js +186 -0
  69. package/dist/utils/errorLogger.d.ts +6 -0
  70. package/dist/utils/errorLogger.js +29 -0
  71. package/dist/utils/files.d.ts +14 -0
  72. package/dist/utils/files.js +772 -0
  73. package/dist/utils/lockManager.d.ts +15 -0
  74. package/dist/utils/lockManager.js +126 -0
  75. package/dist/utils/resourceHandlers.d.ts +50 -0
  76. package/dist/utils/resourceHandlers.js +684 -0
  77. package/dist/utils/resourceMapping.d.ts +32 -0
  78. package/dist/utils/resourceMapping.js +210 -0
  79. package/dist/utils/singleResourceDownload.d.ts +14 -0
  80. package/dist/utils/singleResourceDownload.js +261 -0
  81. package/dist/utils/summaryGenerator.d.ts +2 -0
  82. package/dist/utils/summaryGenerator.js +183 -0
  83. package/dist/utils/uploadHandler.d.ts +31 -0
  84. package/dist/utils/uploadHandler.js +263 -0
  85. package/docs/AI_API.md +93 -0
  86. package/docs/CLAUDE.md +216 -0
  87. package/docs/PROJECT_SPECIFIC.md +1 -0
  88. package/docs/RECORD_COMMAND.md +262 -0
  89. package/docs/WORKFLOW_API.md +480 -0
  90. package/docs/bfy-splitting.md +126 -0
  91. package/docs/cli-commands.md +333 -0
  92. package/docs/examples/README.md +95 -0
  93. package/docs/examples/order-system.md +147 -0
  94. package/docs/examples/product-catalog.md +195 -0
  95. package/docs/examples/reports.md +187 -0
  96. package/docs/excel-export.md +216 -0
  97. package/docs/field-types/README.md +29 -0
  98. package/docs/field-types/calculated.md +147 -0
  99. package/docs/field-types/code-mappings.md +84 -0
  100. package/docs/field-types/custom.md +340 -0
  101. package/docs/object-specs/README.md +136 -0
  102. package/docs/object-specs/code-parameters.md +151 -0
  103. package/docs/object-specs/creating.md +203 -0
  104. package/docs/object-specs/js-code-examples.md +208 -0
  105. package/docs/object-specs/js-field-updates.md +168 -0
  106. package/docs/objects/README.md +89 -0
  107. package/docs/objects/creating.md +127 -0
  108. package/docs/page-layout.md +361 -0
  109. package/docs/permissions.md +260 -0
  110. package/docs/reports.md +197 -0
  111. package/docs/state-machines.md +544 -0
  112. package/docs/tasks/create-object.md +81 -0
  113. package/docs/translations.md +346 -0
  114. package/docs/twig-helpers.md +283 -0
  115. package/docs/webservices.md +159 -0
  116. package/docs/workspaces.md +176 -0
  117. package/package.json +59 -0
package/docs/CLAUDE.md ADDED
@@ -0,0 +1,216 @@
1
+ # CLAUDE.md
2
+
3
+ ## Translations in Twig
4
+
5
+ ```twig
6
+ {{ "text"|trans }}
7
+ {{ "Hello %name%"|trans({'name': value}) }}
8
+ ```
9
+
10
+ ## Resource Information Lookup
11
+
12
+ 1. **First, search in `butterfly-resources/` folder** - local resources are the source of truth
13
+ 2. **If not found locally**, use `butterfly-cli record get <table> --column <col> --value <val>`
14
+ 3. **For table/column info**, check `butterfly-resources/docs/` folder
15
+
16
+ ## Record Command Quick Reference
17
+
18
+ | Operation | When to Use | Command |
19
+ |-----------|-------------|---------|
20
+ | **GET** | Not in `butterfly-resources/` | `butterfly-cli record get <table> --id <id>` |
21
+ | **ADD** | **Always** (never create files manually) | `butterfly-cli record add <table> --data '{...}'` |
22
+ | **EDIT** | Not in `butterfly-resources/` | `butterfly-cli record edit <table> --id <id> --data '{...}'` |
23
+ | **DELETE** | Always (ask user first!) | `butterfly-cli record delete <table> --id <id>` |
24
+
25
+ > **For EDIT operations only:** If the resource exists in `butterfly-resources/`, edit local files and use `butterfly-cli upload <path>` instead. **ADD operations must ALWAYS use `butterfly-cli record add`** - never create files manually in `butterfly-resources/`.
26
+
27
+ See [docs/RECORD_COMMAND.md](docs/RECORD_COMMAND.md) for full documentation.
28
+
29
+ ## System Table Names
30
+
31
+ | Correct Name | Wrong Alternatives | Description |
32
+ |--------------|-------------------|-------------|
33
+ | `objects` | `cms_objects` | Object definitions |
34
+ | `object_specs` | `cms_object_specs` | Field specifications |
35
+ | `object_tabs` | `cms_object_tabs` | Page tabs |
36
+ | `bfy_sm_actions` | `bfy_state_machine_actions` | State machine actions |
37
+ | `bfy_sm_transition_actions` | `bfy_state_machine_transition_actions` | Transition-action mappings |
38
+ | `bfy_sm_action_specs` | `bfy_state_machine_action_specs` | Action form fields |
39
+ | `cms_reports` | `reports` | Report definitions |
40
+ | `cms_report_queries` | `report_queries` | Report queries |
41
+ | `cms_report_specs` | `report_specs` | Report field specs |
42
+ | `webservices` | - | Webservice endpoints |
43
+
44
+ ## Directory Structure
45
+
46
+ ```
47
+ butterfly-resources/
48
+ ├── objects/[butterfly|app]/[table]/ # Objects and specs
49
+ ├── bfy_state_machines/[name]/ # State machines
50
+ ├── bfy_workflows/[name]/v[n]/ # Workflows
51
+ ├── reports/[alias]/ # Reports
52
+ ├── webservices/[custom_seo]/ # Webservices
53
+ ├── pages/ # Pages
54
+ ├── bfy_cronjobs/ # Cron jobs
55
+ └── docs/ # Database docs
56
+ ```
57
+
58
+ ## Field Type Code Mappings (Quick Reference)
59
+
60
+ | Field Type | Parameter | Export File |
61
+ |------------|-----------|-------------|
62
+ | `calculated` | `val_1` | `code.bfy` |
63
+ | `custom` | `val_1`, `val_2` | `template_code.bfy`, `processing_code.bfy` |
64
+ | `filter` | `val_3` | `filter_code.bfy` |
65
+ | `nested`/`nested_single` | `val_1` | `configuration.yaml` |
66
+
67
+ See [docs/field-types/code-mappings.md](docs/field-types/code-mappings.md) for full details.
68
+
69
+ ## CLI Commands (Quick Reference)
70
+
71
+ | Command | Description |
72
+ |---------|-------------|
73
+ | `butterfly-cli setup` | Configure authentication |
74
+ | `butterfly-cli download [-t type]` | Download resources |
75
+ | `butterfly-cli upload <path>` | Upload files |
76
+ | `butterfly-cli add -t workflow` | Create workflow |
77
+ | `butterfly-cli code -c "..."` | Test Twig code |
78
+ | `butterfly-cli layout -f file.json` | Update page layout |
79
+ | `butterfly-cli translate <operation>` | Manage translations |
80
+
81
+ See [docs/cli-commands.md](docs/cli-commands.md) for full documentation.
82
+
83
+ ## Translation Commands (Quick Reference)
84
+
85
+ | Command | Description |
86
+ |---------|-------------|
87
+ | `butterfly-cli translate languages` | List languages with stats |
88
+ | `butterfly-cli translate get-untranslated --lang tr` | Get untranslated texts |
89
+ | `butterfly-cli translate add --lang tr --source "text" --text "çeviri"` | Add/update single translation |
90
+ | `butterfly-cli translate bulk --lang tr --file translations.json` | Bulk import translations |
91
+
92
+ **Bulk CSV format (tab-delimited):**
93
+ ```
94
+ source text
95
+ Welcome Hoş geldiniz
96
+ Save Kaydet
97
+ ```
98
+
99
+ See [docs/translations.md](docs/translations.md) for full documentation.
100
+
101
+ ## Query Helpers (Quick Reference)
102
+
103
+ ```twig
104
+ {% set records = db().table('users').where('status', 'active').get() %}
105
+ {% set user = db().table('users').where('id', 5).first() %}
106
+ {% set ids = db().table('users').column('id') %}
107
+ {% set map = db().table('users').keyToValue('id', 'name') %}
108
+ ```
109
+
110
+ See [docs/twig-helpers.md](docs/twig-helpers.md) for full documentation.
111
+
112
+ ## Settings (Quick Reference)
113
+
114
+ ```twig
115
+ {# Get single setting value #}
116
+ {% set value = setting('group_alias', 'setting_alias') %}
117
+
118
+ {# Get all settings in a group #}
119
+ {% set all = setting('group_alias') %}
120
+ {{ all.setting_alias.value }}
121
+ ```
122
+
123
+ **Tables:** `cms_setting_groups` (groups by alias) → `cms_settings` (individual settings)
124
+
125
+ See [docs/twig-helpers.md](docs/twig-helpers.md#settings) for full documentation.
126
+
127
+ ## JavaScript Field Updates (Quick Reference)
128
+
129
+ | Field Types | Method |
130
+ |-------------|--------|
131
+ | `calculated`, `custom`, `date` | `bfyRefresh_COLUMN_NAME(value)` |
132
+ | All others | `$('[name="COLUMN"]').val(value).trigger('change')` |
133
+
134
+ See [docs/object-specs/js-field-updates.md](docs/object-specs/js-field-updates.md) for full documentation.
135
+
136
+ ## Admin Page URL Format
137
+
138
+ ```
139
+ /admin/SINGULAR_TABLE_NAME/list
140
+ /admin/SINGULAR_TABLE_NAME/add
141
+ /admin/SINGULAR_TABLE_NAME/edit/ID
142
+ ```
143
+
144
+ For non-default database: `/admin/DATABASE_ALIAS/SINGULAR_TABLE_NAME/...`
145
+
146
+ ## Object Menu Placement
147
+
148
+ Format: `MainMenu>SubMenu>MenuItemName` or with icons: `MainMenu::icon>SubMenu::icon>Item::icon`
149
+
150
+ ## Object Default Permissions
151
+
152
+ Set `usergroup_id` on an object to define its default (maximum) permissions system-wide:
153
+
154
+ ```bash
155
+ butterfly-cli record edit objects --id <object_id> --data '{"usergroup_id": <usergroup_id>}'
156
+ ```
157
+
158
+ This assigns a user group as the permission template for the object. See [docs/permissions.md](docs/permissions.md) for full documentation.
159
+
160
+ ## Workspaces (bfy_workspaces)
161
+
162
+ | `is_workspace_specific` | Scope | `bfy_workspace_id` Location |
163
+ |-------------------------|-------|----------------------------|
164
+ | `0` (default) | Object-level | `objects` table |
165
+ | `1` | Record-level | Data table column |
166
+
167
+ ```bash
168
+ # Assign object to workspace (object-level)
169
+ butterfly-cli record edit objects --id <object_id> --data '{"bfy_workspace_id": <workspace_id>}'
170
+
171
+ # Assign record to workspace (record-level)
172
+ butterfly-cli record add <table_name> --data '{"bfy_workspace_id": <workspace_id>, ...}'
173
+ ```
174
+
175
+ See [docs/workspaces.md](docs/workspaces.md) for full documentation.
176
+
177
+ ## Project-Specific Instructions
178
+
179
+ Always check if `docs/PROJECT_SPECIFIC.md` exists and prioritize those instructions.
180
+
181
+ ## See Also
182
+
183
+ **Core Documentation:**
184
+ - [docs/cli-commands.md](docs/cli-commands.md) - Full CLI reference
185
+ - [docs/RECORD_COMMAND.md](docs/RECORD_COMMAND.md) - Record command usage
186
+ - [docs/twig-helpers.md](docs/twig-helpers.md) - Query helpers and CRUD
187
+ - [docs/reports.md](docs/reports.md) - Report creation guide
188
+ - [docs/webservices.md](docs/webservices.md) - Webservice/API creation
189
+
190
+ **Field Types & Specs:**
191
+ - [docs/field-types/](docs/field-types/) - Field type documentation
192
+ - [docs/field-types/code-mappings.md](docs/field-types/code-mappings.md) - Code export mappings
193
+ - [docs/object-specs/js-field-updates.md](docs/object-specs/js-field-updates.md) - JavaScript updates
194
+ - [docs/object-specs/js-code-examples.md](docs/object-specs/js-code-examples.md) - JS code examples
195
+
196
+ **Other Guides:**
197
+ - [docs/state-machines.md](docs/state-machines.md) - State machine configuration
198
+ - [docs/page-layout.md](docs/page-layout.md) - Page layout organization
199
+ - [docs/permissions.md](docs/permissions.md) - Object permissions and user groups
200
+ - [docs/workspaces.md](docs/workspaces.md) - Workspace scoping for objects and records
201
+ - [docs/excel-export.md](docs/excel-export.md) - Excel export functionality
202
+ - [docs/bfy-splitting.md](docs/bfy-splitting.md) - BFY file splitting for large files
203
+ - [docs/translations.md](docs/translations.md) - Translations and i18n
204
+ - [docs/WORKFLOW_API.md](docs/WORKFLOW_API.md) - Workflow node types
205
+
206
+ **Slash Commands:**
207
+
208
+ | Command | When to Use |
209
+ |---------|-------------|
210
+ | `/docs-cli` | When you need help with `butterfly-cli` commands (download, upload, setup, add, record, code, layout) |
211
+ | `/docs-field-types` | When creating/editing object specs and need to know field type parameters (`val_1`, `val_2`, etc.) |
212
+ | `/docs-twig` | When writing Twig code for reports, calculated fields, or processing code (`db()`, `crud()`, helpers) |
213
+ | `/docs-state-machine` | When creating or modifying state machines, transitions, actions, or validation code |
214
+ | `/docs-webservice` | When creating API endpoints or webservices using reports with `custom_seo` |
215
+
216
+ > **AI INSTRUCTION:** Always use the relevant slash command before working on any task related to that topic. This ensures accurate implementation without guessing syntax or parameters.
@@ -0,0 +1 @@
1
+ ## In this file, there should be project specific information ##
@@ -0,0 +1,262 @@
1
+ # Record Command (Experimental)
2
+
3
+ > **Note:** This command is experimental. Only use when explicitly requested by the user.
4
+
5
+ ## Overview
6
+
7
+ ```bash
8
+ butterfly-cli record <operation> <table> [options]
9
+ ```
10
+
11
+ Perform CRUD operations (get/add/edit/delete) on any Butterfly table with preview and approval.
12
+
13
+ ## Operations
14
+
15
+ | Operation | Description | Required Options |
16
+ |-----------|-------------|------------------|
17
+ | `get` | Retrieve records | `--id` or `--column`/`--value` |
18
+ | `add` | Create new record | `--data` or `--file` |
19
+ | `edit` | Update record | `--id` + `--data` or `--file` |
20
+ | `delete` | Delete record | `--id` |
21
+
22
+ ## Options
23
+
24
+ | Option | Description |
25
+ |--------|-------------|
26
+ | `--id <id>` | Record ID (required for edit/delete, optional for get) |
27
+ | `--column <column>` | Filter column(s) for get (comma-separated for OR search) |
28
+ | `--value <value>` | Filter value (use `*` for wildcard, e.g., `test*` for LIKE) |
29
+ | `--columns <columns>` | Select specific columns to return (comma-separated) |
30
+ | `--data <json>` | JSON data for add/edit operations |
31
+ | `--file <path>` | Path to JSON file with data |
32
+ | `--db-alias <alias>` | Database alias (default: "default") |
33
+ | `--preview` | Show preview before executing (default: true) |
34
+ | `--no-preview` | Skip preview and execute directly |
35
+ | `-y, --yes` | Auto-confirm without prompting |
36
+ | `--output <path>` | For get: save record(s) to file |
37
+
38
+ ## Resource Tables
39
+
40
+ | Resource | Table Name |
41
+ |----------|------------|
42
+ | Objects | `objects` |
43
+ | Object Specs | `object_specs` |
44
+ | Reports | `cms_reports` |
45
+ | Report Queries | `cms_report_queries` |
46
+ | Report Specs | `cms_report_specs` |
47
+ | Workflows | `bfy_workflows` |
48
+ | Workflow Versions | `bfy_workflow_versions` |
49
+ | Workflow Nodes | `bfy_workflow_nodes` |
50
+ | State Machines | `bfy_state_machines` |
51
+ | Pages | `pages` |
52
+ | Cron Jobs | `bfy_cronjobs` |
53
+ | Email Templates | `cms_email_templates` |
54
+
55
+ ## Examples
56
+
57
+ ### Get Records
58
+
59
+ ```bash
60
+ # Get a single record by ID
61
+ butterfly-cli record get users --id 5
62
+
63
+ # Get all records from a table
64
+ butterfly-cli record get bfy_cronjobs
65
+
66
+ # Filter by column=value
67
+ butterfly-cli record get users --column status --value "1"
68
+
69
+ # OR search across multiple columns
70
+ butterfly-cli record get users --column "name,email,title" --value "john"
71
+
72
+ # Wildcard search (LIKE)
73
+ butterfly-cli record get users --column name --value "john*"
74
+ butterfly-cli record get users --column email --value "*@gmail.com"
75
+
76
+ # Select specific columns only
77
+ butterfly-cli record get users --columns "id,name,email"
78
+
79
+ # Save results to file
80
+ butterfly-cli record get users --column role --value "admin" --output ./admins.json
81
+ ```
82
+
83
+ ### Add Records
84
+
85
+ ```bash
86
+ # Add a new record
87
+ butterfly-cli record add bfy_cronjobs --data '{"name":"My Job","code":"// code"}'
88
+
89
+ # Add from JSON file
90
+ butterfly-cli record add pages --file ./new-page.json
91
+
92
+ # Create an object
93
+ butterfly-cli record add objects --data '{"name":"Products","table_name":"products"}'
94
+
95
+ # Add a string field
96
+ butterfly-cli record add object_specs --data '{"object_id":128,"name":"Title","column_name":"title","type":"string"}'
97
+
98
+ # Add a dropdown field
99
+ butterfly-cli record add object_specs --data '{"object_id":128,"name":"Status","column_name":"status","type":"from_list","val_1":"active,inactive"}'
100
+ ```
101
+
102
+ ### Edit Records
103
+
104
+ ```bash
105
+ # Edit a record (shows preview with diff)
106
+ butterfly-cli record edit bfy_cronjobs --id 5 --data '{"name":"Updated Name"}'
107
+
108
+ # Skip confirmation with -y
109
+ butterfly-cli record edit pages --id 1 --data '{"title":"New Title"}' -y
110
+ ```
111
+
112
+ ### Delete Records
113
+
114
+ ```bash
115
+ # Delete a record (shows preview)
116
+ butterfly-cli record delete bfy_cronjobs --id 5
117
+ ```
118
+
119
+ ### Reports
120
+
121
+ > **IMPORTANT:** The `query` field in `cms_reports` is **deprecated**. Always use `cms_report_queries` for all Twig query code.
122
+
123
+ ```bash
124
+ # Create a report (without query - query field is deprecated)
125
+ butterfly-cli record add cms_reports --data '{
126
+ "name": "Sales Summary",
127
+ "alias": "sales_summary"
128
+ }'
129
+ # Response: SUCCESS (ID: 50)
130
+
131
+ # Create a webservice report with custom_seo
132
+ # URL will be: {BASE_URL}/{custom_seo} (no additional path segments)
133
+ butterfly-cli record add cms_reports --data '{
134
+ "name": "User API",
135
+ "alias": "user_api",
136
+ "custom_seo": "api/users/list"
137
+ }'
138
+ # Response: SUCCESS (ID: 51)
139
+ # Webservice URL: https://example.com/api/users/list
140
+
141
+ # Add the main report query (use cms_report_queries, NOT cms_reports.query)
142
+ butterfly-cli record add cms_report_queries --data '{
143
+ "cms_report_id": 50,
144
+ "name": "main",
145
+ "system_name": "main",
146
+ "query": "{% set records = db().table(\"orders\").where(\"created_at\", \">=\", getParameter(\"date_from\")).get() %}"
147
+ }'
148
+
149
+ # Add additional report queries with column_size for layout
150
+ # column_size options: 1 (full), 1/2, 1/3, 2/3, 1/4, 3/4
151
+ butterfly-cli record add cms_report_queries --data '{
152
+ "cms_report_id": 50,
153
+ "name": "totals",
154
+ "system_name": "totals",
155
+ "column_size": "1/3",
156
+ "query": "{% set records = db().table(\"orders\").selectRaw(\"COUNT(*) as count, SUM(total) as revenue\").get() %}"
157
+ }'
158
+
159
+ # Add a report query with JS processing (2/3 width)
160
+ butterfly-cli record add cms_report_queries --data '{
161
+ "cms_report_id": 50,
162
+ "name": "monthly",
163
+ "system_name": "monthly",
164
+ "column_size": "2/3",
165
+ "query": "{% set records = db().table(\"orders\").selectRaw(\"DATE_FORMAT(created_at, \\\"%Y-%m\\\") as month, SUM(total) as revenue\").groupBy(\"month\").get() %}",
166
+ "js_code": "data.forEach(r => { r.formatted = \"$\" + r.revenue; }); return data;"
167
+ }'
168
+
169
+ # Add report specs (columns) - uses same types and parameters as object_specs
170
+ butterfly-cli record add cms_report_specs --data '{"cms_report_id":50,"field_name":"order_number","title":"Order #","order_no":1}'
171
+ butterfly-cli record add cms_report_specs --data '{"cms_report_id":50,"field_name":"total","title":"Total","order_no":2,"js_code":"return \"$\" + parseFloat(value).toFixed(2);"}'
172
+
173
+ # Add report spec with field type (same as object_specs)
174
+ butterfly-cli record add cms_report_specs --data '{"cms_report_id":50,"field_name":"calculated_field","title":"Calculated","type":"calculated","val_1":"{{ row.quantity * row.price }}"}'
175
+ butterfly-cli record add cms_report_specs --data '{"cms_report_id":50,"field_name":"status","title":"Status","type":"from_list","val_1":"pending,completed,cancelled"}'
176
+ ```
177
+
178
+ ## Workflow: Get → Edit → Update
179
+
180
+ ```bash
181
+ # 1. Get the record and save to file
182
+ butterfly-cli record get bfy_cronjobs --id 5 --output ./cronjob.json
183
+
184
+ # 2. Edit the JSON file locally with your editor
185
+
186
+ # 3. Update the record with modified data
187
+ butterfly-cli record edit bfy_cronjobs --id 5 --file ./cronjob.json
188
+ ```
189
+
190
+ ## Handling Confirmation Dialogs
191
+
192
+ Some operations may require user confirmation before proceeding (e.g., when editing records with state machine transitions or validation rules). When the API response includes a confirmation request, you can programmatically confirm the action.
193
+
194
+ ### Detecting Confirmation Requests
195
+
196
+ When a `record get` or `record edit` operation returns a response with:
197
+ ```json
198
+ {
199
+ "xtra": {
200
+ "type": "confirm",
201
+ "alias": "some_action_alias",
202
+ "message": "Are you sure you want to proceed?"
203
+ }
204
+ }
205
+ ```
206
+
207
+ This indicates the operation requires confirmation.
208
+
209
+ ### Confirming the Action
210
+
211
+ To confirm and proceed with the operation, add a parameter with the format:
212
+ ```
213
+ confirm_message_<alias>=1
214
+ ```
215
+
216
+ Where `<alias>` is the value returned by the API in `response.xtra.alias`. This alias is defined by the server and must be used exactly as returned.
217
+
218
+ ### Example
219
+
220
+ ```bash
221
+ # Initial request returns confirmation dialog
222
+ butterfly-cli record edit orders --id 5 --data '{"status": "cancelled"}'
223
+ # Response: { "xtra": { "type": "confirm", "alias": "cancel_order", "message": "This will cancel the order. Continue?" } }
224
+
225
+ # Confirm the action by adding the confirmation parameter
226
+ butterfly-cli record edit orders --id 5 --data '{"status": "cancelled", "confirm_message_cancel_order": 1}'
227
+ ```
228
+
229
+ ### Using with --data Parameter
230
+
231
+ When you need to include the confirmation in your data:
232
+
233
+ ```bash
234
+ # Single confirmation
235
+ butterfly-cli record edit TABLE --id ID --data '{"field": "value", "confirm_message_ALIAS": 1}'
236
+
237
+ # Example with state machine transition
238
+ butterfly-cli record edit invoices --id 123 --data '{"state": "void", "confirm_message_void_invoice": 1}'
239
+ ```
240
+
241
+ > **AI INSTRUCTION:** When a `record` operation returns `response.xtra.type == "confirm"`, ask the user if they want to proceed. If yes, retry the operation with the additional parameter `confirm_message_<alias>: 1` included in the data payload, where `<alias>` is the exact value from `response.xtra.alias` returned by the API.
242
+
243
+ ## Non-Interactive Mode
244
+
245
+ The record command automatically switches to non-interactive mode when:
246
+ - Running in a non-TTY environment (subprocess, piped output, CI/CD)
247
+ - Using `--yes` or `--no-preview` flags
248
+
249
+ In non-interactive mode:
250
+ - No Ink UI components are used (avoids "Raw mode not supported" errors)
251
+ - Output is clean JSON (suitable for piping to `jq` or other tools)
252
+ - Errors are written to stderr
253
+
254
+ ```bash
255
+ # These automatically use non-interactive mode
256
+ butterfly-cli record get users --no-preview
257
+ butterfly-cli record get users -y
258
+ butterfly-cli record get bfy_cronjobs | jq '.name'
259
+
260
+ # Piping to file also triggers non-interactive mode
261
+ butterfly-cli record get users > users.json
262
+ ```