@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
@@ -0,0 +1,333 @@
1
+ # Butterfly CLI Commands Reference
2
+
3
+ Complete reference for all butterfly-cli commands.
4
+
5
+ ## Setup
6
+
7
+ ```bash
8
+ butterfly-cli setup
9
+ ```
10
+
11
+ Configure authentication (endpoint, email, password).
12
+
13
+ ---
14
+
15
+ ## Download
16
+
17
+ ```bash
18
+ butterfly-cli download [options]
19
+ ```
20
+
21
+ Download resources from the Butterfly platform.
22
+
23
+ ### Options
24
+
25
+ | Option | Description |
26
+ |--------|-------------|
27
+ | `-t, --type <type>` | Resource type to download (see below) |
28
+ | `-n, --name <name>` | Specific resource name to download |
29
+ | `-o, --output <path>` | Output directory (default: ./butterfly-resources) |
30
+ | `--cleanup` | Clean existing contents before downloading |
31
+
32
+ ### Resource Types
33
+
34
+ | Type | Description |
35
+ |------|-------------|
36
+ | `objects` | CMS objects and their specs |
37
+ | `reports` | Reports with queries and specs |
38
+ | `webservices` | Webservice endpoints |
39
+ | `bfy_ai_tasks` | AI tasks |
40
+ | `bfy_state_machines` | State machines with states, transitions, actions |
41
+ | `pages` | Pages |
42
+ | `bfy_cronjobs` | Cron jobs |
43
+ | `cms_email_templates` | Email templates |
44
+ | `cms_email_layouts` | Email layouts |
45
+ | `bfy_workflows` | Workflows with versions, nodes, and connections |
46
+
47
+ ### Examples
48
+
49
+ ```bash
50
+ # Download all resources
51
+ butterfly-cli download
52
+
53
+ # Download only workflows
54
+ butterfly-cli download -t bfy_workflows
55
+
56
+ # Download specific object
57
+ butterfly-cli download -t objects -n users
58
+
59
+ # Download with cleanup
60
+ butterfly-cli download -t bfy_workflows --cleanup
61
+ ```
62
+
63
+ ---
64
+
65
+ ## Upload
66
+
67
+ ```bash
68
+ butterfly-cli upload <targets...>
69
+ ```
70
+
71
+ Upload files or folders to the Butterfly platform.
72
+
73
+ ### Examples
74
+
75
+ ```bash
76
+ # Upload specific file
77
+ butterfly-cli upload path/to/file.bfy
78
+
79
+ # Upload entire folder
80
+ butterfly-cli upload butterfly-resources/objects/default/users/
81
+ ```
82
+
83
+ ---
84
+
85
+ ## Add
86
+
87
+ ```bash
88
+ butterfly-cli add [options]
89
+ ```
90
+
91
+ Create new resources via API and automatically download them.
92
+
93
+ ### Options
94
+
95
+ | Option | Description |
96
+ |--------|-------------|
97
+ | `-t, --type <type>` | Resource type: `workflow`, `workflow-node` |
98
+ | `-w, --workflow <name>` | Workflow name or ID (for workflow-node) |
99
+ | `-v, --version <number>` | Version number (defaults to latest) |
100
+ | `--title <title>` | Title/name of the resource |
101
+ | `--node-type <type>` | Node type (see below) |
102
+ | `--node-group <group>` | Node group (see below) |
103
+ | `--system-name <name>` | System name for the resource |
104
+ | `-o, --output <path>` | Output directory (default: ./butterfly-resources) |
105
+
106
+ ### Node Types
107
+
108
+ | Type | Description |
109
+ |------|-------------|
110
+ | `CustomScript` | Custom code node (default) |
111
+ | `WebHook` | Webhook trigger |
112
+ | `RESTAPI` | REST API connector |
113
+ | `ArkSigner` | ArkSigner integration |
114
+ | `Redirect` | Redirect output |
115
+ | `UserInteraction` | User interaction trigger |
116
+
117
+ ### Node Groups
118
+
119
+ | Group | Description |
120
+ |-------|-------------|
121
+ | `Code` | Code execution nodes (default) |
122
+ | `Trigger` | Trigger nodes (WebHook, UserInteraction) |
123
+ | `Connector` | Connector nodes (RESTAPI) |
124
+ | `Output` | Output nodes (Redirect) |
125
+ | `ThirdParty` | Third-party integrations (ArkSigner) |
126
+
127
+ ### Examples
128
+
129
+ ```bash
130
+ # Create a new workflow
131
+ butterfly-cli add -t workflow --title "My New Workflow"
132
+
133
+ # Add a CustomScript node to a workflow
134
+ butterfly-cli add -t workflow-node -w "E-Imza" --title "Process Data"
135
+
136
+ # Add a REST API connector node
137
+ butterfly-cli add -t workflow-node -w "E-Imza" --title "API Call" --node-group Connector --node-type RESTAPI
138
+
139
+ # Add a webhook trigger
140
+ butterfly-cli add -t workflow-node -w "E-Imza" --title "My Webhook" --node-group Trigger --node-type WebHook
141
+
142
+ # Add node with specific system name
143
+ butterfly-cli add -t workflow-node -w "E-Imza" --title "Process Order" --system-name process_order
144
+
145
+ # Add node to specific version
146
+ butterfly-cli add -t workflow-node -w "E-Imza" -v 1 --title "New Node"
147
+ ```
148
+
149
+ > **Note:** For detailed information about workflow node types, see [WORKFLOW_API.md](WORKFLOW_API.md).
150
+
151
+ ---
152
+
153
+ ## Layout
154
+
155
+ ```bash
156
+ butterfly-cli layout [options]
157
+ ```
158
+
159
+ Update object page layout (tab and field ordering).
160
+
161
+ ### Options
162
+
163
+ | Option | Description |
164
+ |--------|-------------|
165
+ | `-f, --file <path>` | Path to JSON file with layout data |
166
+ | `-d, --data <json>` | Inline JSON layout data |
167
+
168
+ ### Examples
169
+
170
+ ```bash
171
+ # Update layout from a JSON file
172
+ butterfly-cli layout -f layout.json
173
+
174
+ # Update layout with inline JSON
175
+ butterfly-cli layout -d '[{"id":0,"tabs":[{"id":0,"specs":[{"id":1323,"order_no":1}],"order_no":1}]}]'
176
+ ```
177
+
178
+ > **Note:** For detailed layout structure, see [page-layout.md](page-layout.md).
179
+
180
+ ---
181
+
182
+ ## Code (Debug & Test Twig)
183
+
184
+ ```bash
185
+ butterfly-cli code [options]
186
+ ```
187
+
188
+ Execute Twig code on the server and retrieve variables/output. Useful for debugging queries and testing Twig code before deploying.
189
+
190
+ > **WARNING:** This command executes code on the live server. Any CRUD operations (insert, update, delete) will be performed for real. Use with caution.
191
+
192
+ ### Options
193
+
194
+ | Option | Description |
195
+ |--------|-------------|
196
+ | `-c, --code <code>` | Twig code to execute (inline) |
197
+ | `-f, --file <path>` | Path to file containing Twig code |
198
+ | `-o, --output <path>` | Save output to file instead of stdout |
199
+ | `--vars` | Output only the vars object (variables set in the code) |
200
+ | `--output-only` | Output only the rendered output field |
201
+ | `--raw` | Output raw string (no JSON formatting) for `--output-only` |
202
+
203
+ ### Use Cases
204
+
205
+ **1. Debug database queries:**
206
+ ```bash
207
+ butterfly-cli code -c "{% set records = db().table('users').limit(5).get() %}{{ dump(records) }}"
208
+ ```
209
+
210
+ **2. Inspect variable values:**
211
+ ```bash
212
+ butterfly-cli code --vars -c "{% set count = db().table('orders').count() %}{% set total = db().table('orders').sum('amount') %}"
213
+ ```
214
+
215
+ **3. Test complex Twig logic:**
216
+ ```bash
217
+ butterfly-cli code -f my_query.bfy --vars
218
+ ```
219
+
220
+ **4. Verify query results:**
221
+ ```bash
222
+ butterfly-cli code -c "{% set data = db().table('products').where('status', 'active').get() %}{{ data|json_encode }}" --output-only --raw
223
+ ```
224
+
225
+ ### Example Output
226
+
227
+ ```json
228
+ {
229
+ "success": true,
230
+ "vars": {
231
+ "records": [{"id": 1, "name": "Test"}, {"id": 2, "name": "Demo"}],
232
+ "count": 2
233
+ },
234
+ "output": "... rendered output ..."
235
+ }
236
+ ```
237
+
238
+ ---
239
+
240
+ ## Record Commands
241
+
242
+ For database record operations (get, add, edit, delete), see [RECORD_COMMAND.md](RECORD_COMMAND.md).
243
+
244
+ Quick reference:
245
+ ```bash
246
+ # Get record
247
+ butterfly-cli record get <table> --id <id>
248
+ butterfly-cli record get <table> --column <col> --value <val>
249
+
250
+ # Add record
251
+ butterfly-cli record add <table> --data '{...}'
252
+
253
+ # Edit record
254
+ butterfly-cli record edit <table> --id <id> --data '{...}'
255
+
256
+ # Delete record (ask user first!)
257
+ butterfly-cli record delete <table> --id <id>
258
+ ```
259
+
260
+ ---
261
+
262
+ ## Translate
263
+
264
+ ```bash
265
+ butterfly-cli translate <operation> [options]
266
+ ```
267
+
268
+ Manage translations efficiently without reading YAML files.
269
+
270
+ ### Operations
271
+
272
+ | Operation | Description |
273
+ |-----------|-------------|
274
+ | `languages` | List all languages with translation statistics |
275
+ | `get-untranslated` | Get untranslated texts for a language |
276
+ | `add` | Add or update a single translation |
277
+ | `bulk` | Bulk add/update translations from JSON file |
278
+
279
+ ### Options
280
+
281
+ | Option | Description |
282
+ |--------|-------------|
283
+ | `--lang <iso_code>` | Language ISO code (e.g., `tr`, `de`, `en`) |
284
+ | `--lang-id <id>` | Language ID (alternative to `--lang`) |
285
+ | `--source <text>` | Source text to translate |
286
+ | `--source-id <id>` | Source text ID (alternative to `--source`) |
287
+ | `--text <translation>` | Translated text (for `add` operation) |
288
+ | `-f, --file <path>` | CSV file path (tab-delimited) for `bulk` operation |
289
+ | `--format <format>` | Output format: `json` or `table` (default: `table`) |
290
+ | `--limit <count>` | Limit number of results |
291
+
292
+ ### Examples
293
+
294
+ **List languages with stats:**
295
+ ```bash
296
+ butterfly-cli translate languages
297
+ ```
298
+
299
+ **Get untranslated texts:**
300
+ ```bash
301
+ # Get all untranslated texts for Turkish
302
+ butterfly-cli translate get-untranslated --lang tr
303
+
304
+ # Get first 50 as JSON
305
+ butterfly-cli translate get-untranslated --lang tr --limit 50 --format json
306
+ ```
307
+
308
+ **Add single translation:**
309
+ ```bash
310
+ # Add by source text
311
+ butterfly-cli translate add --lang tr --source "Welcome" --text "Hoş geldiniz"
312
+
313
+ # Add by source ID
314
+ butterfly-cli translate add --lang tr --source-id 123 --text "Hoş geldiniz"
315
+ ```
316
+
317
+ **Bulk translate from file:**
318
+ ```bash
319
+ butterfly-cli translate bulk --lang tr --file translations.csv
320
+ ```
321
+
322
+ ### Bulk CSV Format (Tab-Delimited)
323
+
324
+ ```
325
+ source text
326
+ Welcome Hoş geldiniz
327
+ Save Kaydet
328
+ Hello, World! Merhaba, Dünya!
329
+ ```
330
+
331
+ > **Note:** Use TAB as delimiter (not comma) to handle text containing commas. Header row is optional. The `add` command auto-detects existing translations and updates them. The `bulk` command creates missing source texts automatically.
332
+
333
+ For full documentation, see [translations.md](translations.md).
@@ -0,0 +1,95 @@
1
+ # Examples
2
+
3
+ Practical examples for creating objects and specs via CLI.
4
+
5
+ ## Quick Start Examples
6
+
7
+ | Example | Description |
8
+ |---------|-------------|
9
+ | [Product Catalog](./product-catalog.md) | E-commerce product with variants |
10
+ | [User Management](./user-management.md) | Users with profiles and roles |
11
+ | [Order System](./order-system.md) | Orders with nested line items |
12
+ | [Blog](./blog.md) | Posts with categories and tags |
13
+ | [Reports](./reports.md) | Reports with queries and specs |
14
+
15
+ ## Command Cheat Sheet
16
+
17
+ ### Get Object ID
18
+
19
+ ```bash
20
+ # By table name
21
+ butterfly-cli record get objects --column table_name --value "products"
22
+
23
+ # List all app objects
24
+ butterfly-cli record get objects --column is_cms_object --value 0
25
+ ```
26
+
27
+ ### Create Object
28
+
29
+ ```bash
30
+ butterfly-cli record add objects --data '{
31
+ "name": "Display Name",
32
+ "table_name": "table_name",
33
+ "is_cms_object": 0
34
+ }'
35
+ ```
36
+
37
+ ### Create Spec
38
+
39
+ ```bash
40
+ butterfly-cli record add object_specs --data '{
41
+ "object_id": <ID>,
42
+ "name": "Field Name",
43
+ "column_name": "column_name",
44
+ "type": "string"
45
+ }'
46
+ ```
47
+
48
+ ### Common Field Types
49
+
50
+ ```bash
51
+ # String
52
+ --data '{"type":"string"}'
53
+
54
+ # Integer
55
+ --data '{"type":"integer"}'
56
+
57
+ # Textarea
58
+ --data '{"type":"textarea","height":200}'
59
+
60
+ # Dropdown
61
+ --data '{"type":"from_list","val_1":"opt1:Label 1,opt2:Label 2"}'
62
+
63
+ # Foreign Key
64
+ --data '{"type":"dropdown","val_1":"table","val_2":"id","val_3":"name"}'
65
+
66
+ # Date
67
+ --data '{"type":"date"}'
68
+
69
+ # Checkbox
70
+ --data '{"type":"checkbox","default_value":"0"}'
71
+
72
+ # Calculated
73
+ --data '{"type":"calculated","val_1":"{{ info.qty * info.price }}"}'
74
+ ```
75
+
76
+ ## Full Workflow
77
+
78
+ ```bash
79
+ # 1. Create the object
80
+ butterfly-cli record add objects --data '{
81
+ "name": "Tasks",
82
+ "table_name": "tasks"
83
+ }'
84
+ # Response: SUCCESS (ID: 150)
85
+
86
+ # 2. Add fields
87
+ butterfly-cli record add object_specs --data '{"object_id":150,"name":"Title","column_name":"title","type":"string","required":1,"list_column":1,"edit_order_no":1}'
88
+ butterfly-cli record add object_specs --data '{"object_id":150,"name":"Description","column_name":"description","type":"textarea","edit_order_no":2}'
89
+ butterfly-cli record add object_specs --data '{"object_id":150,"name":"Status","column_name":"status","type":"from_list","val_1":"todo:To Do,progress:In Progress,done:Done","edit_order_no":3}'
90
+ butterfly-cli record add object_specs --data '{"object_id":150,"name":"Due Date","column_name":"due_date","type":"date","edit_order_no":4}'
91
+ butterfly-cli record add object_specs --data '{"object_id":150,"name":"Assigned To","column_name":"assigned_user_id","type":"dropdown","val_1":"users","val_2":"id","val_3":"name","edit_order_no":5}'
92
+
93
+ # 3. Verify
94
+ butterfly-cli record get object_specs --column object_id --value 150
95
+ ```
@@ -0,0 +1,147 @@
1
+ # Order System Example
2
+
3
+ Orders with nested line items (one-to-many relationship).
4
+
5
+ ## Step 1: Create Order Items Object (Child)
6
+
7
+ ```bash
8
+ # Create child object first
9
+ butterfly-cli record add objects --data '{
10
+ "name": "Order Items",
11
+ "table_name": "order_items"
12
+ }'
13
+ # Note ID (e.g., 152)
14
+
15
+ # Add fields
16
+ butterfly-cli record add object_specs --data '{"object_id":152,"name":"Order","column_name":"order_id","type":"dropdown","val_1":"orders","val_2":"id","val_3":"id","edit_order_no":1}'
17
+ butterfly-cli record add object_specs --data '{"object_id":152,"name":"Product","column_name":"product_id","type":"dropdown","val_1":"products","val_2":"id","val_3":"title","edit_order_no":2}'
18
+ butterfly-cli record add object_specs --data '{"object_id":152,"name":"Quantity","column_name":"quantity","type":"integer","default_value":"1","edit_order_no":3}'
19
+ butterfly-cli record add object_specs --data '{"object_id":152,"name":"Unit Price","column_name":"unit_price","type":"decimal","edit_order_no":4}'
20
+ butterfly-cli record add object_specs --data '{"object_id":152,"name":"Total","column_name":"line_total","type":"calculated","val_1":"{{ info.quantity * info.unit_price }}","edit_order_no":5}'
21
+ ```
22
+
23
+ ## Step 2: Create Orders Object (Parent)
24
+
25
+ ```bash
26
+ # Create parent object
27
+ butterfly-cli record add objects --data '{
28
+ "name": "Orders",
29
+ "table_name": "orders",
30
+ "has_trash": 1
31
+ }'
32
+ # Note ID (e.g., 153)
33
+
34
+ # Order Info
35
+ butterfly-cli record add object_specs --data '{
36
+ "object_id": 153,
37
+ "name": "Order Number",
38
+ "column_name": "order_number",
39
+ "type": "string",
40
+ "list_column": 1,
41
+ "section_title": "Order Information",
42
+ "edit_order_no": 1
43
+ }'
44
+
45
+ butterfly-cli record add object_specs --data '{
46
+ "object_id": 153,
47
+ "name": "Customer",
48
+ "column_name": "customer_id",
49
+ "type": "dropdown",
50
+ "val_1": "customers",
51
+ "val_2": "id",
52
+ "val_3": "name",
53
+ "required": 1,
54
+ "list_column": 1,
55
+ "edit_order_no": 2
56
+ }'
57
+
58
+ butterfly-cli record add object_specs --data '{
59
+ "object_id": 153,
60
+ "name": "Order Date",
61
+ "column_name": "order_date",
62
+ "type": "date",
63
+ "default_value": "today",
64
+ "list_column": 1,
65
+ "edit_order_no": 3
66
+ }'
67
+
68
+ # Nested Line Items
69
+ butterfly-cli record add object_specs --data '{
70
+ "object_id": 153,
71
+ "name": "Line Items",
72
+ "column_name": "items",
73
+ "type": "nested",
74
+ "val_1": "table: order_items\nforeign_key: order_id\ncolumns:\n - product_id\n - quantity\n - unit_price\n - line_total",
75
+ "section_title": "Order Items",
76
+ "edit_order_no": 4
77
+ }'
78
+
79
+ # Totals
80
+ butterfly-cli record add object_specs --data '{
81
+ "object_id": 153,
82
+ "name": "Subtotal",
83
+ "column_name": "subtotal",
84
+ "type": "decimal",
85
+ "section_title": "Totals",
86
+ "column_size": "col-md-4",
87
+ "edit_order_no": 5
88
+ }'
89
+
90
+ butterfly-cli record add object_specs --data '{
91
+ "object_id": 153,
92
+ "name": "Tax",
93
+ "column_name": "tax_amount",
94
+ "type": "decimal",
95
+ "column_size": "col-md-4",
96
+ "edit_order_no": 6
97
+ }'
98
+
99
+ butterfly-cli record add object_specs --data '{
100
+ "object_id": 153,
101
+ "name": "Total",
102
+ "column_name": "total",
103
+ "type": "decimal",
104
+ "column_size": "col-md-4",
105
+ "edit_order_no": 7
106
+ }'
107
+
108
+ # Sidebar
109
+ butterfly-cli record add object_specs --data '{
110
+ "object_id": 153,
111
+ "name": "Status",
112
+ "column_name": "status",
113
+ "type": "from_list",
114
+ "val_1": "pending:Pending,processing:Processing,shipped:Shipped,delivered:Delivered,cancelled:Cancelled",
115
+ "default_value": "pending",
116
+ "edit_position": 1,
117
+ "edit_order_no": 1
118
+ }'
119
+
120
+ butterfly-cli record add object_specs --data '{
121
+ "object_id": 153,
122
+ "name": "Payment Status",
123
+ "column_name": "payment_status",
124
+ "type": "from_list",
125
+ "val_1": "unpaid:Unpaid,paid:Paid,refunded:Refunded",
126
+ "default_value": "unpaid",
127
+ "edit_position": 1,
128
+ "edit_order_no": 2
129
+ }'
130
+ ```
131
+
132
+ ## Step 3: Add Auto-Calculate on Product Select
133
+
134
+ Update the order items product field to auto-fill price:
135
+
136
+ ```bash
137
+ butterfly-cli record edit object_specs --id <PRODUCT_SPEC_ID> --data '{
138
+ "js_code": "%element%.on(\"change\", function() { var id = $(this).val(); if(id) { $.post(\"/admin/ajax/cms_object/get\", {\"table_name\": \"products\", \"column\": \"id\", \"value\": id}, function(data) { if(data.data[0]) { $(this).closest(\"tr\").find(\"[name*=unit_price]\").val(data.data[0].price).trigger(\"change\"); } }.bind(this)); } })"
139
+ }'
140
+ ```
141
+
142
+ ## Result
143
+
144
+ - **Orders** with customer, date, status tracking
145
+ - **Order Items** as nested sub-form
146
+ - Auto-calculation of line totals
147
+ - Status and payment tracking in sidebar