zinkee 0.1.22 → 0.1.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +2 -1
- package/AGENTS.md +1 -0
- package/README.md +54 -0
- package/dist/index.js +1045 -328
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/document-templates.ts +110 -0
- package/src/command-registry.ts +56 -0
- package/src/commands/automations.test.ts +130 -0
- package/src/commands/automations.ts +50 -2
- package/src/commands/document-templates.test.ts +569 -0
- package/src/commands/document-templates.ts +563 -0
- package/src/program.ts +2 -0
- package/src/utils/examples.test.ts +46 -0
- package/src/utils/examples.ts +252 -0
package/dist/index.js
CHANGED
|
@@ -436,6 +436,62 @@ var commandRegistry = {
|
|
|
436
436
|
supportsRaw: false,
|
|
437
437
|
output: writeOutput
|
|
438
438
|
},
|
|
439
|
+
"document-templates list": {
|
|
440
|
+
command: "document-templates list",
|
|
441
|
+
accessLevel: "read",
|
|
442
|
+
supportsExample: true,
|
|
443
|
+
supportsRaw: false,
|
|
444
|
+
output: readOutput
|
|
445
|
+
},
|
|
446
|
+
"document-templates get": {
|
|
447
|
+
command: "document-templates get",
|
|
448
|
+
accessLevel: "read",
|
|
449
|
+
supportsExample: true,
|
|
450
|
+
supportsRaw: false,
|
|
451
|
+
output: readOutput
|
|
452
|
+
},
|
|
453
|
+
"document-templates create": {
|
|
454
|
+
command: "document-templates create",
|
|
455
|
+
accessLevel: "write",
|
|
456
|
+
supportsExample: true,
|
|
457
|
+
supportsRaw: true,
|
|
458
|
+
output: writeOutput
|
|
459
|
+
},
|
|
460
|
+
"document-templates update": {
|
|
461
|
+
command: "document-templates update",
|
|
462
|
+
accessLevel: "write",
|
|
463
|
+
supportsExample: true,
|
|
464
|
+
supportsRaw: false,
|
|
465
|
+
output: writeOutput
|
|
466
|
+
},
|
|
467
|
+
"document-templates delete": {
|
|
468
|
+
command: "document-templates delete",
|
|
469
|
+
accessLevel: "destructive",
|
|
470
|
+
supportsExample: true,
|
|
471
|
+
supportsRaw: false,
|
|
472
|
+
output: writeOutput
|
|
473
|
+
},
|
|
474
|
+
"document-templates assets add": {
|
|
475
|
+
command: "document-templates assets add",
|
|
476
|
+
accessLevel: "write",
|
|
477
|
+
supportsExample: true,
|
|
478
|
+
supportsRaw: false,
|
|
479
|
+
output: writeOutput
|
|
480
|
+
},
|
|
481
|
+
"document-templates assets delete": {
|
|
482
|
+
command: "document-templates assets delete",
|
|
483
|
+
accessLevel: "destructive",
|
|
484
|
+
supportsExample: true,
|
|
485
|
+
supportsRaw: false,
|
|
486
|
+
output: writeOutput
|
|
487
|
+
},
|
|
488
|
+
"document-templates assets download": {
|
|
489
|
+
command: "document-templates assets download",
|
|
490
|
+
accessLevel: "read",
|
|
491
|
+
supportsExample: true,
|
|
492
|
+
supportsRaw: false,
|
|
493
|
+
output: "binary"
|
|
494
|
+
},
|
|
439
495
|
"files upload": {
|
|
440
496
|
command: "files upload",
|
|
441
497
|
accessLevel: "write",
|
|
@@ -5450,6 +5506,43 @@ var specificExamples = {
|
|
|
5450
5506
|
"steps": ["one", "two"]
|
|
5451
5507
|
}
|
|
5452
5508
|
}
|
|
5509
|
+
}`
|
|
5510
|
+
},
|
|
5511
|
+
{
|
|
5512
|
+
description: "Add a send-message action. --to maps to fieldMapping.recipients and --message maps to fieldMapping.body. Values are wrapped in {rawValue, source} like every other automation field mapping; use --map / --map-json for extra keys.",
|
|
5513
|
+
command: `zinkee --json automations actions add automation-1 --type send_message --name "Notify customer" --to customer@example.com --subject "Your order status has changed" --message "Hello, your order is now processed."`,
|
|
5514
|
+
raw: `{
|
|
5515
|
+
"type": "send_message",
|
|
5516
|
+
"name": "Notify customer",
|
|
5517
|
+
"config": {
|
|
5518
|
+
"fieldMapping": {
|
|
5519
|
+
"recipients": {
|
|
5520
|
+
"rawValue": "customer@example.com",
|
|
5521
|
+
"source": null
|
|
5522
|
+
},
|
|
5523
|
+
"subject": {
|
|
5524
|
+
"rawValue": "Your order status has changed",
|
|
5525
|
+
"source": null
|
|
5526
|
+
},
|
|
5527
|
+
"body": {
|
|
5528
|
+
"rawValue": "Hello, your order is now processed.",
|
|
5529
|
+
"source": null
|
|
5530
|
+
}
|
|
5531
|
+
}
|
|
5532
|
+
}
|
|
5533
|
+
}`
|
|
5534
|
+
},
|
|
5535
|
+
{
|
|
5536
|
+
description: "Add a generate-document action. The renderer reads the template, writes the file, and stores its id in the target FileField of the target schema.",
|
|
5537
|
+
command: 'zinkee --json automations actions add automation-1 --type generate_document --name "Generate invoice PDF" --document-template 6c08673e-f8a6-44d2-8c91-d09eca911f8f --target-schema 68d2c7be-4392-42de-b5ae-625ad79cfc3c --target-file-field c8edbde8-a361-4e9f-a39a-2e88971f21a7',
|
|
5538
|
+
raw: `{
|
|
5539
|
+
"type": "generate_document",
|
|
5540
|
+
"name": "Generate invoice PDF",
|
|
5541
|
+
"config": {
|
|
5542
|
+
"documentTemplateId": "6c08673e-f8a6-44d2-8c91-d09eca911f8f",
|
|
5543
|
+
"targetSchemaId": "68d2c7be-4392-42de-b5ae-625ad79cfc3c",
|
|
5544
|
+
"targetFileFieldId": "c8edbde8-a361-4e9f-a39a-2e88971f21a7"
|
|
5545
|
+
}
|
|
5453
5546
|
}`
|
|
5454
5547
|
}
|
|
5455
5548
|
]),
|
|
@@ -5500,6 +5593,30 @@ var specificExamples = {
|
|
|
5500
5593
|
"authMode": "STORED",
|
|
5501
5594
|
"connectionId": "connection-1"
|
|
5502
5595
|
}
|
|
5596
|
+
}`
|
|
5597
|
+
},
|
|
5598
|
+
{
|
|
5599
|
+
description: "Replace a send-message action. --to maps to fieldMapping.recipients and --message maps to fieldMapping.body; values are wrapped in {rawValue, source}.",
|
|
5600
|
+
command: `zinkee --json automations actions update automation-1 action-1 --type send_message --name "Notify customer" --to customer@example.com --subject "Your order status has changed" --message "Hello, your order is now processed."`,
|
|
5601
|
+
raw: `{
|
|
5602
|
+
"type": "send_message",
|
|
5603
|
+
"name": "Notify customer",
|
|
5604
|
+
"config": {
|
|
5605
|
+
"fieldMapping": {
|
|
5606
|
+
"recipients": {
|
|
5607
|
+
"rawValue": "customer@example.com",
|
|
5608
|
+
"source": null
|
|
5609
|
+
},
|
|
5610
|
+
"subject": {
|
|
5611
|
+
"rawValue": "Your order status has changed",
|
|
5612
|
+
"source": null
|
|
5613
|
+
},
|
|
5614
|
+
"body": {
|
|
5615
|
+
"rawValue": "Hello, your order is now processed.",
|
|
5616
|
+
"source": null
|
|
5617
|
+
}
|
|
5618
|
+
}
|
|
5619
|
+
}
|
|
5503
5620
|
}`
|
|
5504
5621
|
}
|
|
5505
5622
|
]),
|
|
@@ -5660,6 +5777,171 @@ var specificExamples = {
|
|
|
5660
5777
|
"isRoot": false
|
|
5661
5778
|
}`
|
|
5662
5779
|
}
|
|
5780
|
+
]),
|
|
5781
|
+
"document-templates list": buildCommandExamples([
|
|
5782
|
+
{
|
|
5783
|
+
description: "List every document template in the workspace. Each asset's link is a relative path to the asset download endpoint, ready to call without composition.",
|
|
5784
|
+
command: "zinkee --json document-templates list",
|
|
5785
|
+
response: `[
|
|
5786
|
+
{
|
|
5787
|
+
"id": "7c4a8d3f-1b2e-4a5c-9d6e-1f2a3b4c5d6e",
|
|
5788
|
+
"name": "Quarterly report",
|
|
5789
|
+
"assets": [
|
|
5790
|
+
{
|
|
5791
|
+
"id": "9e8d7c6b-5a4f-3e2d-1c0b-9a8b7c6d5e4f",
|
|
5792
|
+
"name": "Requirements.docx",
|
|
5793
|
+
"link": "/api/v2/document-templates/7c4a8d3f-1b2e-4a5c-9d6e-1f2a3b4c5d6e/assets/9e8d7c6b-5a4f-3e2d-1c0b-9a8b7c6d5e4f/download"
|
|
5794
|
+
}
|
|
5795
|
+
],
|
|
5796
|
+
"createdAt": "2026-01-15T10:00:00Z",
|
|
5797
|
+
"updatedAt": "2026-01-20T14:30:00Z",
|
|
5798
|
+
"createdBy": "creator@example.com",
|
|
5799
|
+
"updatedBy": "updater@example.com"
|
|
5800
|
+
}
|
|
5801
|
+
]`
|
|
5802
|
+
}
|
|
5803
|
+
]),
|
|
5804
|
+
"document-templates get": buildCommandExamples([
|
|
5805
|
+
{
|
|
5806
|
+
description: "Look up one template by UUID. The CLI filters the list endpoint locally (the backend does not expose a get-one route).",
|
|
5807
|
+
command: "zinkee --json document-templates get 7c4a8d3f-1b2e-4a5c-9d6e-1f2a3b4c5d6e",
|
|
5808
|
+
response: `{
|
|
5809
|
+
"id": "7c4a8d3f-1b2e-4a5c-9d6e-1f2a3b4c5d6e",
|
|
5810
|
+
"name": "Quarterly report",
|
|
5811
|
+
"assets": [
|
|
5812
|
+
{
|
|
5813
|
+
"id": "9e8d7c6b-5a4f-3e2d-1c0b-9a8b7c6d5e4f",
|
|
5814
|
+
"name": "Requirements.docx",
|
|
5815
|
+
"link": "/api/v2/document-templates/7c4a8d3f-1b2e-4a5c-9d6e-1f2a3b4c5d6e/assets/9e8d7c6b-5a4f-3e2d-1c0b-9a8b7c6d5e4f/download"
|
|
5816
|
+
}
|
|
5817
|
+
],
|
|
5818
|
+
"createdAt": "2026-01-15T10:00:00Z",
|
|
5819
|
+
"updatedAt": "2026-01-20T14:30:00Z",
|
|
5820
|
+
"createdBy": "creator@example.com",
|
|
5821
|
+
"updatedBy": "creator@example.com"
|
|
5822
|
+
}`
|
|
5823
|
+
},
|
|
5824
|
+
{
|
|
5825
|
+
description: "Look up by exact template name. Names are unique within the workspace; ambiguity is reported as an error.",
|
|
5826
|
+
command: 'zinkee --json document-templates get "Quarterly report"'
|
|
5827
|
+
}
|
|
5828
|
+
]),
|
|
5829
|
+
"document-templates create": buildCommandExamples([
|
|
5830
|
+
{
|
|
5831
|
+
description: "Typical create: empty template by name. Assets are uploaded afterwards via document-templates assets add.",
|
|
5832
|
+
command: 'zinkee --json document-templates create --name "Quarterly report"',
|
|
5833
|
+
raw: `{
|
|
5834
|
+
"name": "Quarterly report",
|
|
5835
|
+
"assets": []
|
|
5836
|
+
}`,
|
|
5837
|
+
response: `{
|
|
5838
|
+
"id": "7c4a8d3f-1b2e-4a5c-9d6e-1f2a3b4c5d6e",
|
|
5839
|
+
"name": "Quarterly report",
|
|
5840
|
+
"assets": [],
|
|
5841
|
+
"createdAt": "2026-01-15T10:00:00Z",
|
|
5842
|
+
"updatedAt": "2026-01-15T10:00:00Z",
|
|
5843
|
+
"createdBy": "creator@example.com",
|
|
5844
|
+
"updatedBy": "creator@example.com"
|
|
5845
|
+
}`
|
|
5846
|
+
},
|
|
5847
|
+
{
|
|
5848
|
+
description: "Create with pre-existing asset records via --raw. Used for import/migration flows where the assets already exist elsewhere; the typical UX is to create empty and upload via assets add.",
|
|
5849
|
+
command: `zinkee --json document-templates create --raw '{"name":"Annual report","assets":[{"id":"9e8d7c6b-5a4f-3e2d-1c0b-9a8b7c6d5e4f","name":"Cover.docx","link":"/existing/cover.docx"},{"id":"3f2e1d0c-9b8a-7654-3210-fedcba987654","name":"Appendix.docx","link":"/existing/appendix.docx"}]}'`,
|
|
5850
|
+
raw: `{
|
|
5851
|
+
"name": "Annual report",
|
|
5852
|
+
"assets": [
|
|
5853
|
+
{
|
|
5854
|
+
"id": "9e8d7c6b-5a4f-3e2d-1c0b-9a8b7c6d5e4f",
|
|
5855
|
+
"name": "Cover.docx",
|
|
5856
|
+
"link": "/existing/cover.docx"
|
|
5857
|
+
},
|
|
5858
|
+
{
|
|
5859
|
+
"id": "3f2e1d0c-9b8a-7654-3210-fedcba987654",
|
|
5860
|
+
"name": "Appendix.docx",
|
|
5861
|
+
"link": "/existing/appendix.docx"
|
|
5862
|
+
}
|
|
5863
|
+
]
|
|
5864
|
+
}`
|
|
5865
|
+
}
|
|
5866
|
+
]),
|
|
5867
|
+
"document-templates update": buildCommandExamples([
|
|
5868
|
+
{
|
|
5869
|
+
description: "Rename a template. The template argument accepts a UUID or an exact current name. Only the name is updatable through this endpoint; assets are managed via the assets subcommands.",
|
|
5870
|
+
command: 'zinkee --json document-templates update "Quarterly report" --name "Annual report"',
|
|
5871
|
+
raw: `{
|
|
5872
|
+
"name": "Annual report"
|
|
5873
|
+
}`,
|
|
5874
|
+
response: `{
|
|
5875
|
+
"id": "7c4a8d3f-1b2e-4a5c-9d6e-1f2a3b4c5d6e",
|
|
5876
|
+
"name": "Annual report",
|
|
5877
|
+
"assets": [
|
|
5878
|
+
{
|
|
5879
|
+
"id": "9e8d7c6b-5a4f-3e2d-1c0b-9a8b7c6d5e4f",
|
|
5880
|
+
"name": "Requirements.docx",
|
|
5881
|
+
"link": "/api/v2/document-templates/7c4a8d3f-1b2e-4a5c-9d6e-1f2a3b4c5d6e/assets/9e8d7c6b-5a4f-3e2d-1c0b-9a8b7c6d5e4f/download"
|
|
5882
|
+
}
|
|
5883
|
+
],
|
|
5884
|
+
"createdAt": "2026-01-15T10:00:00Z",
|
|
5885
|
+
"updatedAt": "2026-01-22T09:15:00Z",
|
|
5886
|
+
"createdBy": "creator@example.com",
|
|
5887
|
+
"updatedBy": "updater@example.com"
|
|
5888
|
+
}`
|
|
5889
|
+
}
|
|
5890
|
+
]),
|
|
5891
|
+
"document-templates delete": buildCommandExamples([
|
|
5892
|
+
{
|
|
5893
|
+
description: "Delete a template and remove its asset files from storage. Record fields that reference previously generated documents are not modified.",
|
|
5894
|
+
command: "zinkee --json document-templates delete 7c4a8d3f-1b2e-4a5c-9d6e-1f2a3b4c5d6e",
|
|
5895
|
+
response: `{
|
|
5896
|
+
"id": "7c4a8d3f-1b2e-4a5c-9d6e-1f2a3b4c5d6e",
|
|
5897
|
+
"deleted": true
|
|
5898
|
+
}`
|
|
5899
|
+
}
|
|
5900
|
+
]),
|
|
5901
|
+
"document-templates assets add": buildCommandExamples([
|
|
5902
|
+
{
|
|
5903
|
+
description: 'Upload a local file as an asset of a template. The CLI sends a multipart form with a part named "file"; the asset display name defaults to the uploaded filename.',
|
|
5904
|
+
command: 'zinkee --json document-templates assets add "Quarterly report" ./contract.docx',
|
|
5905
|
+
response: `{
|
|
5906
|
+
"id": "7c4a8d3f-1b2e-4a5c-9d6e-1f2a3b4c5d6e",
|
|
5907
|
+
"name": "Quarterly report",
|
|
5908
|
+
"assets": [
|
|
5909
|
+
{
|
|
5910
|
+
"id": "9e8d7c6b-5a4f-3e2d-1c0b-9a8b7c6d5e4f",
|
|
5911
|
+
"name": "contract.docx",
|
|
5912
|
+
"link": "/api/v2/document-templates/7c4a8d3f-1b2e-4a5c-9d6e-1f2a3b4c5d6e/assets/9e8d7c6b-5a4f-3e2d-1c0b-9a8b7c6d5e4f/download"
|
|
5913
|
+
}
|
|
5914
|
+
],
|
|
5915
|
+
"createdAt": "2026-01-15T10:00:00Z",
|
|
5916
|
+
"updatedAt": "2026-01-22T09:15:00Z",
|
|
5917
|
+
"createdBy": "creator@example.com",
|
|
5918
|
+
"updatedBy": "updater@example.com"
|
|
5919
|
+
}`
|
|
5920
|
+
},
|
|
5921
|
+
{
|
|
5922
|
+
description: "Override the asset display name with --name (otherwise the uploaded filename is used).",
|
|
5923
|
+
command: 'zinkee --json document-templates assets add "Quarterly report" ./contract.docx --name "Customer Contract"'
|
|
5924
|
+
}
|
|
5925
|
+
]),
|
|
5926
|
+
"document-templates assets delete": buildCommandExamples([
|
|
5927
|
+
{
|
|
5928
|
+
description: "Delete one asset from a template and remove its file from storage.",
|
|
5929
|
+
command: "zinkee --json document-templates assets delete 7c4a8d3f-1b2e-4a5c-9d6e-1f2a3b4c5d6e 9e8d7c6b-5a4f-3e2d-1c0b-9a8b7c6d5e4f",
|
|
5930
|
+
response: `{
|
|
5931
|
+
"id": "9e8d7c6b-5a4f-3e2d-1c0b-9a8b7c6d5e4f",
|
|
5932
|
+
"deleted": true
|
|
5933
|
+
}`
|
|
5934
|
+
}
|
|
5935
|
+
]),
|
|
5936
|
+
"document-templates assets download": buildCommandExamples([
|
|
5937
|
+
{
|
|
5938
|
+
description: "Download asset bytes to disk. The CLI streams the raw bytes to --output; in --json mode --output is required and the JSON envelope only carries metadata.",
|
|
5939
|
+
command: "zinkee --json document-templates assets download 7c4a8d3f-1b2e-4a5c-9d6e-1f2a3b4c5d6e 9e8d7c6b-5a4f-3e2d-1c0b-9a8b7c6d5e4f --output ./contract.docx"
|
|
5940
|
+
},
|
|
5941
|
+
{
|
|
5942
|
+
description: "Stream asset bytes to stdout (omit --json and --output). Useful for piping into other tools.",
|
|
5943
|
+
command: "zinkee document-templates assets download 7c4a8d3f-1b2e-4a5c-9d6e-1f2a3b4c5d6e 9e8d7c6b-5a4f-3e2d-1c0b-9a8b7c6d5e4f > contract.docx"
|
|
5944
|
+
}
|
|
5663
5945
|
])
|
|
5664
5946
|
};
|
|
5665
5947
|
function fallbackExamples(commandName) {
|
|
@@ -5779,7 +6061,7 @@ ${index + 1}. ${example.description}
|
|
|
5779
6061
|
|
|
5780
6062
|
// src/program.ts
|
|
5781
6063
|
import { createRequire } from "module";
|
|
5782
|
-
import { Command as
|
|
6064
|
+
import { Command as Command11 } from "commander";
|
|
5783
6065
|
|
|
5784
6066
|
// src/config.ts
|
|
5785
6067
|
import { mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
@@ -6540,11 +6822,11 @@ function hasSetPath(target, path) {
|
|
|
6540
6822
|
return Object.hasOwn(target, path);
|
|
6541
6823
|
}
|
|
6542
6824
|
let current = target;
|
|
6543
|
-
for (const
|
|
6544
|
-
if (!isJsonObject2(current) || !Object.hasOwn(current,
|
|
6825
|
+
for (const segment4 of segments) {
|
|
6826
|
+
if (!isJsonObject2(current) || !Object.hasOwn(current, segment4)) {
|
|
6545
6827
|
return false;
|
|
6546
6828
|
}
|
|
6547
|
-
current = current[
|
|
6829
|
+
current = current[segment4];
|
|
6548
6830
|
}
|
|
6549
6831
|
return true;
|
|
6550
6832
|
}
|
|
@@ -7007,6 +7289,15 @@ function buildActionInput(options, mode) {
|
|
|
7007
7289
|
if (options.targetSchema !== void 0) {
|
|
7008
7290
|
config.targetSchemaId = options.targetSchema;
|
|
7009
7291
|
}
|
|
7292
|
+
if (options.to !== void 0) {
|
|
7293
|
+
mappings.recipients = options.to;
|
|
7294
|
+
}
|
|
7295
|
+
if (options.subject !== void 0) {
|
|
7296
|
+
mappings.subject = options.subject;
|
|
7297
|
+
}
|
|
7298
|
+
if (options.message !== void 0) {
|
|
7299
|
+
mappings.body = options.message;
|
|
7300
|
+
}
|
|
7010
7301
|
if (!isEmptyObject(mappings)) {
|
|
7011
7302
|
config.fieldMapping = mappings;
|
|
7012
7303
|
}
|
|
@@ -7050,6 +7341,12 @@ function buildActionInput(options, mode) {
|
|
|
7050
7341
|
if (!isEmptyObject(args)) {
|
|
7051
7342
|
config.pluginArgs = args;
|
|
7052
7343
|
}
|
|
7344
|
+
if (options.documentTemplate !== void 0) {
|
|
7345
|
+
config.documentTemplateId = options.documentTemplate;
|
|
7346
|
+
}
|
|
7347
|
+
if (options.targetFileField !== void 0) {
|
|
7348
|
+
config.targetFileFieldId = options.targetFileField;
|
|
7349
|
+
}
|
|
7053
7350
|
if (!isEmptyObject(config)) {
|
|
7054
7351
|
if (isJsonObject2(config.fieldMapping)) {
|
|
7055
7352
|
config.fieldMapping = normalizeAutomationFieldMapping(
|
|
@@ -7236,12 +7533,28 @@ function addTriggerPayloadOptions(command) {
|
|
|
7236
7533
|
[]
|
|
7237
7534
|
).option("--webhook-endpoint-id <uuid>", "webhook endpoint id").option("--raw <json>", "raw trigger JSON payload").option("--raw-file <path>", "path to raw trigger JSON payload");
|
|
7238
7535
|
}
|
|
7536
|
+
var ACTION_TYPES_HELP = `
|
|
7537
|
+
Action types and their flags:
|
|
7538
|
+
create_record --target-schema, --map, --map-json
|
|
7539
|
+
update_record --target-schema, --use-trigger-record, --map,
|
|
7540
|
+
--condition, --condition-json
|
|
7541
|
+
search_records --target-schema, --condition, --condition-json
|
|
7542
|
+
send_message --to, --subject, --message
|
|
7543
|
+
(--map / --map-json also accepted for extra keys)
|
|
7544
|
+
http_request --method, --url, --header, --body, --content-type,
|
|
7545
|
+
--timeout-ms, --var, --auth-mode, --connection
|
|
7546
|
+
execute_plugin --plugin, --arg, --arg-json
|
|
7547
|
+
generate_document --document-template, --target-schema, --target-file-field
|
|
7548
|
+
`;
|
|
7239
7549
|
function addActionPayloadOptions(command) {
|
|
7240
|
-
return command.option(
|
|
7550
|
+
return command.option(
|
|
7551
|
+
"--type <type>",
|
|
7552
|
+
"action type (create_record|update_record|search_records|send_message|http_request|execute_plugin|generate_document)"
|
|
7553
|
+
).option("--name <name>", "action name").option("--target-schema <uuid>", "target schema id").option("--map <field=value>", "field mapping", collectValues, []).option("--map-json <field=json>", "JSON field mapping", collectValues, []).option("--condition <field:comparator:value>", "action condition", collectValues, []).option("--condition-json <json>", "action condition as JSON", collectValues, []).option("--use-trigger-record", "use the triggering record").option("--method <method>", "HTTP method").option("--url <url>", "HTTP target URL").option("--header <key=value>", "HTTP header", collectValues, []).option("--body <json>", "HTTP request body as JSON").option("--body-file <path>", "path to HTTP request body JSON").option("--content-type <type>", "HTTP content type").option(
|
|
7241
7554
|
"--timeout-ms <n>",
|
|
7242
7555
|
"HTTP timeout in milliseconds",
|
|
7243
7556
|
parseNonNegativeInteger
|
|
7244
|
-
).option("--var <key=value>", "HTTP variable", collectValues, []).option("--auth-mode <mode>", "HTTP auth mode").option("--connection <uuid>", "connection id for HTTP auth").option("--plugin <id>", "plugin id for execute_plugin").option("--arg <key=value>", "plugin argument", collectValues, []).option("--arg-json <key=json>", "plugin argument as JSON", collectValues, []).option("--raw <json>", "raw action JSON payload").option("--raw-file <path>", "path to raw action JSON payload");
|
|
7557
|
+
).option("--var <key=value>", "HTTP variable", collectValues, []).option("--auth-mode <mode>", "HTTP auth mode").option("--connection <uuid>", "connection id for HTTP auth").option("--plugin <id>", "plugin id for execute_plugin").option("--arg <key=value>", "plugin argument", collectValues, []).option("--arg-json <key=json>", "plugin argument as JSON", collectValues, []).option("--to <recipient>", "send_message recipient (maps to fieldMapping.recipients)").option("--subject <text>", "send_message subject").option("--message <text>", "send_message body text (maps to fieldMapping.body)").option("--document-template <uuid>", "generate_document template id").option("--target-file-field <uuid>", "generate_document target FileField id").option("--raw <json>", "raw action JSON payload").option("--raw-file <path>", "path to raw action JSON payload").addHelpText("after", ACTION_TYPES_HELP);
|
|
7245
7558
|
}
|
|
7246
7559
|
function registerAutomationsCommands(program, options = {}) {
|
|
7247
7560
|
const filePath = options.configPath ?? defaultConfigPath;
|
|
@@ -8657,40 +8970,72 @@ function registerDisplaysCommands(program, options = {}) {
|
|
|
8657
8970
|
});
|
|
8658
8971
|
}
|
|
8659
8972
|
|
|
8660
|
-
// src/commands/
|
|
8973
|
+
// src/commands/document-templates.ts
|
|
8661
8974
|
import { readFileSync as readFileSync5, writeFileSync as writeFileSync2 } from "fs";
|
|
8662
8975
|
import { basename } from "path";
|
|
8663
8976
|
import { InvalidArgumentError as InvalidArgumentError4 } from "commander";
|
|
8664
8977
|
|
|
8665
|
-
// src/api/
|
|
8978
|
+
// src/api/document-templates.ts
|
|
8979
|
+
function jsonOptions4(body, method) {
|
|
8980
|
+
return {
|
|
8981
|
+
method,
|
|
8982
|
+
headers: {
|
|
8983
|
+
"content-type": "application/json"
|
|
8984
|
+
},
|
|
8985
|
+
body: JSON.stringify(body)
|
|
8986
|
+
};
|
|
8987
|
+
}
|
|
8666
8988
|
function selectorValue4(selector) {
|
|
8667
|
-
return selector.value;
|
|
8989
|
+
return encodeURIComponent(selector.value);
|
|
8668
8990
|
}
|
|
8669
|
-
|
|
8991
|
+
function segment3(value) {
|
|
8992
|
+
return encodeURIComponent(value);
|
|
8993
|
+
}
|
|
8994
|
+
var DocumentTemplatesApi = class {
|
|
8670
8995
|
constructor(client) {
|
|
8671
8996
|
this.client = client;
|
|
8672
8997
|
}
|
|
8673
|
-
|
|
8674
|
-
return this.client.
|
|
8675
|
-
method: "POST",
|
|
8676
|
-
body: input
|
|
8677
|
-
});
|
|
8998
|
+
listTemplates() {
|
|
8999
|
+
return this.client.getJson("/api/v2/document-templates");
|
|
8678
9000
|
}
|
|
8679
|
-
|
|
8680
|
-
return this.client.
|
|
9001
|
+
createTemplate(input) {
|
|
9002
|
+
return this.client.requestJson(
|
|
9003
|
+
"/api/v2/document-templates",
|
|
9004
|
+
jsonOptions4(input, "POST")
|
|
9005
|
+
);
|
|
8681
9006
|
}
|
|
8682
|
-
|
|
9007
|
+
updateTemplate(template, input) {
|
|
9008
|
+
return this.client.requestJson(
|
|
9009
|
+
`/api/v2/document-templates/${selectorValue4(template)}`,
|
|
9010
|
+
jsonOptions4(input, "PATCH")
|
|
9011
|
+
);
|
|
9012
|
+
}
|
|
9013
|
+
deleteTemplate(template) {
|
|
8683
9014
|
return this.client.requestJson(
|
|
8684
|
-
`/api/v2/
|
|
9015
|
+
`/api/v2/document-templates/${selectorValue4(template)}`,
|
|
8685
9016
|
{ method: "DELETE" }
|
|
8686
9017
|
);
|
|
8687
9018
|
}
|
|
8688
|
-
|
|
8689
|
-
return this.client.
|
|
9019
|
+
addAsset(template, input) {
|
|
9020
|
+
return this.client.requestJson(
|
|
9021
|
+
`/api/v2/document-templates/${selectorValue4(template)}/assets`,
|
|
9022
|
+
{ method: "POST", body: input }
|
|
9023
|
+
);
|
|
9024
|
+
}
|
|
9025
|
+
deleteAsset(template, assetId) {
|
|
9026
|
+
return this.client.requestJson(
|
|
9027
|
+
`/api/v2/document-templates/${selectorValue4(template)}/assets/${segment3(assetId)}`,
|
|
9028
|
+
{ method: "DELETE" }
|
|
9029
|
+
);
|
|
9030
|
+
}
|
|
9031
|
+
downloadAsset(template, assetId) {
|
|
9032
|
+
return this.client.requestBinary(
|
|
9033
|
+
`/api/v2/document-templates/${selectorValue4(template)}/assets/${segment3(assetId)}/download`
|
|
9034
|
+
);
|
|
8690
9035
|
}
|
|
8691
9036
|
};
|
|
8692
9037
|
|
|
8693
|
-
// src/commands/
|
|
9038
|
+
// src/commands/document-templates.ts
|
|
8694
9039
|
function getCommandIo5(stdout) {
|
|
8695
9040
|
return stdout ?? process.stdout;
|
|
8696
9041
|
}
|
|
@@ -8722,7 +9067,7 @@ function toConfigurationError5(filePath, error) {
|
|
|
8722
9067
|
}
|
|
8723
9068
|
throw error;
|
|
8724
9069
|
}
|
|
8725
|
-
function
|
|
9070
|
+
function createDocumentTemplatesApi(command, filePath) {
|
|
8726
9071
|
try {
|
|
8727
9072
|
const config = readRuntimeConfig(filePath);
|
|
8728
9073
|
const runtime = resolveRuntimeContext(config, getGlobalOptions5(command));
|
|
@@ -8733,7 +9078,7 @@ function createFilesApi(command, filePath) {
|
|
|
8733
9078
|
);
|
|
8734
9079
|
}
|
|
8735
9080
|
return {
|
|
8736
|
-
api: new
|
|
9081
|
+
api: new DocumentTemplatesApi(
|
|
8737
9082
|
new ApiClient({
|
|
8738
9083
|
baseUrl: runtime.baseUrl,
|
|
8739
9084
|
apiKey: runtime.apiKey
|
|
@@ -8766,9 +9111,57 @@ function parseUuidOrSlugSelector4(input) {
|
|
|
8766
9111
|
throw new InvalidArgumentError4(message);
|
|
8767
9112
|
}
|
|
8768
9113
|
}
|
|
8769
|
-
function
|
|
9114
|
+
function isJsonObject4(value) {
|
|
8770
9115
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8771
9116
|
}
|
|
9117
|
+
function isEmptyObject4(value) {
|
|
9118
|
+
return Object.keys(value).length === 0;
|
|
9119
|
+
}
|
|
9120
|
+
function parseJsonValue2(input, sourceLabel) {
|
|
9121
|
+
try {
|
|
9122
|
+
return JSON.parse(input);
|
|
9123
|
+
} catch (error) {
|
|
9124
|
+
const message = error instanceof Error ? error.message : "Invalid JSON.";
|
|
9125
|
+
throw new CliError(
|
|
9126
|
+
"invalid_cli_usage",
|
|
9127
|
+
`Failed to parse JSON from ${sourceLabel}: ${message}`
|
|
9128
|
+
);
|
|
9129
|
+
}
|
|
9130
|
+
}
|
|
9131
|
+
function readTextFile2(filePath, label) {
|
|
9132
|
+
try {
|
|
9133
|
+
return readFileSync5(filePath, "utf8");
|
|
9134
|
+
} catch (error) {
|
|
9135
|
+
const message = error instanceof Error ? error.message : "Unable to read file.";
|
|
9136
|
+
throw new CliError(
|
|
9137
|
+
"invalid_cli_usage",
|
|
9138
|
+
`Failed to read ${label} from ${filePath}: ${message}`
|
|
9139
|
+
);
|
|
9140
|
+
}
|
|
9141
|
+
}
|
|
9142
|
+
function readJsonObjectOption2(raw, rawFile, rawLabel, rawFileLabel) {
|
|
9143
|
+
if (raw && rawFile) {
|
|
9144
|
+
throw new CliError(
|
|
9145
|
+
"invalid_cli_usage",
|
|
9146
|
+
`Provide either "${rawLabel}" or "${rawFileLabel}", not both.`
|
|
9147
|
+
);
|
|
9148
|
+
}
|
|
9149
|
+
let parsed;
|
|
9150
|
+
if (raw) {
|
|
9151
|
+
parsed = parseJsonValue2(raw, rawLabel);
|
|
9152
|
+
} else if (rawFile) {
|
|
9153
|
+
parsed = parseJsonValue2(readTextFile2(rawFile, rawFileLabel), `${rawFileLabel} ${rawFile}`);
|
|
9154
|
+
} else {
|
|
9155
|
+
return {};
|
|
9156
|
+
}
|
|
9157
|
+
if (!isJsonObject4(parsed)) {
|
|
9158
|
+
throw new CliError(
|
|
9159
|
+
"invalid_cli_usage",
|
|
9160
|
+
`Expected ${raw ? rawLabel : rawFileLabel} to contain a JSON object.`
|
|
9161
|
+
);
|
|
9162
|
+
}
|
|
9163
|
+
return parsed;
|
|
9164
|
+
}
|
|
8772
9165
|
function readLocalFile(filePath) {
|
|
8773
9166
|
try {
|
|
8774
9167
|
return readFileSync5(filePath);
|
|
@@ -8788,38 +9181,361 @@ function writeDownloadedFile(outputPath, value) {
|
|
|
8788
9181
|
);
|
|
8789
9182
|
}
|
|
8790
9183
|
}
|
|
8791
|
-
function
|
|
8792
|
-
|
|
8793
|
-
|
|
8794
|
-
|
|
8795
|
-
|
|
8796
|
-
|
|
8797
|
-
|
|
8798
|
-
|
|
8799
|
-
|
|
8800
|
-
|
|
8801
|
-
|
|
8802
|
-
|
|
8803
|
-
|
|
8804
|
-
|
|
8805
|
-
|
|
8806
|
-
|
|
8807
|
-
|
|
8808
|
-
|
|
8809
|
-
|
|
8810
|
-
|
|
8811
|
-
|
|
8812
|
-
|
|
8813
|
-
|
|
8814
|
-
|
|
8815
|
-
|
|
9184
|
+
function templateRows(templates) {
|
|
9185
|
+
return templates.map((template) => ({
|
|
9186
|
+
id: template.id ?? "",
|
|
9187
|
+
name: template.name ?? "",
|
|
9188
|
+
assetCount: Array.isArray(template.assets) ? template.assets.length : 0,
|
|
9189
|
+
updatedAt: template.updatedAt ?? ""
|
|
9190
|
+
}));
|
|
9191
|
+
}
|
|
9192
|
+
function resolveTemplate(templates, selector) {
|
|
9193
|
+
if (selector.kind === "uuid") {
|
|
9194
|
+
const match = templates.find((template) => template.id === selector.value);
|
|
9195
|
+
if (match) {
|
|
9196
|
+
return match;
|
|
9197
|
+
}
|
|
9198
|
+
throw new CliError(
|
|
9199
|
+
"invalid_cli_usage",
|
|
9200
|
+
`Document template "${selector.value}" was not found.`
|
|
9201
|
+
);
|
|
9202
|
+
}
|
|
9203
|
+
const matches = templates.filter((template) => template.name === selector.value);
|
|
9204
|
+
if (matches.length === 1) {
|
|
9205
|
+
return matches[0];
|
|
9206
|
+
}
|
|
9207
|
+
if (matches.length > 1) {
|
|
9208
|
+
throw new CliError(
|
|
9209
|
+
"invalid_cli_usage",
|
|
9210
|
+
`Document template "${selector.value}" is ambiguous. Found ${matches.length} matches.`
|
|
9211
|
+
);
|
|
9212
|
+
}
|
|
9213
|
+
throw new CliError(
|
|
9214
|
+
"invalid_cli_usage",
|
|
9215
|
+
`Document template "${selector.value}" was not found.`
|
|
9216
|
+
);
|
|
9217
|
+
}
|
|
9218
|
+
async function resolveTemplateSelector(api, selector) {
|
|
9219
|
+
if (selector.kind === "uuid") {
|
|
9220
|
+
return selector;
|
|
9221
|
+
}
|
|
9222
|
+
const templates = await api.listTemplates();
|
|
9223
|
+
const resolved = resolveTemplate(templates, selector);
|
|
9224
|
+
if (typeof resolved.id !== "string" || resolved.id.length === 0) {
|
|
9225
|
+
throw new CliError(
|
|
9226
|
+
"invalid_cli_usage",
|
|
9227
|
+
`Document template "${selector.value}" is missing an id in the API response.`
|
|
9228
|
+
);
|
|
9229
|
+
}
|
|
9230
|
+
return { kind: "uuid", value: resolved.id };
|
|
9231
|
+
}
|
|
9232
|
+
function buildCreateInput(options) {
|
|
9233
|
+
const raw = readJsonObjectOption2(options.raw, options.rawFile, "--raw", "--raw-file");
|
|
9234
|
+
const input = { ...raw };
|
|
9235
|
+
if (options.name !== void 0) {
|
|
9236
|
+
input.name = options.name;
|
|
9237
|
+
}
|
|
9238
|
+
if (typeof input.name !== "string" || input.name.trim().length === 0) {
|
|
9239
|
+
throw new CliError("invalid_cli_usage", 'Provide template name via "--name".');
|
|
9240
|
+
}
|
|
9241
|
+
if (input.assets === void 0) {
|
|
9242
|
+
input.assets = [];
|
|
9243
|
+
}
|
|
9244
|
+
return input;
|
|
9245
|
+
}
|
|
9246
|
+
function buildUpdateInput(options) {
|
|
9247
|
+
const input = {};
|
|
9248
|
+
if (options.name !== void 0) {
|
|
9249
|
+
input.name = options.name;
|
|
9250
|
+
}
|
|
9251
|
+
if (isEmptyObject4(input)) {
|
|
9252
|
+
throw new CliError("invalid_cli_usage", 'Provide template updates via "--name".');
|
|
9253
|
+
}
|
|
9254
|
+
return input;
|
|
9255
|
+
}
|
|
9256
|
+
function registerDocumentTemplatesCommands(program, options = {}) {
|
|
9257
|
+
const filePath = options.configPath ?? defaultConfigPath;
|
|
9258
|
+
const stdout = getCommandIo5(options.stdout);
|
|
9259
|
+
const templates = program.command("document-templates").description("Manage document templates and their assets");
|
|
9260
|
+
templates.command("list").description("List document templates").action(async function action() {
|
|
9261
|
+
const { api, json } = createDocumentTemplatesApi(this, filePath);
|
|
9262
|
+
const data = await api.listTemplates();
|
|
9263
|
+
if (json) {
|
|
9264
|
+
emitJson5(stdout, "document-templates list", data, filePath);
|
|
9265
|
+
return;
|
|
9266
|
+
}
|
|
9267
|
+
printTable(templateRows(data), ["id", "name", "assetCount", "updatedAt"], stdout);
|
|
9268
|
+
});
|
|
9269
|
+
templates.command("get").description("Get a document template by UUID or exact name").argument("<template>", "template UUID or exact name", parseUuidOrSlugSelector4).action(async function action(template) {
|
|
9270
|
+
const { api, json } = createDocumentTemplatesApi(this, filePath);
|
|
9271
|
+
const list = await api.listTemplates();
|
|
9272
|
+
const data = resolveTemplate(list, template);
|
|
9273
|
+
if (json) {
|
|
9274
|
+
emitJson5(stdout, "document-templates get", data, filePath);
|
|
9275
|
+
return;
|
|
9276
|
+
}
|
|
9277
|
+
printTable([data], void 0, stdout);
|
|
9278
|
+
});
|
|
9279
|
+
templates.command("create").description("Create a document template").option("--name <name>", "template name").option("--raw <json>", "raw create JSON payload").option("--raw-file <path>", "path to raw create JSON payload").action(async function action(commandOptions) {
|
|
9280
|
+
const { api, json, readOnly } = createDocumentTemplatesApi(this, filePath);
|
|
9281
|
+
ensureWritable4("document-templates create", readOnly, "write");
|
|
9282
|
+
const data = await api.createTemplate(buildCreateInput(commandOptions));
|
|
9283
|
+
if (json) {
|
|
9284
|
+
emitJson5(stdout, "document-templates create", data, filePath);
|
|
9285
|
+
return;
|
|
9286
|
+
}
|
|
9287
|
+
writeLine5(stdout, `Created document template "${String(data.name ?? commandOptions.name)}".`);
|
|
9288
|
+
});
|
|
9289
|
+
templates.command("update").description("Rename a document template").argument("<template>", "template UUID or exact name", parseUuidOrSlugSelector4).option("--name <name>", "new template name").action(async function action(template, commandOptions) {
|
|
9290
|
+
const { api, json, readOnly } = createDocumentTemplatesApi(this, filePath);
|
|
9291
|
+
ensureWritable4("document-templates update", readOnly, "write");
|
|
9292
|
+
const resolved = await resolveTemplateSelector(api, template);
|
|
9293
|
+
const data = await api.updateTemplate(resolved, buildUpdateInput(commandOptions));
|
|
9294
|
+
if (json) {
|
|
9295
|
+
emitJson5(stdout, "document-templates update", data, filePath);
|
|
9296
|
+
return;
|
|
9297
|
+
}
|
|
9298
|
+
writeLine5(stdout, `Updated document template "${String(data.name ?? template.value)}".`);
|
|
9299
|
+
});
|
|
9300
|
+
templates.command("delete").description("Delete a document template (and its assets)").argument("<template>", "template UUID or exact name", parseUuidOrSlugSelector4).action(async function action(template) {
|
|
9301
|
+
const { api, json, readOnly } = createDocumentTemplatesApi(this, filePath);
|
|
9302
|
+
ensureWritable4("document-templates delete", readOnly, "destructive");
|
|
9303
|
+
const resolved = await resolveTemplateSelector(api, template);
|
|
9304
|
+
const data = await api.deleteTemplate(resolved);
|
|
9305
|
+
if (json) {
|
|
9306
|
+
emitJson5(stdout, "document-templates delete", data, filePath);
|
|
9307
|
+
return;
|
|
9308
|
+
}
|
|
9309
|
+
writeLine5(stdout, `Deleted document template "${template.value}".`);
|
|
9310
|
+
});
|
|
9311
|
+
const assets = templates.command("assets").description("Manage document template assets");
|
|
9312
|
+
assets.command("add").description("Upload an asset file to a document template").argument("<template>", "template UUID or exact name", parseUuidOrSlugSelector4).argument("<path>", "path to the local file").option("--name <name>", "override the asset display name").action(async function action(template, localPath, commandOptions) {
|
|
9313
|
+
const { api, json, readOnly } = createDocumentTemplatesApi(this, filePath);
|
|
9314
|
+
ensureWritable4("document-templates assets add", readOnly, "write");
|
|
9315
|
+
const contents = readLocalFile(localPath);
|
|
9316
|
+
const formData = new FormData();
|
|
9317
|
+
formData.append("file", new Blob([contents]), basename(localPath));
|
|
9318
|
+
if (commandOptions.name !== void 0) {
|
|
9319
|
+
formData.append("name", commandOptions.name);
|
|
9320
|
+
}
|
|
9321
|
+
const resolved = await resolveTemplateSelector(api, template);
|
|
9322
|
+
const data = await api.addAsset(resolved, formData);
|
|
9323
|
+
if (json) {
|
|
9324
|
+
emitJson5(stdout, "document-templates assets add", data, filePath);
|
|
9325
|
+
return;
|
|
9326
|
+
}
|
|
9327
|
+
writeLine5(
|
|
9328
|
+
stdout,
|
|
9329
|
+
`Added asset "${commandOptions.name ?? basename(localPath)}" to template "${template.value}".`
|
|
9330
|
+
);
|
|
9331
|
+
});
|
|
9332
|
+
assets.command("delete").description("Delete one asset from a document template").argument("<template>", "template UUID or exact name", parseUuidOrSlugSelector4).argument("<asset>", "asset UUID").action(async function action(template, assetId) {
|
|
9333
|
+
const { api, json, readOnly } = createDocumentTemplatesApi(this, filePath);
|
|
9334
|
+
ensureWritable4("document-templates assets delete", readOnly, "destructive");
|
|
9335
|
+
const resolved = await resolveTemplateSelector(api, template);
|
|
9336
|
+
const data = await api.deleteAsset(resolved, assetId);
|
|
9337
|
+
if (json) {
|
|
9338
|
+
emitJson5(stdout, "document-templates assets delete", data, filePath);
|
|
9339
|
+
return;
|
|
9340
|
+
}
|
|
9341
|
+
writeLine5(stdout, `Deleted asset "${assetId}" from template "${template.value}".`);
|
|
9342
|
+
});
|
|
9343
|
+
assets.command("download").description("Download the raw bytes of a document template asset").argument("<template>", "template UUID or exact name", parseUuidOrSlugSelector4).argument("<asset>", "asset UUID").option("--output <path>", "write the downloaded bytes to a path").action(async function action(template, assetId, commandOptions) {
|
|
9344
|
+
const { api, json } = createDocumentTemplatesApi(this, filePath);
|
|
9345
|
+
if (json && !commandOptions.output) {
|
|
9346
|
+
throw new CliError(
|
|
9347
|
+
"invalid_cli_usage",
|
|
9348
|
+
'Provide "--output" when using "--json" with "document-templates assets download".'
|
|
9349
|
+
);
|
|
9350
|
+
}
|
|
9351
|
+
const resolved = await resolveTemplateSelector(api, template);
|
|
9352
|
+
const data = await api.downloadAsset(resolved, assetId);
|
|
9353
|
+
if (commandOptions.output) {
|
|
9354
|
+
writeDownloadedFile(commandOptions.output, data);
|
|
9355
|
+
if (json) {
|
|
9356
|
+
emitJson5(
|
|
9357
|
+
stdout,
|
|
9358
|
+
"document-templates assets download",
|
|
9359
|
+
{
|
|
9360
|
+
template: resolved.value,
|
|
9361
|
+
asset: assetId,
|
|
9362
|
+
output: commandOptions.output,
|
|
9363
|
+
bytes: data.byteLength
|
|
9364
|
+
},
|
|
9365
|
+
filePath
|
|
9366
|
+
);
|
|
9367
|
+
return;
|
|
9368
|
+
}
|
|
9369
|
+
writeLine5(stdout, `Downloaded asset to "${commandOptions.output}".`);
|
|
9370
|
+
return;
|
|
9371
|
+
}
|
|
9372
|
+
writeBinary(stdout, data);
|
|
9373
|
+
});
|
|
9374
|
+
}
|
|
9375
|
+
|
|
9376
|
+
// src/commands/files.ts
|
|
9377
|
+
import { readFileSync as readFileSync6, writeFileSync as writeFileSync3 } from "fs";
|
|
9378
|
+
import { basename as basename2 } from "path";
|
|
9379
|
+
import { InvalidArgumentError as InvalidArgumentError5 } from "commander";
|
|
9380
|
+
|
|
9381
|
+
// src/api/files.ts
|
|
9382
|
+
function selectorValue5(selector) {
|
|
9383
|
+
return selector.value;
|
|
9384
|
+
}
|
|
9385
|
+
var FilesApi = class {
|
|
9386
|
+
constructor(client) {
|
|
9387
|
+
this.client = client;
|
|
9388
|
+
}
|
|
9389
|
+
uploadFile(input) {
|
|
9390
|
+
return this.client.requestJson("/api/v2/files", {
|
|
9391
|
+
method: "POST",
|
|
9392
|
+
body: input
|
|
9393
|
+
});
|
|
9394
|
+
}
|
|
9395
|
+
downloadFile(file) {
|
|
9396
|
+
return this.client.requestBinary(`/api/v2/files/${selectorValue5(file)}`);
|
|
9397
|
+
}
|
|
9398
|
+
deleteFile(file) {
|
|
9399
|
+
return this.client.requestJson(
|
|
9400
|
+
`/api/v2/files/${selectorValue5(file)}`,
|
|
9401
|
+
{ method: "DELETE" }
|
|
9402
|
+
);
|
|
9403
|
+
}
|
|
9404
|
+
getStorageInfo() {
|
|
9405
|
+
return this.client.getJson("/api/v2/files/storage-info");
|
|
9406
|
+
}
|
|
9407
|
+
};
|
|
9408
|
+
|
|
9409
|
+
// src/commands/files.ts
|
|
9410
|
+
function getCommandIo6(stdout) {
|
|
9411
|
+
return stdout ?? process.stdout;
|
|
9412
|
+
}
|
|
9413
|
+
function writeLine6(stdout, value) {
|
|
9414
|
+
stdout.write(`${value}
|
|
9415
|
+
`);
|
|
9416
|
+
}
|
|
9417
|
+
function writeBinary2(stdout, value) {
|
|
9418
|
+
stdout.write(Buffer.from(value));
|
|
9419
|
+
}
|
|
9420
|
+
function getGlobalOptions6(command) {
|
|
9421
|
+
return command.optsWithGlobals();
|
|
9422
|
+
}
|
|
9423
|
+
function emitJson6(stdout, commandName, data, configPath, meta = {}) {
|
|
9424
|
+
writeLine6(
|
|
9425
|
+
stdout,
|
|
9426
|
+
JSON.stringify(buildJsonSuccess(data, { command: commandName, configPath, ...meta }))
|
|
9427
|
+
);
|
|
9428
|
+
}
|
|
9429
|
+
function toConfigurationError6(filePath, error) {
|
|
9430
|
+
if (error instanceof CliError) {
|
|
9431
|
+
throw error;
|
|
9432
|
+
}
|
|
9433
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") {
|
|
9434
|
+
throw new CliError("configuration_error", `Config file not found at ${filePath}.`);
|
|
9435
|
+
}
|
|
9436
|
+
if (error instanceof Error) {
|
|
9437
|
+
throw new CliError("configuration_error", error.message);
|
|
9438
|
+
}
|
|
9439
|
+
throw error;
|
|
9440
|
+
}
|
|
9441
|
+
function createFilesApi(command, filePath) {
|
|
9442
|
+
try {
|
|
9443
|
+
const config = readRuntimeConfig(filePath);
|
|
9444
|
+
const runtime = resolveRuntimeContext(config, getGlobalOptions6(command));
|
|
9445
|
+
if (!runtime.baseUrl) {
|
|
9446
|
+
throw new CliError(
|
|
9447
|
+
"configuration_error",
|
|
9448
|
+
`Resolved profile "${runtime.profile}" is missing a base URL.`
|
|
9449
|
+
);
|
|
9450
|
+
}
|
|
9451
|
+
return {
|
|
9452
|
+
api: new FilesApi(
|
|
9453
|
+
new ApiClient({
|
|
9454
|
+
baseUrl: runtime.baseUrl,
|
|
9455
|
+
apiKey: runtime.apiKey
|
|
9456
|
+
})
|
|
9457
|
+
),
|
|
9458
|
+
json: runtime.json,
|
|
9459
|
+
readOnly: runtime.readOnly
|
|
9460
|
+
};
|
|
9461
|
+
} catch (error) {
|
|
9462
|
+
toConfigurationError6(filePath, error);
|
|
9463
|
+
}
|
|
9464
|
+
}
|
|
9465
|
+
function ensureWritable5(commandName, readOnly, commandMode) {
|
|
9466
|
+
if (readOnly) {
|
|
9467
|
+
throw new CliError(
|
|
9468
|
+
"command_not_allowed_in_read_only_mode",
|
|
9469
|
+
`Command "${commandName}" is not allowed in read-only mode.`,
|
|
9470
|
+
{
|
|
9471
|
+
commandMode,
|
|
9472
|
+
executionMode: "read-only"
|
|
9473
|
+
}
|
|
9474
|
+
);
|
|
9475
|
+
}
|
|
9476
|
+
}
|
|
9477
|
+
function parseUuidOrSlugSelector5(input) {
|
|
9478
|
+
try {
|
|
9479
|
+
return normalizeUuidOrSlug(input);
|
|
9480
|
+
} catch (error) {
|
|
9481
|
+
const message = error instanceof Error ? error.message : "Invalid selector.";
|
|
9482
|
+
throw new InvalidArgumentError5(message);
|
|
9483
|
+
}
|
|
9484
|
+
}
|
|
9485
|
+
function isRecord3(value) {
|
|
9486
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9487
|
+
}
|
|
9488
|
+
function readLocalFile2(filePath) {
|
|
9489
|
+
try {
|
|
9490
|
+
return readFileSync6(filePath);
|
|
9491
|
+
} catch (error) {
|
|
9492
|
+
const message = error instanceof Error ? error.message : "Unable to read file.";
|
|
9493
|
+
throw new CliError("invalid_cli_usage", `Failed to read file at ${filePath}: ${message}`);
|
|
9494
|
+
}
|
|
9495
|
+
}
|
|
9496
|
+
function writeDownloadedFile2(outputPath, value) {
|
|
9497
|
+
try {
|
|
9498
|
+
writeFileSync3(outputPath, Buffer.from(value));
|
|
9499
|
+
} catch (error) {
|
|
9500
|
+
const message = error instanceof Error ? error.message : "Unable to write file.";
|
|
9501
|
+
throw new CliError(
|
|
9502
|
+
"invalid_cli_usage",
|
|
9503
|
+
`Failed to write downloaded file to ${outputPath}: ${message}`
|
|
9504
|
+
);
|
|
9505
|
+
}
|
|
9506
|
+
}
|
|
9507
|
+
function registerFilesCommands(program, options = {}) {
|
|
9508
|
+
const filePath = options.configPath ?? defaultConfigPath;
|
|
9509
|
+
const stdout = getCommandIo6(options.stdout);
|
|
9510
|
+
const files = program.command("files").description("Manage files and storage");
|
|
9511
|
+
files.command("upload").description("Upload a local file").argument("<path>", "path to the local file").action(function action(path) {
|
|
9512
|
+
const { api, json, readOnly } = createFilesApi(this, filePath);
|
|
9513
|
+
ensureWritable5("files upload", readOnly, "write");
|
|
9514
|
+
const contents = readLocalFile2(path);
|
|
9515
|
+
const formData = new FormData();
|
|
9516
|
+
formData.append("file", new Blob([contents]), basename2(path));
|
|
9517
|
+
return api.uploadFile(formData).then((data) => {
|
|
9518
|
+
if (json) {
|
|
9519
|
+
emitJson6(stdout, "files upload", data, filePath);
|
|
9520
|
+
return;
|
|
9521
|
+
}
|
|
9522
|
+
writeLine6(stdout, `Uploaded file "${basename2(path)}".`);
|
|
9523
|
+
});
|
|
9524
|
+
});
|
|
9525
|
+
files.command("download").description("Download a file").argument("<file>", "file identifier").option("--output <path>", "write the downloaded file to a path").action(function action(file, commandOptions) {
|
|
9526
|
+
const { api, json } = createFilesApi(this, filePath);
|
|
9527
|
+
if (json && !commandOptions.output) {
|
|
9528
|
+
throw new CliError(
|
|
9529
|
+
"invalid_cli_usage",
|
|
9530
|
+
'Provide "--output" when using "--json" with "files download".'
|
|
9531
|
+
);
|
|
8816
9532
|
}
|
|
8817
|
-
const fileSelector =
|
|
9533
|
+
const fileSelector = parseUuidOrSlugSelector5(file);
|
|
8818
9534
|
return api.downloadFile(fileSelector).then((data) => {
|
|
8819
9535
|
if (commandOptions.output) {
|
|
8820
|
-
|
|
9536
|
+
writeDownloadedFile2(commandOptions.output, data);
|
|
8821
9537
|
if (json) {
|
|
8822
|
-
|
|
9538
|
+
emitJson6(
|
|
8823
9539
|
stdout,
|
|
8824
9540
|
"files download",
|
|
8825
9541
|
{
|
|
@@ -8831,45 +9547,45 @@ function registerFilesCommands(program, options = {}) {
|
|
|
8831
9547
|
);
|
|
8832
9548
|
return;
|
|
8833
9549
|
}
|
|
8834
|
-
|
|
9550
|
+
writeLine6(stdout, `Downloaded file to "${commandOptions.output}".`);
|
|
8835
9551
|
return;
|
|
8836
9552
|
}
|
|
8837
|
-
|
|
9553
|
+
writeBinary2(stdout, data);
|
|
8838
9554
|
});
|
|
8839
9555
|
});
|
|
8840
9556
|
files.command("delete").description("Delete a file").argument("<file>", "file identifier").action(function action(file) {
|
|
8841
9557
|
const { api, json, readOnly } = createFilesApi(this, filePath);
|
|
8842
|
-
|
|
8843
|
-
const fileSelector =
|
|
9558
|
+
ensureWritable5("files delete", readOnly, "destructive");
|
|
9559
|
+
const fileSelector = parseUuidOrSlugSelector5(file);
|
|
8844
9560
|
return api.deleteFile(fileSelector).then((data) => {
|
|
8845
9561
|
if (json) {
|
|
8846
|
-
|
|
9562
|
+
emitJson6(stdout, "files delete", data, filePath);
|
|
8847
9563
|
return;
|
|
8848
9564
|
}
|
|
8849
|
-
|
|
9565
|
+
writeLine6(stdout, `Deleted file "${fileSelector.value}".`);
|
|
8850
9566
|
});
|
|
8851
9567
|
});
|
|
8852
9568
|
files.command("storage").description("Show storage usage information").action(function action() {
|
|
8853
9569
|
const { api, json } = createFilesApi(this, filePath);
|
|
8854
9570
|
return api.getStorageInfo().then((data) => {
|
|
8855
9571
|
if (json) {
|
|
8856
|
-
|
|
9572
|
+
emitJson6(stdout, "files storage", data, filePath);
|
|
8857
9573
|
return;
|
|
8858
9574
|
}
|
|
8859
9575
|
if (isRecord3(data)) {
|
|
8860
9576
|
printTable([data], Object.keys(data), stdout);
|
|
8861
9577
|
return;
|
|
8862
9578
|
}
|
|
8863
|
-
|
|
9579
|
+
writeLine6(stdout, String(data));
|
|
8864
9580
|
});
|
|
8865
9581
|
});
|
|
8866
9582
|
}
|
|
8867
9583
|
|
|
8868
9584
|
// src/commands/logs.ts
|
|
8869
|
-
import { InvalidArgumentError as
|
|
9585
|
+
import { InvalidArgumentError as InvalidArgumentError6 } from "commander";
|
|
8870
9586
|
|
|
8871
9587
|
// src/api/logs.ts
|
|
8872
|
-
function
|
|
9588
|
+
function selectorValue6(selector) {
|
|
8873
9589
|
return selector.value;
|
|
8874
9590
|
}
|
|
8875
9591
|
var LogsApi = class {
|
|
@@ -8878,29 +9594,29 @@ var LogsApi = class {
|
|
|
8878
9594
|
}
|
|
8879
9595
|
listLogs(schema, recordId) {
|
|
8880
9596
|
return this.client.getJson(
|
|
8881
|
-
`/api/v2/schemas/${
|
|
9597
|
+
`/api/v2/schemas/${selectorValue6(schema)}/records/${recordId}/logs`
|
|
8882
9598
|
);
|
|
8883
9599
|
}
|
|
8884
9600
|
};
|
|
8885
9601
|
|
|
8886
9602
|
// src/commands/logs.ts
|
|
8887
|
-
function
|
|
9603
|
+
function getCommandIo7(stdout) {
|
|
8888
9604
|
return stdout ?? process.stdout;
|
|
8889
9605
|
}
|
|
8890
|
-
function
|
|
9606
|
+
function writeLine7(stdout, value) {
|
|
8891
9607
|
stdout.write(`${value}
|
|
8892
9608
|
`);
|
|
8893
9609
|
}
|
|
8894
|
-
function
|
|
9610
|
+
function getGlobalOptions7(command) {
|
|
8895
9611
|
return command.optsWithGlobals();
|
|
8896
9612
|
}
|
|
8897
|
-
function
|
|
8898
|
-
|
|
9613
|
+
function emitJson7(stdout, commandName, data, ..._extra) {
|
|
9614
|
+
writeLine7(
|
|
8899
9615
|
stdout,
|
|
8900
9616
|
JSON.stringify(buildJsonSuccess(data, { command: commandName }))
|
|
8901
9617
|
);
|
|
8902
9618
|
}
|
|
8903
|
-
function
|
|
9619
|
+
function toConfigurationError7(filePath, error) {
|
|
8904
9620
|
if (error instanceof CliError) {
|
|
8905
9621
|
throw error;
|
|
8906
9622
|
}
|
|
@@ -8915,7 +9631,7 @@ function toConfigurationError6(filePath, error) {
|
|
|
8915
9631
|
function createLogsApi(command, filePath) {
|
|
8916
9632
|
try {
|
|
8917
9633
|
const config = readRuntimeConfig(filePath);
|
|
8918
|
-
const runtime = resolveRuntimeContext(config,
|
|
9634
|
+
const runtime = resolveRuntimeContext(config, getGlobalOptions7(command));
|
|
8919
9635
|
if (!runtime.baseUrl) {
|
|
8920
9636
|
throw new CliError(
|
|
8921
9637
|
"configuration_error",
|
|
@@ -8932,25 +9648,25 @@ function createLogsApi(command, filePath) {
|
|
|
8932
9648
|
json: runtime.json
|
|
8933
9649
|
};
|
|
8934
9650
|
} catch (error) {
|
|
8935
|
-
|
|
9651
|
+
toConfigurationError7(filePath, error);
|
|
8936
9652
|
}
|
|
8937
9653
|
}
|
|
8938
|
-
function
|
|
9654
|
+
function parseUuidOrSlugSelector6(input) {
|
|
8939
9655
|
try {
|
|
8940
9656
|
return normalizeUuidOrSlug(input);
|
|
8941
9657
|
} catch (error) {
|
|
8942
9658
|
const message = error instanceof Error ? error.message : "Invalid selector.";
|
|
8943
|
-
throw new
|
|
9659
|
+
throw new InvalidArgumentError6(message);
|
|
8944
9660
|
}
|
|
8945
9661
|
}
|
|
8946
|
-
function
|
|
9662
|
+
function isJsonObject5(value) {
|
|
8947
9663
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8948
9664
|
}
|
|
8949
9665
|
function toTableRows3(data) {
|
|
8950
9666
|
if (Array.isArray(data)) {
|
|
8951
|
-
return data.map((entry) =>
|
|
9667
|
+
return data.map((entry) => isJsonObject5(entry) ? entry : { value: entry });
|
|
8952
9668
|
}
|
|
8953
|
-
if (
|
|
9669
|
+
if (isJsonObject5(data)) {
|
|
8954
9670
|
return [data];
|
|
8955
9671
|
}
|
|
8956
9672
|
return [{ value: data }];
|
|
@@ -8960,13 +9676,13 @@ function emitTable3(stdout, data) {
|
|
|
8960
9676
|
}
|
|
8961
9677
|
function registerLogsCommands(program, options = {}) {
|
|
8962
9678
|
const filePath = options.configPath ?? defaultConfigPath;
|
|
8963
|
-
const stdout =
|
|
9679
|
+
const stdout = getCommandIo7(options.stdout);
|
|
8964
9680
|
const logs = program.command("logs").description("Inspect record change logs");
|
|
8965
|
-
logs.command("list").description("List change logs for a record").argument("<schema>", "schema uuid or slug",
|
|
9681
|
+
logs.command("list").description("List change logs for a record").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector6).argument("<record>", "record uuid or slug", parseUuidOrSlugSelector6).action(async function action(schema, record) {
|
|
8966
9682
|
const { api, json } = createLogsApi(this, filePath);
|
|
8967
9683
|
const data = await api.listLogs(schema, record.value);
|
|
8968
9684
|
if (json) {
|
|
8969
|
-
|
|
9685
|
+
emitJson7(stdout, "logs list", data, filePath);
|
|
8970
9686
|
return;
|
|
8971
9687
|
}
|
|
8972
9688
|
emitTable3(stdout, data);
|
|
@@ -8974,11 +9690,11 @@ function registerLogsCommands(program, options = {}) {
|
|
|
8974
9690
|
}
|
|
8975
9691
|
|
|
8976
9692
|
// src/commands/navigation.ts
|
|
8977
|
-
import { readFileSync as
|
|
8978
|
-
import { InvalidArgumentError as
|
|
9693
|
+
import { readFileSync as readFileSync7 } from "fs";
|
|
9694
|
+
import { InvalidArgumentError as InvalidArgumentError7 } from "commander";
|
|
8979
9695
|
|
|
8980
9696
|
// src/api/navigation.ts
|
|
8981
|
-
function
|
|
9697
|
+
function jsonOptions5(body, method) {
|
|
8982
9698
|
return {
|
|
8983
9699
|
method,
|
|
8984
9700
|
headers: {
|
|
@@ -8987,7 +9703,7 @@ function jsonOptions4(body, method) {
|
|
|
8987
9703
|
body: JSON.stringify(body)
|
|
8988
9704
|
};
|
|
8989
9705
|
}
|
|
8990
|
-
function
|
|
9706
|
+
function selectorValue7(selector) {
|
|
8991
9707
|
return selector.value;
|
|
8992
9708
|
}
|
|
8993
9709
|
var NavigationApi = class {
|
|
@@ -9000,44 +9716,44 @@ var NavigationApi = class {
|
|
|
9000
9716
|
createFolder(body) {
|
|
9001
9717
|
return this.client.requestJson(
|
|
9002
9718
|
"/api/v2/navigation/folders",
|
|
9003
|
-
|
|
9719
|
+
jsonOptions5(body, "POST")
|
|
9004
9720
|
);
|
|
9005
9721
|
}
|
|
9006
9722
|
updateFolder(folder, body) {
|
|
9007
9723
|
return this.client.requestJson(
|
|
9008
|
-
`/api/v2/navigation/folders/${
|
|
9009
|
-
|
|
9724
|
+
`/api/v2/navigation/folders/${selectorValue7(folder)}`,
|
|
9725
|
+
jsonOptions5(body, "PATCH")
|
|
9010
9726
|
);
|
|
9011
9727
|
}
|
|
9012
9728
|
deleteFolder(folder) {
|
|
9013
9729
|
return this.client.requestJson(
|
|
9014
|
-
`/api/v2/navigation/folders/${
|
|
9730
|
+
`/api/v2/navigation/folders/${selectorValue7(folder)}`,
|
|
9015
9731
|
{ method: "DELETE" }
|
|
9016
9732
|
);
|
|
9017
9733
|
}
|
|
9018
9734
|
moveResource(body) {
|
|
9019
9735
|
return this.client.requestJson(
|
|
9020
9736
|
"/api/v2/navigation/resources:move",
|
|
9021
|
-
|
|
9737
|
+
jsonOptions5(body, "POST")
|
|
9022
9738
|
);
|
|
9023
9739
|
}
|
|
9024
9740
|
};
|
|
9025
9741
|
|
|
9026
9742
|
// src/commands/navigation.ts
|
|
9027
|
-
function
|
|
9743
|
+
function getCommandIo8(stdout) {
|
|
9028
9744
|
return stdout ?? process.stdout;
|
|
9029
9745
|
}
|
|
9030
|
-
function
|
|
9746
|
+
function writeLine8(stdout, value) {
|
|
9031
9747
|
stdout.write(`${value}
|
|
9032
9748
|
`);
|
|
9033
9749
|
}
|
|
9034
|
-
function
|
|
9750
|
+
function getGlobalOptions8(command) {
|
|
9035
9751
|
return command.optsWithGlobals();
|
|
9036
9752
|
}
|
|
9037
|
-
function
|
|
9038
|
-
|
|
9753
|
+
function emitJson8(stdout, commandName, data, configPath) {
|
|
9754
|
+
writeLine8(stdout, JSON.stringify(buildJsonSuccess(data, { command: commandName, configPath })));
|
|
9039
9755
|
}
|
|
9040
|
-
function
|
|
9756
|
+
function toConfigurationError8(filePath, error) {
|
|
9041
9757
|
if (error instanceof CliError) {
|
|
9042
9758
|
throw error;
|
|
9043
9759
|
}
|
|
@@ -9052,7 +9768,7 @@ function toConfigurationError7(filePath, error) {
|
|
|
9052
9768
|
function createNavigationApi(command, filePath) {
|
|
9053
9769
|
try {
|
|
9054
9770
|
const config = readRuntimeConfig(filePath);
|
|
9055
|
-
const runtime = resolveRuntimeContext(config,
|
|
9771
|
+
const runtime = resolveRuntimeContext(config, getGlobalOptions8(command));
|
|
9056
9772
|
if (!runtime.baseUrl) {
|
|
9057
9773
|
throw new CliError("configuration_error", `Resolved profile "${runtime.profile}" is missing a base URL.`);
|
|
9058
9774
|
}
|
|
@@ -9067,10 +9783,10 @@ function createNavigationApi(command, filePath) {
|
|
|
9067
9783
|
readOnly: runtime.readOnly
|
|
9068
9784
|
};
|
|
9069
9785
|
} catch (error) {
|
|
9070
|
-
|
|
9786
|
+
toConfigurationError8(filePath, error);
|
|
9071
9787
|
}
|
|
9072
9788
|
}
|
|
9073
|
-
function
|
|
9789
|
+
function ensureWritable6(commandName, readOnly, mode) {
|
|
9074
9790
|
if (readOnly) {
|
|
9075
9791
|
throw new CliError(
|
|
9076
9792
|
"command_not_allowed_in_read_only_mode",
|
|
@@ -9079,12 +9795,12 @@ function ensureWritable5(commandName, readOnly, mode) {
|
|
|
9079
9795
|
);
|
|
9080
9796
|
}
|
|
9081
9797
|
}
|
|
9082
|
-
function
|
|
9798
|
+
function parseUuidOrSlugSelector7(input) {
|
|
9083
9799
|
try {
|
|
9084
9800
|
return normalizeUuidOrSlug(input);
|
|
9085
9801
|
} catch (error) {
|
|
9086
9802
|
const message = error instanceof Error ? error.message : "Invalid selector.";
|
|
9087
|
-
throw new
|
|
9803
|
+
throw new InvalidArgumentError7(message);
|
|
9088
9804
|
}
|
|
9089
9805
|
}
|
|
9090
9806
|
function parseInteger(value, flagName) {
|
|
@@ -9101,7 +9817,7 @@ function readJsonObject(raw, rawFile) {
|
|
|
9101
9817
|
if (raw && rawFile) {
|
|
9102
9818
|
throw new CliError("invalid_cli_usage", 'Use either "--props" or "--props-file", not both.');
|
|
9103
9819
|
}
|
|
9104
|
-
const source = rawFile ?
|
|
9820
|
+
const source = rawFile ? readFileSync7(rawFile, "utf8") : raw;
|
|
9105
9821
|
if (!source) {
|
|
9106
9822
|
return {};
|
|
9107
9823
|
}
|
|
@@ -9163,41 +9879,41 @@ function folderRows2(folders) {
|
|
|
9163
9879
|
}
|
|
9164
9880
|
function registerNavigationCommands(program, options = {}) {
|
|
9165
9881
|
const filePath = options.configPath ?? defaultConfigPath;
|
|
9166
|
-
const stdout =
|
|
9882
|
+
const stdout = getCommandIo8(options.stdout);
|
|
9167
9883
|
const navigation = program.command("navigation").description("Manage workspace navigation");
|
|
9168
9884
|
const folders = navigation.command("folders").description("Manage navigation folders");
|
|
9169
9885
|
folders.command("list").description("List navigation folders").action(async function action() {
|
|
9170
9886
|
const { api, json } = createNavigationApi(this, filePath);
|
|
9171
9887
|
const data = await api.listFolders();
|
|
9172
9888
|
if (json) {
|
|
9173
|
-
|
|
9889
|
+
emitJson8(stdout, "navigation folders list", data, filePath);
|
|
9174
9890
|
return;
|
|
9175
9891
|
}
|
|
9176
9892
|
printTable(folderRows2(data), ["id", "order", "name", "resourceCount"], stdout);
|
|
9177
9893
|
});
|
|
9178
|
-
folders.command("get").description("Get a navigation folder by UUID or exact name").argument("<folder>", "folder UUID or exact name",
|
|
9894
|
+
folders.command("get").description("Get a navigation folder by UUID or exact name").argument("<folder>", "folder UUID or exact name", parseUuidOrSlugSelector7).action(async function action(folder) {
|
|
9179
9895
|
const { api, json } = createNavigationApi(this, filePath);
|
|
9180
9896
|
const data = await api.listFolders();
|
|
9181
9897
|
const resolved = resolveFolder2(data, folder);
|
|
9182
9898
|
if (json) {
|
|
9183
|
-
|
|
9899
|
+
emitJson8(stdout, "navigation folders get", resolved, filePath);
|
|
9184
9900
|
return;
|
|
9185
9901
|
}
|
|
9186
9902
|
printTable(folderRows2([resolved]), ["id", "order", "name", "resourceCount"], stdout);
|
|
9187
9903
|
});
|
|
9188
9904
|
folders.command("create").description("Create a navigation folder").requiredOption("--name <name>", "folder name").option("--order <n>", "folder order").option("--props <json>", "folder additionalProperties JSON").option("--props-file <path>", "folder additionalProperties JSON file").action(async function action(commandOptions) {
|
|
9189
9905
|
const { api, json, readOnly } = createNavigationApi(this, filePath);
|
|
9190
|
-
|
|
9906
|
+
ensureWritable6("navigation folders create", readOnly, "write");
|
|
9191
9907
|
const data = await api.createFolder(buildFolderBody(commandOptions));
|
|
9192
9908
|
if (json) {
|
|
9193
|
-
|
|
9909
|
+
emitJson8(stdout, "navigation folders create", data, filePath);
|
|
9194
9910
|
return;
|
|
9195
9911
|
}
|
|
9196
|
-
|
|
9912
|
+
writeLine8(stdout, `Created navigation folder "${String(data.name ?? commandOptions.name)}".`);
|
|
9197
9913
|
});
|
|
9198
|
-
folders.command("update").description("Update a navigation folder").argument("<folder>", "folder UUID or exact name",
|
|
9914
|
+
folders.command("update").description("Update a navigation folder").argument("<folder>", "folder UUID or exact name", parseUuidOrSlugSelector7).option("--name <name>", "folder name").option("--order <n>", "folder order").option("--props <json>", "folder additionalProperties JSON").option("--props-file <path>", "folder additionalProperties JSON file").action(async function action(folder, commandOptions) {
|
|
9199
9915
|
const { api, json, readOnly } = createNavigationApi(this, filePath);
|
|
9200
|
-
|
|
9916
|
+
ensureWritable6("navigation folders update", readOnly, "write");
|
|
9201
9917
|
const allFolders = await api.listFolders();
|
|
9202
9918
|
const resolved = resolveFolder2(allFolders, folder);
|
|
9203
9919
|
const body = buildFolderBody(commandOptions);
|
|
@@ -9206,54 +9922,54 @@ function registerNavigationCommands(program, options = {}) {
|
|
|
9206
9922
|
}
|
|
9207
9923
|
const data = await api.updateFolder({ kind: "uuid", value: resolved.id }, body);
|
|
9208
9924
|
if (json) {
|
|
9209
|
-
|
|
9925
|
+
emitJson8(stdout, "navigation folders update", data, filePath);
|
|
9210
9926
|
return;
|
|
9211
9927
|
}
|
|
9212
|
-
|
|
9928
|
+
writeLine8(stdout, `Updated navigation folder "${String(data.name ?? resolved.name ?? resolved.id)}".`);
|
|
9213
9929
|
});
|
|
9214
|
-
folders.command("delete").description("Delete a navigation folder").argument("<folder>", "folder UUID or exact name",
|
|
9930
|
+
folders.command("delete").description("Delete a navigation folder").argument("<folder>", "folder UUID or exact name", parseUuidOrSlugSelector7).action(async function action(folder) {
|
|
9215
9931
|
const { api, json, readOnly } = createNavigationApi(this, filePath);
|
|
9216
|
-
|
|
9932
|
+
ensureWritable6("navigation folders delete", readOnly, "destructive");
|
|
9217
9933
|
const allFolders = await api.listFolders();
|
|
9218
9934
|
const resolved = resolveFolder2(allFolders, folder);
|
|
9219
9935
|
const data = await api.deleteFolder({ kind: "uuid", value: resolved.id });
|
|
9220
9936
|
if (json) {
|
|
9221
|
-
|
|
9937
|
+
emitJson8(stdout, "navigation folders delete", data, filePath);
|
|
9222
9938
|
return;
|
|
9223
9939
|
}
|
|
9224
|
-
|
|
9940
|
+
writeLine8(stdout, `Deleted navigation folder "${resolved.name ?? resolved.id}".`);
|
|
9225
9941
|
});
|
|
9226
9942
|
navigation.command("resources").description("Manage navigation resources").command("move").description("Move a resource into a folder").argument("<resource>", "resource UUID").requiredOption("--type <type>", "resource type").requiredOption("--to <folder>", "target folder UUID or exact name").action(async function action(resourceId, commandOptions) {
|
|
9227
9943
|
const { api, json, readOnly } = createNavigationApi(this, filePath);
|
|
9228
|
-
|
|
9944
|
+
ensureWritable6("navigation resources move", readOnly, "write");
|
|
9229
9945
|
const allFolders = await api.listFolders();
|
|
9230
|
-
const resolved = resolveFolder2(allFolders,
|
|
9946
|
+
const resolved = resolveFolder2(allFolders, parseUuidOrSlugSelector7(commandOptions.to));
|
|
9231
9947
|
const data = await api.moveResource({
|
|
9232
9948
|
resourceId,
|
|
9233
9949
|
resourceType: commandOptions.type.toUpperCase(),
|
|
9234
9950
|
targetFolderId: resolved.id
|
|
9235
9951
|
});
|
|
9236
9952
|
if (json) {
|
|
9237
|
-
|
|
9953
|
+
emitJson8(stdout, "navigation resources move", data, filePath);
|
|
9238
9954
|
return;
|
|
9239
9955
|
}
|
|
9240
|
-
|
|
9956
|
+
writeLine8(stdout, `Moved resource "${resourceId}" to "${resolved.name ?? resolved.id}".`);
|
|
9241
9957
|
});
|
|
9242
9958
|
}
|
|
9243
9959
|
|
|
9244
9960
|
// src/commands/profiles.ts
|
|
9245
|
-
function
|
|
9961
|
+
function getCommandIo9(stdout) {
|
|
9246
9962
|
return stdout ?? process.stdout;
|
|
9247
9963
|
}
|
|
9248
|
-
function
|
|
9964
|
+
function writeLine9(stdout, value) {
|
|
9249
9965
|
stdout.write(`${value}
|
|
9250
9966
|
`);
|
|
9251
9967
|
}
|
|
9252
|
-
function
|
|
9968
|
+
function getGlobalOptions9(command) {
|
|
9253
9969
|
return command.optsWithGlobals();
|
|
9254
9970
|
}
|
|
9255
|
-
function
|
|
9256
|
-
|
|
9971
|
+
function emitJson9(stdout, commandName, data, configPath) {
|
|
9972
|
+
writeLine9(
|
|
9257
9973
|
stdout,
|
|
9258
9974
|
JSON.stringify(buildJsonSuccess(data, { command: commandName, configPath }))
|
|
9259
9975
|
);
|
|
@@ -9309,15 +10025,15 @@ function emitProfilesTable(stdout, data) {
|
|
|
9309
10025
|
}
|
|
9310
10026
|
function registerProfilesCommands(program, options = {}) {
|
|
9311
10027
|
const filePath = options.configPath ?? defaultConfigPath;
|
|
9312
|
-
const stdout =
|
|
10028
|
+
const stdout = getCommandIo9(options.stdout);
|
|
9313
10029
|
const profiles = program.command("profiles").description("Manage local CLI profiles");
|
|
9314
10030
|
profiles.command("list").description("List configured profiles").action(function action() {
|
|
9315
10031
|
const config = readRequiredConfig(filePath);
|
|
9316
10032
|
const data = Object.entries(config.profiles).map(
|
|
9317
10033
|
([name, profile]) => toDisplayProfile(name, profile, config.defaultProfile)
|
|
9318
10034
|
);
|
|
9319
|
-
if (
|
|
9320
|
-
|
|
10035
|
+
if (getGlobalOptions9(this).json) {
|
|
10036
|
+
emitJson9(stdout, "profiles list", data, filePath);
|
|
9321
10037
|
return;
|
|
9322
10038
|
}
|
|
9323
10039
|
emitProfilesTable(stdout, data);
|
|
@@ -9326,8 +10042,8 @@ function registerProfilesCommands(program, options = {}) {
|
|
|
9326
10042
|
const config = readRequiredConfig(filePath);
|
|
9327
10043
|
const profile = getRequiredProfile(config, profileName);
|
|
9328
10044
|
const data = toDisplayProfile(profileName, profile, config.defaultProfile);
|
|
9329
|
-
if (
|
|
9330
|
-
|
|
10045
|
+
if (getGlobalOptions9(this).json) {
|
|
10046
|
+
emitJson9(stdout, "profiles get", data, filePath);
|
|
9331
10047
|
return;
|
|
9332
10048
|
}
|
|
9333
10049
|
emitProfilesTable(stdout, [data]);
|
|
@@ -9341,11 +10057,11 @@ function registerProfilesCommands(program, options = {}) {
|
|
|
9341
10057
|
profile: profileName,
|
|
9342
10058
|
defaultProfile: nextConfig.defaultProfile
|
|
9343
10059
|
};
|
|
9344
|
-
if (
|
|
9345
|
-
|
|
10060
|
+
if (getGlobalOptions9(this).json) {
|
|
10061
|
+
emitJson9(stdout, "profiles use", data, filePath);
|
|
9346
10062
|
return;
|
|
9347
10063
|
}
|
|
9348
|
-
|
|
10064
|
+
writeLine9(stdout, `Using profile "${profileName}".`);
|
|
9349
10065
|
});
|
|
9350
10066
|
profiles.command("add").description("Add a profile to the local config").argument("<profile>", "profile name").requiredOption("--api-key <token>", "API key").option("--base-url <url>", "base URL").action(function action(profileName, commandOptions) {
|
|
9351
10067
|
const config = loadConfigForAdd(filePath);
|
|
@@ -9369,11 +10085,11 @@ function registerProfilesCommands(program, options = {}) {
|
|
|
9369
10085
|
nextConfig.profiles[profileName] ?? {},
|
|
9370
10086
|
nextConfig.defaultProfile
|
|
9371
10087
|
);
|
|
9372
|
-
if (
|
|
9373
|
-
|
|
10088
|
+
if (getGlobalOptions9(this).json) {
|
|
10089
|
+
emitJson9(stdout, "profiles add", data, filePath);
|
|
9374
10090
|
return;
|
|
9375
10091
|
}
|
|
9376
|
-
|
|
10092
|
+
writeLine9(stdout, `Added profile "${profileName}".`);
|
|
9377
10093
|
});
|
|
9378
10094
|
profiles.command("update").description("Update an existing profile").argument("<profile>", "profile name").option("--api-key <token>", "API key").option("--base-url <url>", "base URL").action(function action(profileName, commandOptions) {
|
|
9379
10095
|
if (commandOptions.apiKey === void 0 && commandOptions.baseUrl === void 0) {
|
|
@@ -9395,11 +10111,11 @@ function registerProfilesCommands(program, options = {}) {
|
|
|
9395
10111
|
nextConfig.profiles[profileName] ?? {},
|
|
9396
10112
|
nextConfig.defaultProfile
|
|
9397
10113
|
);
|
|
9398
|
-
if (
|
|
9399
|
-
|
|
10114
|
+
if (getGlobalOptions9(this).json) {
|
|
10115
|
+
emitJson9(stdout, "profiles update", data, filePath);
|
|
9400
10116
|
return;
|
|
9401
10117
|
}
|
|
9402
|
-
|
|
10118
|
+
writeLine9(stdout, `Updated profile "${profileName}".`);
|
|
9403
10119
|
});
|
|
9404
10120
|
profiles.command("remove").description("Remove a profile from the local config").argument("<profile>", "profile name").action(function action(profileName) {
|
|
9405
10121
|
const config = readRequiredConfig(filePath);
|
|
@@ -9410,20 +10126,20 @@ function registerProfilesCommands(program, options = {}) {
|
|
|
9410
10126
|
profile: profileName,
|
|
9411
10127
|
defaultProfile: nextConfig.defaultProfile
|
|
9412
10128
|
};
|
|
9413
|
-
if (
|
|
9414
|
-
|
|
10129
|
+
if (getGlobalOptions9(this).json) {
|
|
10130
|
+
emitJson9(stdout, "profiles remove", data, filePath);
|
|
9415
10131
|
return;
|
|
9416
10132
|
}
|
|
9417
|
-
|
|
10133
|
+
writeLine9(stdout, `Removed profile "${profileName}".`);
|
|
9418
10134
|
});
|
|
9419
10135
|
}
|
|
9420
10136
|
|
|
9421
10137
|
// src/commands/records.ts
|
|
9422
|
-
import { readFileSync as
|
|
9423
|
-
import { InvalidArgumentError as
|
|
10138
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
10139
|
+
import { InvalidArgumentError as InvalidArgumentError8 } from "commander";
|
|
9424
10140
|
|
|
9425
10141
|
// src/api/records.ts
|
|
9426
|
-
function
|
|
10142
|
+
function jsonOptions6(body, method) {
|
|
9427
10143
|
return {
|
|
9428
10144
|
method,
|
|
9429
10145
|
headers: {
|
|
@@ -9432,7 +10148,7 @@ function jsonOptions5(body, method) {
|
|
|
9432
10148
|
body: JSON.stringify(body)
|
|
9433
10149
|
};
|
|
9434
10150
|
}
|
|
9435
|
-
function
|
|
10151
|
+
function selectorValue8(selector) {
|
|
9436
10152
|
return selector.value;
|
|
9437
10153
|
}
|
|
9438
10154
|
var RecordsApi = class {
|
|
@@ -9447,7 +10163,7 @@ var RecordsApi = class {
|
|
|
9447
10163
|
if (query.offset !== void 0) {
|
|
9448
10164
|
params.set("offset", String(query.offset));
|
|
9449
10165
|
}
|
|
9450
|
-
const path = `/api/v2/schemas/${
|
|
10166
|
+
const path = `/api/v2/schemas/${selectorValue8(schema)}/records`;
|
|
9451
10167
|
const queryString = params.toString();
|
|
9452
10168
|
return this.client.getJson(
|
|
9453
10169
|
queryString ? `${path}?${queryString}` : path
|
|
@@ -9456,36 +10172,36 @@ var RecordsApi = class {
|
|
|
9456
10172
|
queryRecords(schema, query) {
|
|
9457
10173
|
const body = this.normalizeQueryInput(query);
|
|
9458
10174
|
return this.client.requestJson(
|
|
9459
|
-
`/api/v2/schemas/${
|
|
9460
|
-
|
|
10175
|
+
`/api/v2/schemas/${selectorValue8(schema)}/records:query`,
|
|
10176
|
+
jsonOptions6(body, "POST")
|
|
9461
10177
|
);
|
|
9462
10178
|
}
|
|
9463
10179
|
getRecord(schema, record) {
|
|
9464
10180
|
return this.client.getJson(
|
|
9465
|
-
`/api/v2/schemas/${
|
|
10181
|
+
`/api/v2/schemas/${selectorValue8(schema)}/records/${selectorValue8(record)}`
|
|
9466
10182
|
);
|
|
9467
10183
|
}
|
|
9468
10184
|
createRecord(schema, input) {
|
|
9469
10185
|
return this.client.requestJson(
|
|
9470
|
-
`/api/v2/schemas/${
|
|
9471
|
-
|
|
10186
|
+
`/api/v2/schemas/${selectorValue8(schema)}/records`,
|
|
10187
|
+
jsonOptions6(input, "POST")
|
|
9472
10188
|
);
|
|
9473
10189
|
}
|
|
9474
10190
|
updateRecord(schema, record, input) {
|
|
9475
10191
|
return this.client.requestJson(
|
|
9476
|
-
`/api/v2/schemas/${
|
|
9477
|
-
|
|
10192
|
+
`/api/v2/schemas/${selectorValue8(schema)}/records/${selectorValue8(record)}`,
|
|
10193
|
+
jsonOptions6(input, "PATCH")
|
|
9478
10194
|
);
|
|
9479
10195
|
}
|
|
9480
10196
|
deleteRecord(schema, record) {
|
|
9481
10197
|
return this.client.requestJson(
|
|
9482
|
-
`/api/v2/schemas/${
|
|
10198
|
+
`/api/v2/schemas/${selectorValue8(schema)}/records/${selectorValue8(record)}`,
|
|
9483
10199
|
{ method: "DELETE" }
|
|
9484
10200
|
);
|
|
9485
10201
|
}
|
|
9486
10202
|
clearRecords(schema) {
|
|
9487
10203
|
return this.client.requestJson(
|
|
9488
|
-
`/api/v2/schemas/${
|
|
10204
|
+
`/api/v2/schemas/${selectorValue8(schema)}/records:clear`,
|
|
9489
10205
|
{ method: "DELETE" }
|
|
9490
10206
|
);
|
|
9491
10207
|
}
|
|
@@ -9518,7 +10234,7 @@ var RecordsApi = class {
|
|
|
9518
10234
|
};
|
|
9519
10235
|
|
|
9520
10236
|
// src/api/schemas.ts
|
|
9521
|
-
function
|
|
10237
|
+
function jsonOptions7(body, method) {
|
|
9522
10238
|
return {
|
|
9523
10239
|
method,
|
|
9524
10240
|
headers: {
|
|
@@ -9527,7 +10243,7 @@ function jsonOptions6(body, method) {
|
|
|
9527
10243
|
body: JSON.stringify(body)
|
|
9528
10244
|
};
|
|
9529
10245
|
}
|
|
9530
|
-
function
|
|
10246
|
+
function selectorValue9(selector) {
|
|
9531
10247
|
return selector.value;
|
|
9532
10248
|
}
|
|
9533
10249
|
var SchemasApi = class {
|
|
@@ -9538,20 +10254,20 @@ var SchemasApi = class {
|
|
|
9538
10254
|
return this.client.getJson("/api/v2/schemas");
|
|
9539
10255
|
}
|
|
9540
10256
|
getSchema(schema) {
|
|
9541
|
-
return this.client.getJson(`/api/v2/schemas/${
|
|
10257
|
+
return this.client.getJson(`/api/v2/schemas/${selectorValue9(schema)}`);
|
|
9542
10258
|
}
|
|
9543
10259
|
createSchema(input) {
|
|
9544
|
-
return this.client.requestJson("/api/v2/schemas",
|
|
10260
|
+
return this.client.requestJson("/api/v2/schemas", jsonOptions7(input, "POST"));
|
|
9545
10261
|
}
|
|
9546
10262
|
updateSchema(schema, input) {
|
|
9547
10263
|
return this.client.requestJson(
|
|
9548
|
-
`/api/v2/schemas/${
|
|
9549
|
-
|
|
10264
|
+
`/api/v2/schemas/${selectorValue9(schema)}`,
|
|
10265
|
+
jsonOptions7(input, "PATCH")
|
|
9550
10266
|
);
|
|
9551
10267
|
}
|
|
9552
10268
|
deleteSchema(schema) {
|
|
9553
10269
|
return this.client.requestJson(
|
|
9554
|
-
`/api/v2/schemas/${
|
|
10270
|
+
`/api/v2/schemas/${selectorValue9(schema)}`,
|
|
9555
10271
|
{ method: "DELETE" }
|
|
9556
10272
|
);
|
|
9557
10273
|
}
|
|
@@ -9561,47 +10277,47 @@ var SchemasApi = class {
|
|
|
9561
10277
|
}
|
|
9562
10278
|
getField(schema, field) {
|
|
9563
10279
|
return this.client.getJson(
|
|
9564
|
-
`/api/v2/schemas/${
|
|
10280
|
+
`/api/v2/schemas/${selectorValue9(schema)}/fields/${selectorValue9(field)}`
|
|
9565
10281
|
);
|
|
9566
10282
|
}
|
|
9567
10283
|
createField(schema, input) {
|
|
9568
10284
|
return this.client.requestJson(
|
|
9569
|
-
`/api/v2/schemas/${
|
|
9570
|
-
|
|
10285
|
+
`/api/v2/schemas/${selectorValue9(schema)}/fields`,
|
|
10286
|
+
jsonOptions7(input, "POST")
|
|
9571
10287
|
);
|
|
9572
10288
|
}
|
|
9573
10289
|
updateField(schema, field, input) {
|
|
9574
10290
|
return this.client.requestJson(
|
|
9575
|
-
`/api/v2/schemas/${
|
|
9576
|
-
|
|
10291
|
+
`/api/v2/schemas/${selectorValue9(schema)}/fields/${selectorValue9(field)}`,
|
|
10292
|
+
jsonOptions7(input, "PATCH")
|
|
9577
10293
|
);
|
|
9578
10294
|
}
|
|
9579
10295
|
deleteField(schema, field) {
|
|
9580
10296
|
return this.client.requestJson(
|
|
9581
|
-
`/api/v2/schemas/${
|
|
10297
|
+
`/api/v2/schemas/${selectorValue9(schema)}/fields/${selectorValue9(field)}`,
|
|
9582
10298
|
{ method: "DELETE" }
|
|
9583
10299
|
);
|
|
9584
10300
|
}
|
|
9585
10301
|
};
|
|
9586
10302
|
|
|
9587
10303
|
// src/commands/records.ts
|
|
9588
|
-
function
|
|
10304
|
+
function getCommandIo10(stdout) {
|
|
9589
10305
|
return stdout ?? process.stdout;
|
|
9590
10306
|
}
|
|
9591
|
-
function
|
|
10307
|
+
function writeLine10(stdout, value) {
|
|
9592
10308
|
stdout.write(`${value}
|
|
9593
10309
|
`);
|
|
9594
10310
|
}
|
|
9595
|
-
function
|
|
10311
|
+
function getGlobalOptions10(command) {
|
|
9596
10312
|
return command.optsWithGlobals();
|
|
9597
10313
|
}
|
|
9598
|
-
function
|
|
9599
|
-
|
|
10314
|
+
function emitJson10(stdout, commandName, data, configPath, meta = {}) {
|
|
10315
|
+
writeLine10(
|
|
9600
10316
|
stdout,
|
|
9601
10317
|
JSON.stringify(buildJsonSuccess(data, { command: commandName, configPath, ...meta }))
|
|
9602
10318
|
);
|
|
9603
10319
|
}
|
|
9604
|
-
function
|
|
10320
|
+
function toConfigurationError9(filePath, error) {
|
|
9605
10321
|
if (error instanceof CliError) {
|
|
9606
10322
|
throw error;
|
|
9607
10323
|
}
|
|
@@ -9616,7 +10332,7 @@ function toConfigurationError8(filePath, error) {
|
|
|
9616
10332
|
function createRecordsApi(command, filePath) {
|
|
9617
10333
|
try {
|
|
9618
10334
|
const config = readRuntimeConfig(filePath);
|
|
9619
|
-
const runtime = resolveRuntimeContext(config,
|
|
10335
|
+
const runtime = resolveRuntimeContext(config, getGlobalOptions10(command));
|
|
9620
10336
|
if (!runtime.baseUrl) {
|
|
9621
10337
|
throw new CliError(
|
|
9622
10338
|
"configuration_error",
|
|
@@ -9635,10 +10351,10 @@ function createRecordsApi(command, filePath) {
|
|
|
9635
10351
|
readOnly: runtime.readOnly
|
|
9636
10352
|
};
|
|
9637
10353
|
} catch (error) {
|
|
9638
|
-
|
|
10354
|
+
toConfigurationError9(filePath, error);
|
|
9639
10355
|
}
|
|
9640
10356
|
}
|
|
9641
|
-
function
|
|
10357
|
+
function ensureWritable7(commandName, readOnly, commandMode) {
|
|
9642
10358
|
if (readOnly) {
|
|
9643
10359
|
throw new CliError(
|
|
9644
10360
|
"command_not_allowed_in_read_only_mode",
|
|
@@ -9650,24 +10366,24 @@ function ensureWritable6(commandName, readOnly, commandMode) {
|
|
|
9650
10366
|
);
|
|
9651
10367
|
}
|
|
9652
10368
|
}
|
|
9653
|
-
function
|
|
10369
|
+
function parseUuidOrSlugSelector8(input) {
|
|
9654
10370
|
try {
|
|
9655
10371
|
return normalizeUuidOrSlug(input);
|
|
9656
10372
|
} catch (error) {
|
|
9657
10373
|
const message = error instanceof Error ? error.message : "Invalid selector.";
|
|
9658
|
-
throw new
|
|
10374
|
+
throw new InvalidArgumentError8(message);
|
|
9659
10375
|
}
|
|
9660
10376
|
}
|
|
9661
10377
|
function parseNonNegativeInteger2(input) {
|
|
9662
10378
|
if (!/^\d+$/.test(input.trim())) {
|
|
9663
|
-
throw new
|
|
10379
|
+
throw new InvalidArgumentError8(`Expected a non-negative integer, received "${input}".`);
|
|
9664
10380
|
}
|
|
9665
10381
|
return Number(input);
|
|
9666
10382
|
}
|
|
9667
10383
|
function parseCommaSeparatedValues(input, label) {
|
|
9668
10384
|
const values = input.split(",").map((value) => value.trim()).filter(Boolean);
|
|
9669
10385
|
if (values.length === 0) {
|
|
9670
|
-
throw new
|
|
10386
|
+
throw new InvalidArgumentError8(`Expected ${label} to contain at least one value.`);
|
|
9671
10387
|
}
|
|
9672
10388
|
return values;
|
|
9673
10389
|
}
|
|
@@ -9676,7 +10392,7 @@ function parseExpressionValue(input) {
|
|
|
9676
10392
|
return parseExpression(input);
|
|
9677
10393
|
} catch (error) {
|
|
9678
10394
|
const message = error instanceof Error ? error.message : "Invalid expression.";
|
|
9679
|
-
throw new
|
|
10395
|
+
throw new InvalidArgumentError8(message);
|
|
9680
10396
|
}
|
|
9681
10397
|
}
|
|
9682
10398
|
function parseKeyValueAssignment(input) {
|
|
@@ -9684,7 +10400,7 @@ function parseKeyValueAssignment(input) {
|
|
|
9684
10400
|
return parseKeyValue(input);
|
|
9685
10401
|
} catch (error) {
|
|
9686
10402
|
const message = error instanceof Error ? error.message : "Invalid assignment.";
|
|
9687
|
-
throw new
|
|
10403
|
+
throw new InvalidArgumentError8(message);
|
|
9688
10404
|
}
|
|
9689
10405
|
}
|
|
9690
10406
|
function parseJsonKeyValueAssignment(input) {
|
|
@@ -9692,7 +10408,7 @@ function parseJsonKeyValueAssignment(input) {
|
|
|
9692
10408
|
return parseJsonAssignment(input);
|
|
9693
10409
|
} catch (error) {
|
|
9694
10410
|
const message = error instanceof Error ? error.message : "Invalid JSON assignment.";
|
|
9695
|
-
throw new
|
|
10411
|
+
throw new InvalidArgumentError8(message);
|
|
9696
10412
|
}
|
|
9697
10413
|
}
|
|
9698
10414
|
function collectStringValues(value, previous = []) {
|
|
@@ -9710,7 +10426,7 @@ function collectKeyValueAssignments(value, previous = []) {
|
|
|
9710
10426
|
function collectJsonAssignments(value, previous = []) {
|
|
9711
10427
|
return [...previous, parseJsonKeyValueAssignment(value)];
|
|
9712
10428
|
}
|
|
9713
|
-
function
|
|
10429
|
+
function isJsonObject6(value) {
|
|
9714
10430
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9715
10431
|
}
|
|
9716
10432
|
function parseRawJsonObject2(input, sourceLabel) {
|
|
@@ -9724,7 +10440,7 @@ function parseRawJsonObject2(input, sourceLabel) {
|
|
|
9724
10440
|
`Failed to parse JSON from ${sourceLabel}: ${message}`
|
|
9725
10441
|
);
|
|
9726
10442
|
}
|
|
9727
|
-
if (!
|
|
10443
|
+
if (!isJsonObject6(parsed)) {
|
|
9728
10444
|
throw new CliError(
|
|
9729
10445
|
"invalid_cli_usage",
|
|
9730
10446
|
`Expected ${sourceLabel} to contain a JSON object.`
|
|
@@ -9745,7 +10461,7 @@ function readRawObject3(raw, rawFile) {
|
|
|
9745
10461
|
if (rawFile) {
|
|
9746
10462
|
let contents;
|
|
9747
10463
|
try {
|
|
9748
|
-
contents =
|
|
10464
|
+
contents = readFileSync8(rawFile, "utf8");
|
|
9749
10465
|
} catch (error) {
|
|
9750
10466
|
const message = error instanceof Error ? error.message : "Unable to read file.";
|
|
9751
10467
|
throw new CliError(
|
|
@@ -9757,7 +10473,7 @@ function readRawObject3(raw, rawFile) {
|
|
|
9757
10473
|
}
|
|
9758
10474
|
return {};
|
|
9759
10475
|
}
|
|
9760
|
-
function
|
|
10476
|
+
function isEmptyObject5(value) {
|
|
9761
10477
|
return Object.keys(value).length === 0;
|
|
9762
10478
|
}
|
|
9763
10479
|
function buildAssignmentObject(assignments = [], jsonAssignments = []) {
|
|
@@ -9805,7 +10521,7 @@ function buildRecordCreateInput(options) {
|
|
|
9805
10521
|
...readRawObject3(options.raw, options.rawFile),
|
|
9806
10522
|
...buildAssignmentObject(options.set, options.setJson)
|
|
9807
10523
|
};
|
|
9808
|
-
if (
|
|
10524
|
+
if (isEmptyObject5(values)) {
|
|
9809
10525
|
throw new CliError(
|
|
9810
10526
|
"invalid_cli_usage",
|
|
9811
10527
|
'Provide record fields via "--set", "--set-json", "--raw", or "--raw-file".'
|
|
@@ -9818,7 +10534,7 @@ function readRawSetPayload2(raw) {
|
|
|
9818
10534
|
if (setValue === void 0) {
|
|
9819
10535
|
return {};
|
|
9820
10536
|
}
|
|
9821
|
-
if (!
|
|
10537
|
+
if (!isJsonObject6(setValue)) {
|
|
9822
10538
|
throw new CliError(
|
|
9823
10539
|
"invalid_cli_usage",
|
|
9824
10540
|
'Expected raw update payload field "set" to be a JSON object.'
|
|
@@ -9863,7 +10579,7 @@ function buildRecordUpdateInput(options) {
|
|
|
9863
10579
|
} else {
|
|
9864
10580
|
delete input.unset;
|
|
9865
10581
|
}
|
|
9866
|
-
if (
|
|
10582
|
+
if (isEmptyObject5(input)) {
|
|
9867
10583
|
throw new CliError(
|
|
9868
10584
|
"invalid_cli_usage",
|
|
9869
10585
|
'Provide record updates via "--set", "--set-json", "--unset", "--raw", or "--raw-file".'
|
|
@@ -9873,9 +10589,9 @@ function buildRecordUpdateInput(options) {
|
|
|
9873
10589
|
}
|
|
9874
10590
|
function toTableRows4(data) {
|
|
9875
10591
|
if (Array.isArray(data)) {
|
|
9876
|
-
return data.map((entry) =>
|
|
10592
|
+
return data.map((entry) => isJsonObject6(entry) ? entry : { value: entry });
|
|
9877
10593
|
}
|
|
9878
|
-
if (
|
|
10594
|
+
if (isJsonObject6(data)) {
|
|
9879
10595
|
return [data];
|
|
9880
10596
|
}
|
|
9881
10597
|
return [{ value: data }];
|
|
@@ -9905,9 +10621,9 @@ async function resolveSchemaSelector(api, selector) {
|
|
|
9905
10621
|
}
|
|
9906
10622
|
function registerRecordsCommands(program, options = {}) {
|
|
9907
10623
|
const filePath = options.configPath ?? defaultConfigPath;
|
|
9908
|
-
const stdout =
|
|
10624
|
+
const stdout = getCommandIo10(options.stdout);
|
|
9909
10625
|
const records = program.command("records").description("Manage schema records");
|
|
9910
|
-
records.command("list").description("List records for a schema with simple pagination").argument("<schema>", "schema uuid or slug",
|
|
10626
|
+
records.command("list").description("List records for a schema with simple pagination").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector8).option("--limit <number>", "limit results", parseNonNegativeInteger2).option("--offset <number>", "offset results", parseNonNegativeInteger2).action(async function action(schema, commandOptions) {
|
|
9911
10627
|
const { api, schemasApi, json } = createRecordsApi(this, filePath);
|
|
9912
10628
|
const resolvedSchema = await resolveSchemaSelector(schemasApi, schema);
|
|
9913
10629
|
const data = await api.listRecords(
|
|
@@ -9916,7 +10632,7 @@ function registerRecordsCommands(program, options = {}) {
|
|
|
9916
10632
|
);
|
|
9917
10633
|
const recordsData = getQueryRecords(data);
|
|
9918
10634
|
if (json) {
|
|
9919
|
-
|
|
10635
|
+
emitJson10(
|
|
9920
10636
|
stdout,
|
|
9921
10637
|
"records list",
|
|
9922
10638
|
recordsData,
|
|
@@ -9927,7 +10643,7 @@ function registerRecordsCommands(program, options = {}) {
|
|
|
9927
10643
|
}
|
|
9928
10644
|
emitTable4(stdout, recordsData);
|
|
9929
10645
|
});
|
|
9930
|
-
records.command("query").description("Query records for a schema").argument("<schema>", "schema uuid or slug",
|
|
10646
|
+
records.command("query").description("Query records for a schema").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector8).option("--select <fields>", "comma-separated field selection", (value) => parseCommaSeparatedValues(value, "--select")).option("--where <expression>", "where expression", collectWhereExpressions, []).option("--sort <field:direction>", "sort field(s)", collectSortValues, []).option("--limit <number>", "limit results", parseNonNegativeInteger2).option("--offset <number>", "offset results", parseNonNegativeInteger2).option("--raw <json>", "raw JSON object payload").option("--raw-file <path>", "path to a raw JSON object payload").action(async function action(schema, commandOptions) {
|
|
9931
10647
|
const { api, schemasApi, json } = createRecordsApi(this, filePath);
|
|
9932
10648
|
const resolvedSchema = await resolveSchemaSelector(schemasApi, schema);
|
|
9933
10649
|
const data = await api.queryRecords(
|
|
@@ -9936,7 +10652,7 @@ function registerRecordsCommands(program, options = {}) {
|
|
|
9936
10652
|
);
|
|
9937
10653
|
const recordsData = getQueryRecords(data);
|
|
9938
10654
|
if (json) {
|
|
9939
|
-
|
|
10655
|
+
emitJson10(
|
|
9940
10656
|
stdout,
|
|
9941
10657
|
"records query",
|
|
9942
10658
|
recordsData,
|
|
@@ -9947,33 +10663,33 @@ function registerRecordsCommands(program, options = {}) {
|
|
|
9947
10663
|
}
|
|
9948
10664
|
emitTable4(stdout, recordsData);
|
|
9949
10665
|
});
|
|
9950
|
-
records.command("get").description("Get a record by UUID or slug").argument("<schema>", "schema uuid or slug",
|
|
10666
|
+
records.command("get").description("Get a record by UUID or slug").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector8).argument("<record>", "record uuid or slug", parseUuidOrSlugSelector8).action(async function action(schema, record) {
|
|
9951
10667
|
const { api, schemasApi, json } = createRecordsApi(this, filePath);
|
|
9952
10668
|
const resolvedSchema = await resolveSchemaSelector(schemasApi, schema);
|
|
9953
10669
|
const data = await api.getRecord(resolvedSchema, record);
|
|
9954
10670
|
if (json) {
|
|
9955
|
-
|
|
10671
|
+
emitJson10(stdout, "records get", data, filePath);
|
|
9956
10672
|
return;
|
|
9957
10673
|
}
|
|
9958
10674
|
emitTable4(stdout, data);
|
|
9959
10675
|
});
|
|
9960
|
-
records.command("create").description("Create a record").argument("<schema>", "schema uuid or slug",
|
|
10676
|
+
records.command("create").description("Create a record").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector8).option("--set <field=value>", "set a string field", collectKeyValueAssignments, []).option("--set-json <field=json>", "set a structured field", collectJsonAssignments, []).option("--raw <json>", "raw JSON object payload").option("--raw-file <path>", "path to a raw JSON object payload").action(async function action(schema, commandOptions) {
|
|
9961
10677
|
const { api, schemasApi, json, readOnly } = createRecordsApi(this, filePath);
|
|
9962
|
-
|
|
10678
|
+
ensureWritable7("records create", readOnly, "write");
|
|
9963
10679
|
const resolvedSchema = await resolveSchemaSelector(schemasApi, schema);
|
|
9964
10680
|
const data = await api.createRecord(
|
|
9965
10681
|
resolvedSchema,
|
|
9966
10682
|
buildRecordCreateInput(commandOptions)
|
|
9967
10683
|
);
|
|
9968
10684
|
if (json) {
|
|
9969
|
-
|
|
10685
|
+
emitJson10(stdout, "records create", data, filePath);
|
|
9970
10686
|
return;
|
|
9971
10687
|
}
|
|
9972
|
-
|
|
10688
|
+
writeLine10(stdout, `Created record "${getRecordIdentifier(data)}".`);
|
|
9973
10689
|
});
|
|
9974
|
-
records.command("update").description("Update a record").argument("<schema>", "schema uuid or slug",
|
|
10690
|
+
records.command("update").description("Update a record").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector8).argument("<record>", "record uuid or slug", parseUuidOrSlugSelector8).option("--set <field=value>", "set a string field", collectKeyValueAssignments, []).option("--set-json <field=json>", "set a structured field", collectJsonAssignments, []).option("--unset <field>", "unset a field", collectStringValues, []).option("--raw <json>", "raw JSON object payload").option("--raw-file <path>", "path to a raw JSON object payload").action(async function action(schema, record, commandOptions) {
|
|
9975
10691
|
const { api, schemasApi, json, readOnly } = createRecordsApi(this, filePath);
|
|
9976
|
-
|
|
10692
|
+
ensureWritable7("records update", readOnly, "write");
|
|
9977
10693
|
const resolvedSchema = await resolveSchemaSelector(schemasApi, schema);
|
|
9978
10694
|
const data = await api.updateRecord(
|
|
9979
10695
|
resolvedSchema,
|
|
@@ -9981,14 +10697,14 @@ function registerRecordsCommands(program, options = {}) {
|
|
|
9981
10697
|
buildRecordUpdateInput(commandOptions)
|
|
9982
10698
|
);
|
|
9983
10699
|
if (json) {
|
|
9984
|
-
|
|
10700
|
+
emitJson10(stdout, "records update", data, filePath);
|
|
9985
10701
|
return;
|
|
9986
10702
|
}
|
|
9987
|
-
|
|
10703
|
+
writeLine10(stdout, `Updated record "${getRecordIdentifier(data)}".`);
|
|
9988
10704
|
});
|
|
9989
|
-
records.command("delete").description("Delete a record").argument("<schema>", "schema uuid or slug",
|
|
10705
|
+
records.command("delete").description("Delete a record").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector8).argument("<record>", "record uuid or slug", parseUuidOrSlugSelector8).action(async function action(schema, record) {
|
|
9990
10706
|
const { api, schemasApi, json, readOnly } = createRecordsApi(this, filePath);
|
|
9991
|
-
|
|
10707
|
+
ensureWritable7("records delete", readOnly, "destructive");
|
|
9992
10708
|
const resolvedSchema = await resolveSchemaSelector(schemasApi, schema);
|
|
9993
10709
|
await api.deleteRecord(resolvedSchema, record);
|
|
9994
10710
|
const data = {
|
|
@@ -9997,44 +10713,44 @@ function registerRecordsCommands(program, options = {}) {
|
|
|
9997
10713
|
deleted: true
|
|
9998
10714
|
};
|
|
9999
10715
|
if (json) {
|
|
10000
|
-
|
|
10716
|
+
emitJson10(stdout, "records delete", data, filePath);
|
|
10001
10717
|
return;
|
|
10002
10718
|
}
|
|
10003
|
-
|
|
10719
|
+
writeLine10(stdout, `Deleted record "${record.value}" from schema "${schema.value}".`);
|
|
10004
10720
|
});
|
|
10005
|
-
records.command("clear").description("Delete all records from a schema's table").argument("<schema>", "schema uuid or slug",
|
|
10721
|
+
records.command("clear").description("Delete all records from a schema's table").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector8).action(async function action(schema) {
|
|
10006
10722
|
const { api, schemasApi, json, readOnly } = createRecordsApi(this, filePath);
|
|
10007
|
-
|
|
10723
|
+
ensureWritable7("records clear", readOnly, "destructive");
|
|
10008
10724
|
const resolvedSchema = await resolveSchemaSelector(schemasApi, schema);
|
|
10009
10725
|
const data = await api.clearRecords(resolvedSchema);
|
|
10010
10726
|
if (json) {
|
|
10011
|
-
|
|
10727
|
+
emitJson10(stdout, "records clear", data, filePath);
|
|
10012
10728
|
return;
|
|
10013
10729
|
}
|
|
10014
|
-
|
|
10730
|
+
writeLine10(stdout, `Cleared all records from schema "${schema.value}".`);
|
|
10015
10731
|
});
|
|
10016
10732
|
}
|
|
10017
10733
|
|
|
10018
10734
|
// src/commands/schemas.ts
|
|
10019
|
-
import { readFileSync as
|
|
10020
|
-
import { InvalidArgumentError as
|
|
10021
|
-
function
|
|
10735
|
+
import { readFileSync as readFileSync9 } from "fs";
|
|
10736
|
+
import { InvalidArgumentError as InvalidArgumentError9 } from "commander";
|
|
10737
|
+
function getCommandIo11(stdout) {
|
|
10022
10738
|
return stdout ?? process.stdout;
|
|
10023
10739
|
}
|
|
10024
|
-
function
|
|
10740
|
+
function writeLine11(stdout, value) {
|
|
10025
10741
|
stdout.write(`${value}
|
|
10026
10742
|
`);
|
|
10027
10743
|
}
|
|
10028
|
-
function
|
|
10744
|
+
function getGlobalOptions11(command) {
|
|
10029
10745
|
return command.optsWithGlobals();
|
|
10030
10746
|
}
|
|
10031
|
-
function
|
|
10032
|
-
|
|
10747
|
+
function emitJson11(stdout, commandName, data, configPath) {
|
|
10748
|
+
writeLine11(
|
|
10033
10749
|
stdout,
|
|
10034
10750
|
JSON.stringify(buildJsonSuccess(data, { command: commandName, configPath }))
|
|
10035
10751
|
);
|
|
10036
10752
|
}
|
|
10037
|
-
function
|
|
10753
|
+
function toConfigurationError10(filePath, error) {
|
|
10038
10754
|
if (error instanceof CliError) {
|
|
10039
10755
|
throw error;
|
|
10040
10756
|
}
|
|
@@ -10049,7 +10765,7 @@ function toConfigurationError9(filePath, error) {
|
|
|
10049
10765
|
function createSchemasApi(command, filePath) {
|
|
10050
10766
|
try {
|
|
10051
10767
|
const config = readRuntimeConfig(filePath);
|
|
10052
|
-
const runtime = resolveRuntimeContext(config,
|
|
10768
|
+
const runtime = resolveRuntimeContext(config, getGlobalOptions11(command));
|
|
10053
10769
|
if (!runtime.baseUrl) {
|
|
10054
10770
|
throw new CliError(
|
|
10055
10771
|
"configuration_error",
|
|
@@ -10068,10 +10784,10 @@ function createSchemasApi(command, filePath) {
|
|
|
10068
10784
|
readOnly: runtime.readOnly
|
|
10069
10785
|
};
|
|
10070
10786
|
} catch (error) {
|
|
10071
|
-
|
|
10787
|
+
toConfigurationError10(filePath, error);
|
|
10072
10788
|
}
|
|
10073
10789
|
}
|
|
10074
|
-
function
|
|
10790
|
+
function ensureWritable8(commandName, readOnly, commandMode) {
|
|
10075
10791
|
if (readOnly) {
|
|
10076
10792
|
throw new CliError(
|
|
10077
10793
|
"command_not_allowed_in_read_only_mode",
|
|
@@ -10083,12 +10799,12 @@ function ensureWritable7(commandName, readOnly, commandMode) {
|
|
|
10083
10799
|
);
|
|
10084
10800
|
}
|
|
10085
10801
|
}
|
|
10086
|
-
function
|
|
10802
|
+
function parseUuidOrSlugSelector9(input) {
|
|
10087
10803
|
try {
|
|
10088
10804
|
return normalizeUuidOrSlug(input);
|
|
10089
10805
|
} catch (error) {
|
|
10090
10806
|
const message = error instanceof Error ? error.message : "Invalid selector.";
|
|
10091
|
-
throw new
|
|
10807
|
+
throw new InvalidArgumentError9(message);
|
|
10092
10808
|
}
|
|
10093
10809
|
}
|
|
10094
10810
|
function parseBooleanFlag(input) {
|
|
@@ -10099,9 +10815,9 @@ function parseBooleanFlag(input) {
|
|
|
10099
10815
|
if (["false", "0", "no", "n", "off"].includes(normalized)) {
|
|
10100
10816
|
return false;
|
|
10101
10817
|
}
|
|
10102
|
-
throw new
|
|
10818
|
+
throw new InvalidArgumentError9(`Expected a boolean value, received "${input}".`);
|
|
10103
10819
|
}
|
|
10104
|
-
function
|
|
10820
|
+
function isJsonObject7(value) {
|
|
10105
10821
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10106
10822
|
}
|
|
10107
10823
|
function parseRawJsonObject3(input, sourceLabel) {
|
|
@@ -10115,7 +10831,7 @@ function parseRawJsonObject3(input, sourceLabel) {
|
|
|
10115
10831
|
`Failed to parse JSON from ${sourceLabel}: ${message}`
|
|
10116
10832
|
);
|
|
10117
10833
|
}
|
|
10118
|
-
if (!
|
|
10834
|
+
if (!isJsonObject7(parsed)) {
|
|
10119
10835
|
throw new CliError(
|
|
10120
10836
|
"invalid_cli_usage",
|
|
10121
10837
|
`Expected ${sourceLabel} to contain a JSON object.`
|
|
@@ -10136,7 +10852,7 @@ function readRawObject4(raw, rawFile) {
|
|
|
10136
10852
|
if (rawFile) {
|
|
10137
10853
|
let contents;
|
|
10138
10854
|
try {
|
|
10139
|
-
contents =
|
|
10855
|
+
contents = readFileSync9(rawFile, "utf8");
|
|
10140
10856
|
} catch (error) {
|
|
10141
10857
|
const message = error instanceof Error ? error.message : "Unable to read file.";
|
|
10142
10858
|
throw new CliError(
|
|
@@ -10195,7 +10911,7 @@ function applyFieldDefaultValue(input, defaultValue) {
|
|
|
10195
10911
|
return;
|
|
10196
10912
|
}
|
|
10197
10913
|
const config = input.config;
|
|
10198
|
-
if (config !== void 0 && !
|
|
10914
|
+
if (config !== void 0 && !isJsonObject7(config)) {
|
|
10199
10915
|
throw new CliError(
|
|
10200
10916
|
"invalid_cli_usage",
|
|
10201
10917
|
'Expected field "config" to be a JSON object when using "--default".'
|
|
@@ -10235,7 +10951,7 @@ function buildFieldCreateInput(options) {
|
|
|
10235
10951
|
input.required = options.required;
|
|
10236
10952
|
}
|
|
10237
10953
|
applyFieldDefaultValue(input, options.default);
|
|
10238
|
-
if ("config" in input &&
|
|
10954
|
+
if ("config" in input && isJsonObject7(input.config) && isEmptyObject6(input.config)) {
|
|
10239
10955
|
delete input.config;
|
|
10240
10956
|
}
|
|
10241
10957
|
return input;
|
|
@@ -10308,35 +11024,35 @@ async function resolveFieldSelector(api, schema, selector) {
|
|
|
10308
11024
|
value: match.id
|
|
10309
11025
|
};
|
|
10310
11026
|
}
|
|
10311
|
-
function
|
|
11027
|
+
function isEmptyObject6(value) {
|
|
10312
11028
|
return Object.keys(value).length === 0;
|
|
10313
11029
|
}
|
|
10314
11030
|
function registerSchemasCommands(program, options = {}) {
|
|
10315
11031
|
const filePath = options.configPath ?? defaultConfigPath;
|
|
10316
|
-
const stdout =
|
|
11032
|
+
const stdout = getCommandIo11(options.stdout);
|
|
10317
11033
|
const schemas = program.command("schemas").description("Manage schemas and schema fields");
|
|
10318
11034
|
schemas.command("list").description("List schemas").action(async function action() {
|
|
10319
11035
|
const { api, json } = createSchemasApi(this, filePath);
|
|
10320
11036
|
const data = await api.listSchemas();
|
|
10321
11037
|
if (json) {
|
|
10322
|
-
|
|
11038
|
+
emitJson11(stdout, "schemas list", data, filePath);
|
|
10323
11039
|
return;
|
|
10324
11040
|
}
|
|
10325
11041
|
emitSchemasTable(stdout, data);
|
|
10326
11042
|
});
|
|
10327
|
-
schemas.command("get").description("Get a schema by UUID or slug").argument("<schema>", "schema uuid or slug",
|
|
11043
|
+
schemas.command("get").description("Get a schema by UUID or slug").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector9).action(async function action(schema) {
|
|
10328
11044
|
const { api, json } = createSchemasApi(this, filePath);
|
|
10329
11045
|
const resolvedSchema = await resolveSchemaSelector2(api, schema);
|
|
10330
11046
|
const data = await api.getSchema(resolvedSchema);
|
|
10331
11047
|
if (json) {
|
|
10332
|
-
|
|
11048
|
+
emitJson11(stdout, "schemas get", data, filePath);
|
|
10333
11049
|
return;
|
|
10334
11050
|
}
|
|
10335
11051
|
emitSchemasTable(stdout, [data]);
|
|
10336
11052
|
});
|
|
10337
11053
|
schemas.command("create").description("Create a schema").requiredOption("--name <name>", "schema name").requiredOption("--slug <slug>", "schema slug").option("--auditable", "mark schema as auditable").option("--commentable", "mark schema as commentable").action(async function action(commandOptions) {
|
|
10338
11054
|
const { api, json, readOnly } = createSchemasApi(this, filePath);
|
|
10339
|
-
|
|
11055
|
+
ensureWritable8("schemas create", readOnly, "write");
|
|
10340
11056
|
const input = {
|
|
10341
11057
|
name: commandOptions.name,
|
|
10342
11058
|
slug: commandOptions.slug,
|
|
@@ -10345,17 +11061,17 @@ function registerSchemasCommands(program, options = {}) {
|
|
|
10345
11061
|
};
|
|
10346
11062
|
const data = await api.createSchema(input);
|
|
10347
11063
|
if (json) {
|
|
10348
|
-
|
|
11064
|
+
emitJson11(stdout, "schemas create", data, filePath);
|
|
10349
11065
|
return;
|
|
10350
11066
|
}
|
|
10351
|
-
|
|
11067
|
+
writeLine11(stdout, `Created schema "${data.slug ?? commandOptions.slug}".`);
|
|
10352
11068
|
});
|
|
10353
|
-
schemas.command("update").description("Update a schema").argument("<schema>", "schema uuid or slug",
|
|
11069
|
+
schemas.command("update").description("Update a schema").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector9).option("--name <name>", "schema name").option("--slug <slug>", "schema slug").option("--auditable <bool>", "auditable flag", parseBooleanFlag).option("--commentable <bool>", "commentable flag", parseBooleanFlag).action(async function action(schema, commandOptions) {
|
|
10354
11070
|
const { api, json, readOnly } = createSchemasApi(this, filePath);
|
|
10355
|
-
|
|
11071
|
+
ensureWritable8("schemas update", readOnly, "write");
|
|
10356
11072
|
const resolvedSchema = await resolveSchemaSelector2(api, schema);
|
|
10357
11073
|
const input = buildSchemaUpdateInput(commandOptions);
|
|
10358
|
-
if (
|
|
11074
|
+
if (isEmptyObject6(input)) {
|
|
10359
11075
|
throw new CliError(
|
|
10360
11076
|
"invalid_cli_usage",
|
|
10361
11077
|
'Provide at least one schema field to update via "--name", "--slug", "--auditable", or "--commentable".'
|
|
@@ -10363,14 +11079,14 @@ function registerSchemasCommands(program, options = {}) {
|
|
|
10363
11079
|
}
|
|
10364
11080
|
const data = await api.updateSchema(resolvedSchema, input);
|
|
10365
11081
|
if (json) {
|
|
10366
|
-
|
|
11082
|
+
emitJson11(stdout, "schemas update", data, filePath);
|
|
10367
11083
|
return;
|
|
10368
11084
|
}
|
|
10369
|
-
|
|
11085
|
+
writeLine11(stdout, `Updated schema "${data.slug ?? schema.value}".`);
|
|
10370
11086
|
});
|
|
10371
|
-
schemas.command("delete").description("Delete a schema").argument("<schema>", "schema uuid or slug",
|
|
11087
|
+
schemas.command("delete").description("Delete a schema").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector9).action(async function action(schema) {
|
|
10372
11088
|
const { api, json, readOnly } = createSchemasApi(this, filePath);
|
|
10373
|
-
|
|
11089
|
+
ensureWritable8("schemas delete", readOnly, "destructive");
|
|
10374
11090
|
const resolvedSchema = await resolveSchemaSelector2(api, schema);
|
|
10375
11091
|
await api.deleteSchema(resolvedSchema);
|
|
10376
11092
|
const data = {
|
|
@@ -10378,36 +11094,36 @@ function registerSchemasCommands(program, options = {}) {
|
|
|
10378
11094
|
deleted: true
|
|
10379
11095
|
};
|
|
10380
11096
|
if (json) {
|
|
10381
|
-
|
|
11097
|
+
emitJson11(stdout, "schemas delete", data, filePath);
|
|
10382
11098
|
return;
|
|
10383
11099
|
}
|
|
10384
|
-
|
|
11100
|
+
writeLine11(stdout, `Deleted schema "${schema.value}".`);
|
|
10385
11101
|
});
|
|
10386
11102
|
const fields = schemas.command("fields").description("Manage schema fields");
|
|
10387
|
-
fields.command("list").description("List fields for a schema").argument("<schema>", "schema uuid or slug",
|
|
11103
|
+
fields.command("list").description("List fields for a schema").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector9).action(async function action(schema) {
|
|
10388
11104
|
const { api, json } = createSchemasApi(this, filePath);
|
|
10389
11105
|
const resolvedSchema = await resolveSchemaSelector2(api, schema);
|
|
10390
11106
|
const data = await api.listFields(resolvedSchema);
|
|
10391
11107
|
if (json) {
|
|
10392
|
-
|
|
11108
|
+
emitJson11(stdout, "schemas fields list", data, filePath);
|
|
10393
11109
|
return;
|
|
10394
11110
|
}
|
|
10395
11111
|
emitFieldsTable(stdout, data);
|
|
10396
11112
|
});
|
|
10397
|
-
fields.command("get").description("Get a field by UUID or slug").argument("<schema>", "schema uuid or slug",
|
|
11113
|
+
fields.command("get").description("Get a field by UUID or slug").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector9).argument("<field>", "field uuid or slug", parseUuidOrSlugSelector9).action(async function action(schema, field) {
|
|
10398
11114
|
const { api, json } = createSchemasApi(this, filePath);
|
|
10399
11115
|
const resolvedSchema = await resolveSchemaSelector2(api, schema);
|
|
10400
11116
|
const resolvedField = await resolveFieldSelector(api, resolvedSchema, field);
|
|
10401
11117
|
const data = await api.getField(resolvedSchema, resolvedField);
|
|
10402
11118
|
if (json) {
|
|
10403
|
-
|
|
11119
|
+
emitJson11(stdout, "schemas fields get", data, filePath);
|
|
10404
11120
|
return;
|
|
10405
11121
|
}
|
|
10406
11122
|
emitFieldsTable(stdout, [data]);
|
|
10407
11123
|
});
|
|
10408
|
-
fields.command("create").description(`Create a field in a schema.${buildSchemaFieldCreateHelpText()}`).argument("<schema>", "schema uuid or slug",
|
|
11124
|
+
fields.command("create").description(`Create a field in a schema.${buildSchemaFieldCreateHelpText()}`).argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector9).option("--type <type>", `field type (${formatSchemaFieldTypes()})`).option("--slug <slug>", "field slug").option("--label <label>", "field label").option("--required <bool>", "required flag", parseBooleanFlag).option("--default <value>", "default field value").option("--raw <json>", "raw JSON object payload (see type-specific shapes in --help)").option("--raw-file <path>", "path to a raw JSON object payload").action(async function action(schema, commandOptions) {
|
|
10409
11125
|
const { api, json, readOnly } = createSchemasApi(this, filePath);
|
|
10410
|
-
|
|
11126
|
+
ensureWritable8("schemas fields create", readOnly, "write");
|
|
10411
11127
|
const input = buildFieldCreateInput(commandOptions);
|
|
10412
11128
|
const resolvedSchema = await resolveSchemaSelector2(api, schema);
|
|
10413
11129
|
let data;
|
|
@@ -10417,14 +11133,14 @@ function registerSchemasCommands(program, options = {}) {
|
|
|
10417
11133
|
toFieldCreateError(error, input);
|
|
10418
11134
|
}
|
|
10419
11135
|
if (json) {
|
|
10420
|
-
|
|
11136
|
+
emitJson11(stdout, "schemas fields create", data, filePath);
|
|
10421
11137
|
return;
|
|
10422
11138
|
}
|
|
10423
|
-
|
|
11139
|
+
writeLine11(stdout, `Created field "${data.slug ?? commandOptions.slug}".`);
|
|
10424
11140
|
});
|
|
10425
|
-
fields.command("update").description("Update a field in a schema").argument("<schema>", "schema uuid or slug",
|
|
11141
|
+
fields.command("update").description("Update a field in a schema").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector9).argument("<field>", "field uuid or slug", parseUuidOrSlugSelector9).option("--label <label>", "field label").option("--required <bool>", "required flag", parseBooleanFlag).option("--default <value>", "default field value").option("--raw <json>", "raw JSON object payload").option("--raw-file <path>", "path to a raw JSON object payload").action(async function action(schema, field, commandOptions) {
|
|
10426
11142
|
const { api, json, readOnly } = createSchemasApi(this, filePath);
|
|
10427
|
-
|
|
11143
|
+
ensureWritable8("schemas fields update", readOnly, "write");
|
|
10428
11144
|
const resolvedSchema = await resolveSchemaSelector2(api, schema);
|
|
10429
11145
|
const resolvedField = await resolveFieldSelector(api, resolvedSchema, field);
|
|
10430
11146
|
const currentField = await api.getField(resolvedSchema, resolvedField);
|
|
@@ -10433,7 +11149,7 @@ function registerSchemasCommands(program, options = {}) {
|
|
|
10433
11149
|
throw new CliError("invalid_cli_usage", `Field "${field.value}" is missing type metadata.`);
|
|
10434
11150
|
}
|
|
10435
11151
|
const input = buildFieldUpdateInput(currentType, commandOptions);
|
|
10436
|
-
if (
|
|
11152
|
+
if (isEmptyObject6(input)) {
|
|
10437
11153
|
throw new CliError(
|
|
10438
11154
|
"invalid_cli_usage",
|
|
10439
11155
|
'Provide at least one field update via "--label", "--required", "--raw", or "--raw-file".'
|
|
@@ -10441,14 +11157,14 @@ function registerSchemasCommands(program, options = {}) {
|
|
|
10441
11157
|
}
|
|
10442
11158
|
const data = await api.updateField(resolvedSchema, resolvedField, input);
|
|
10443
11159
|
if (json) {
|
|
10444
|
-
|
|
11160
|
+
emitJson11(stdout, "schemas fields update", data, filePath);
|
|
10445
11161
|
return;
|
|
10446
11162
|
}
|
|
10447
|
-
|
|
11163
|
+
writeLine11(stdout, `Updated field "${data.slug ?? field.value}".`);
|
|
10448
11164
|
});
|
|
10449
|
-
fields.command("delete").description("Delete a field from a schema").argument("<schema>", "schema uuid or slug",
|
|
11165
|
+
fields.command("delete").description("Delete a field from a schema").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector9).argument("<field>", "field uuid or slug", parseUuidOrSlugSelector9).action(async function action(schema, field) {
|
|
10450
11166
|
const { api, json, readOnly } = createSchemasApi(this, filePath);
|
|
10451
|
-
|
|
11167
|
+
ensureWritable8("schemas fields delete", readOnly, "destructive");
|
|
10452
11168
|
const resolvedSchema = await resolveSchemaSelector2(api, schema);
|
|
10453
11169
|
const resolvedField = await resolveFieldSelector(api, resolvedSchema, field);
|
|
10454
11170
|
await api.deleteField(resolvedSchema, resolvedField);
|
|
@@ -10458,19 +11174,19 @@ function registerSchemasCommands(program, options = {}) {
|
|
|
10458
11174
|
deleted: true
|
|
10459
11175
|
};
|
|
10460
11176
|
if (json) {
|
|
10461
|
-
|
|
11177
|
+
emitJson11(stdout, "schemas fields delete", data, filePath);
|
|
10462
11178
|
return;
|
|
10463
11179
|
}
|
|
10464
|
-
|
|
11180
|
+
writeLine11(stdout, `Deleted field "${field.value}" from schema "${schema.value}".`);
|
|
10465
11181
|
});
|
|
10466
11182
|
}
|
|
10467
11183
|
|
|
10468
11184
|
// src/commands/teamspace.ts
|
|
10469
|
-
import { readFileSync as
|
|
10470
|
-
import { InvalidArgumentError as
|
|
11185
|
+
import { readFileSync as readFileSync10 } from "fs";
|
|
11186
|
+
import { InvalidArgumentError as InvalidArgumentError10 } from "commander";
|
|
10471
11187
|
|
|
10472
11188
|
// src/api/teamspace.ts
|
|
10473
|
-
function
|
|
11189
|
+
function jsonOptions8(body, method) {
|
|
10474
11190
|
return {
|
|
10475
11191
|
method,
|
|
10476
11192
|
headers: {
|
|
@@ -10479,7 +11195,7 @@ function jsonOptions7(body, method) {
|
|
|
10479
11195
|
body: JSON.stringify(body)
|
|
10480
11196
|
};
|
|
10481
11197
|
}
|
|
10482
|
-
function
|
|
11198
|
+
function selectorValue10(selector) {
|
|
10483
11199
|
return selector.value;
|
|
10484
11200
|
}
|
|
10485
11201
|
var TeamspaceApi = class {
|
|
@@ -10500,53 +11216,53 @@ var TeamspaceApi = class {
|
|
|
10500
11216
|
createFolder(input) {
|
|
10501
11217
|
return this.client.requestJson(
|
|
10502
11218
|
"/api/v2/teamspaces/folders",
|
|
10503
|
-
|
|
11219
|
+
jsonOptions8(input, "POST")
|
|
10504
11220
|
);
|
|
10505
11221
|
}
|
|
10506
11222
|
updateFolder(folder, input) {
|
|
10507
11223
|
return this.client.requestJson(
|
|
10508
|
-
`/api/v2/teamspaces/folders/${
|
|
10509
|
-
|
|
11224
|
+
`/api/v2/teamspaces/folders/${selectorValue10(folder)}`,
|
|
11225
|
+
jsonOptions8(input, "PATCH")
|
|
10510
11226
|
);
|
|
10511
11227
|
}
|
|
10512
11228
|
deleteFolder(folder) {
|
|
10513
11229
|
return this.client.requestJson(
|
|
10514
|
-
`/api/v2/teamspaces/folders/${
|
|
11230
|
+
`/api/v2/teamspaces/folders/${selectorValue10(folder)}`,
|
|
10515
11231
|
{ method: "DELETE" }
|
|
10516
11232
|
);
|
|
10517
11233
|
}
|
|
10518
11234
|
publishResource(input) {
|
|
10519
11235
|
return this.client.requestJson(
|
|
10520
11236
|
"/api/v2/teamspaces/resources:publish",
|
|
10521
|
-
|
|
11237
|
+
jsonOptions8(input, "POST")
|
|
10522
11238
|
);
|
|
10523
11239
|
}
|
|
10524
11240
|
unpublishResource(resourceId) {
|
|
10525
11241
|
return this.client.requestJson(
|
|
10526
11242
|
"/api/v2/teamspaces/resources:unpublish",
|
|
10527
|
-
|
|
11243
|
+
jsonOptions8({ resourceId }, "POST")
|
|
10528
11244
|
);
|
|
10529
11245
|
}
|
|
10530
11246
|
};
|
|
10531
11247
|
|
|
10532
11248
|
// src/commands/teamspace.ts
|
|
10533
|
-
function
|
|
11249
|
+
function getCommandIo12(stdout) {
|
|
10534
11250
|
return stdout ?? process.stdout;
|
|
10535
11251
|
}
|
|
10536
|
-
function
|
|
11252
|
+
function writeLine12(stdout, value) {
|
|
10537
11253
|
stdout.write(`${value}
|
|
10538
11254
|
`);
|
|
10539
11255
|
}
|
|
10540
|
-
function
|
|
11256
|
+
function getGlobalOptions12(command) {
|
|
10541
11257
|
return command.optsWithGlobals();
|
|
10542
11258
|
}
|
|
10543
|
-
function
|
|
10544
|
-
|
|
11259
|
+
function emitJson12(stdout, commandName, data, configPath) {
|
|
11260
|
+
writeLine12(
|
|
10545
11261
|
stdout,
|
|
10546
11262
|
JSON.stringify(buildJsonSuccess(data, { command: commandName, configPath }))
|
|
10547
11263
|
);
|
|
10548
11264
|
}
|
|
10549
|
-
function
|
|
11265
|
+
function toConfigurationError11(filePath, error) {
|
|
10550
11266
|
if (error instanceof CliError) {
|
|
10551
11267
|
throw error;
|
|
10552
11268
|
}
|
|
@@ -10561,7 +11277,7 @@ function toConfigurationError10(filePath, error) {
|
|
|
10561
11277
|
function createTeamspaceApi(command, filePath) {
|
|
10562
11278
|
try {
|
|
10563
11279
|
const config = readRuntimeConfig(filePath);
|
|
10564
|
-
const runtime = resolveRuntimeContext(config,
|
|
11280
|
+
const runtime = resolveRuntimeContext(config, getGlobalOptions12(command));
|
|
10565
11281
|
if (!runtime.baseUrl) {
|
|
10566
11282
|
throw new CliError(
|
|
10567
11283
|
"configuration_error",
|
|
@@ -10579,10 +11295,10 @@ function createTeamspaceApi(command, filePath) {
|
|
|
10579
11295
|
readOnly: runtime.readOnly
|
|
10580
11296
|
};
|
|
10581
11297
|
} catch (error) {
|
|
10582
|
-
|
|
11298
|
+
toConfigurationError11(filePath, error);
|
|
10583
11299
|
}
|
|
10584
11300
|
}
|
|
10585
|
-
function
|
|
11301
|
+
function ensureWritable9(commandName, readOnly, commandMode) {
|
|
10586
11302
|
if (readOnly) {
|
|
10587
11303
|
throw new CliError(
|
|
10588
11304
|
"command_not_allowed_in_read_only_mode",
|
|
@@ -10594,21 +11310,21 @@ function ensureWritable8(commandName, readOnly, commandMode) {
|
|
|
10594
11310
|
);
|
|
10595
11311
|
}
|
|
10596
11312
|
}
|
|
10597
|
-
function
|
|
11313
|
+
function parseUuidOrSlugSelector10(input) {
|
|
10598
11314
|
try {
|
|
10599
11315
|
return normalizeUuidOrSlug(input);
|
|
10600
11316
|
} catch (error) {
|
|
10601
11317
|
const message = error instanceof Error ? error.message : "Invalid selector.";
|
|
10602
|
-
throw new
|
|
11318
|
+
throw new InvalidArgumentError10(message);
|
|
10603
11319
|
}
|
|
10604
11320
|
}
|
|
10605
11321
|
function parseNonNegativeInteger3(input) {
|
|
10606
11322
|
if (!/^\d+$/.test(input.trim())) {
|
|
10607
|
-
throw new
|
|
11323
|
+
throw new InvalidArgumentError10(`Expected a non-negative integer, received "${input}".`);
|
|
10608
11324
|
}
|
|
10609
11325
|
return Number(input);
|
|
10610
11326
|
}
|
|
10611
|
-
function
|
|
11327
|
+
function isJsonObject8(value) {
|
|
10612
11328
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10613
11329
|
}
|
|
10614
11330
|
function parseRawJsonObject4(input, sourceLabel) {
|
|
@@ -10622,7 +11338,7 @@ function parseRawJsonObject4(input, sourceLabel) {
|
|
|
10622
11338
|
`Failed to parse JSON from ${sourceLabel}: ${message}`
|
|
10623
11339
|
);
|
|
10624
11340
|
}
|
|
10625
|
-
if (!
|
|
11341
|
+
if (!isJsonObject8(parsed)) {
|
|
10626
11342
|
throw new CliError(
|
|
10627
11343
|
"invalid_cli_usage",
|
|
10628
11344
|
`Expected ${sourceLabel} to contain a JSON object.`
|
|
@@ -10643,7 +11359,7 @@ function readRawObject5(raw, rawFile) {
|
|
|
10643
11359
|
if (rawFile) {
|
|
10644
11360
|
let contents;
|
|
10645
11361
|
try {
|
|
10646
|
-
contents =
|
|
11362
|
+
contents = readFileSync10(rawFile, "utf8");
|
|
10647
11363
|
} catch (error) {
|
|
10648
11364
|
const message = error instanceof Error ? error.message : "Unable to read file.";
|
|
10649
11365
|
throw new CliError(
|
|
@@ -10655,7 +11371,7 @@ function readRawObject5(raw, rawFile) {
|
|
|
10655
11371
|
}
|
|
10656
11372
|
return void 0;
|
|
10657
11373
|
}
|
|
10658
|
-
function
|
|
11374
|
+
function isEmptyObject7(value) {
|
|
10659
11375
|
return Object.keys(value).length === 0;
|
|
10660
11376
|
}
|
|
10661
11377
|
function buildFolderCreateInput(options) {
|
|
@@ -10686,7 +11402,7 @@ function buildFolderUpdateInput(options) {
|
|
|
10686
11402
|
if (props !== void 0) {
|
|
10687
11403
|
input.additionalProperties = props;
|
|
10688
11404
|
}
|
|
10689
|
-
if (
|
|
11405
|
+
if (isEmptyObject7(input)) {
|
|
10690
11406
|
throw new CliError(
|
|
10691
11407
|
"invalid_cli_usage",
|
|
10692
11408
|
'Provide folder updates via "--name", "--order", "--props", or "--props-file".'
|
|
@@ -10696,9 +11412,9 @@ function buildFolderUpdateInput(options) {
|
|
|
10696
11412
|
}
|
|
10697
11413
|
function toTableRows5(data) {
|
|
10698
11414
|
if (Array.isArray(data)) {
|
|
10699
|
-
return data.map((entry) =>
|
|
11415
|
+
return data.map((entry) => isJsonObject8(entry) ? entry : { value: entry });
|
|
10700
11416
|
}
|
|
10701
|
-
if (
|
|
11417
|
+
if (isJsonObject8(data)) {
|
|
10702
11418
|
return [data];
|
|
10703
11419
|
}
|
|
10704
11420
|
return [{ value: data }];
|
|
@@ -10760,85 +11476,85 @@ async function resolveFolderSelector2(api, selector) {
|
|
|
10760
11476
|
}
|
|
10761
11477
|
function registerTeamspaceCommands(program, options = {}) {
|
|
10762
11478
|
const filePath = options.configPath ?? defaultConfigPath;
|
|
10763
|
-
const stdout =
|
|
11479
|
+
const stdout = getCommandIo12(options.stdout);
|
|
10764
11480
|
const teamspace = program.command("teamspace").description("Manage teamspace folders and resources");
|
|
10765
11481
|
const folders = teamspace.command("folders").description("Manage teamspace folders");
|
|
10766
11482
|
folders.command("list").description("List teamspace folders").option("--include-resources", "include nested resources").action(async function action(commandOptions) {
|
|
10767
11483
|
const { api, json } = createTeamspaceApi(this, filePath);
|
|
10768
11484
|
const data = await api.listFolders(Boolean(commandOptions.includeResources));
|
|
10769
11485
|
if (json) {
|
|
10770
|
-
|
|
11486
|
+
emitJson12(stdout, "teamspace folders list", data, filePath);
|
|
10771
11487
|
return;
|
|
10772
11488
|
}
|
|
10773
11489
|
emitTable5(stdout, data);
|
|
10774
11490
|
});
|
|
10775
|
-
folders.command("get").description("Get a teamspace folder by exact name or UUID").argument("<folder>", "folder UUID or exact name",
|
|
11491
|
+
folders.command("get").description("Get a teamspace folder by exact name or UUID").argument("<folder>", "folder UUID or exact name", parseUuidOrSlugSelector10).option("--include-resources", "include nested resources").action(async function action(folder, commandOptions) {
|
|
10776
11492
|
const { api, json } = createTeamspaceApi(this, filePath);
|
|
10777
11493
|
const resolvedFolder = await resolveFolderSelector2(api, folder);
|
|
10778
11494
|
const allFolders = await api.listFolders(Boolean(commandOptions.includeResources));
|
|
10779
11495
|
const data = findFolderEntity(allFolders, resolvedFolder);
|
|
10780
11496
|
if (json) {
|
|
10781
|
-
|
|
11497
|
+
emitJson12(stdout, "teamspace folders get", data, filePath);
|
|
10782
11498
|
return;
|
|
10783
11499
|
}
|
|
10784
11500
|
emitTable5(stdout, data);
|
|
10785
11501
|
});
|
|
10786
11502
|
folders.command("create").description("Create a teamspace folder").requiredOption("--name <name>", "folder name").option("--order <n>", "folder order", parseNonNegativeInteger3).option("--props <json>", "folder properties payload").option("--props-file <path>", "path to a folder properties JSON payload").action(async function action(commandOptions) {
|
|
10787
11503
|
const { api, json, readOnly } = createTeamspaceApi(this, filePath);
|
|
10788
|
-
|
|
11504
|
+
ensureWritable9("teamspace folders create", readOnly, "write");
|
|
10789
11505
|
const data = await api.createFolder(buildFolderCreateInput(commandOptions));
|
|
10790
11506
|
if (json) {
|
|
10791
|
-
|
|
11507
|
+
emitJson12(stdout, "teamspace folders create", data, filePath);
|
|
10792
11508
|
return;
|
|
10793
11509
|
}
|
|
10794
|
-
|
|
11510
|
+
writeLine12(stdout, `Created folder "${getFolderIdentifier(data)}".`);
|
|
10795
11511
|
});
|
|
10796
|
-
folders.command("update").description("Update a teamspace folder").argument("<folder>", "folder UUID or exact name",
|
|
11512
|
+
folders.command("update").description("Update a teamspace folder").argument("<folder>", "folder UUID or exact name", parseUuidOrSlugSelector10).option("--name <name>", "folder name").option("--order <n>", "folder order", parseNonNegativeInteger3).option("--props <json>", "folder properties payload").option("--props-file <path>", "path to a folder properties JSON payload").action(async function action(folder, commandOptions) {
|
|
10797
11513
|
const { api, json, readOnly } = createTeamspaceApi(this, filePath);
|
|
10798
|
-
|
|
11514
|
+
ensureWritable9("teamspace folders update", readOnly, "write");
|
|
10799
11515
|
const resolvedFolder = await resolveFolderSelector2(api, folder);
|
|
10800
11516
|
const data = await api.updateFolder(resolvedFolder, buildFolderUpdateInput(commandOptions));
|
|
10801
11517
|
if (json) {
|
|
10802
|
-
|
|
11518
|
+
emitJson12(stdout, "teamspace folders update", data, filePath);
|
|
10803
11519
|
return;
|
|
10804
11520
|
}
|
|
10805
|
-
|
|
11521
|
+
writeLine12(stdout, `Updated folder "${getFolderIdentifier(data)}".`);
|
|
10806
11522
|
});
|
|
10807
|
-
folders.command("delete").description("Delete a teamspace folder").argument("<folder>", "folder UUID or exact name",
|
|
11523
|
+
folders.command("delete").description("Delete a teamspace folder").argument("<folder>", "folder UUID or exact name", parseUuidOrSlugSelector10).action(async function action(folder) {
|
|
10808
11524
|
const { api, json, readOnly } = createTeamspaceApi(this, filePath);
|
|
10809
|
-
|
|
11525
|
+
ensureWritable9("teamspace folders delete", readOnly, "destructive");
|
|
10810
11526
|
const resolvedFolder = await resolveFolderSelector2(api, folder);
|
|
10811
11527
|
const data = await api.deleteFolder(resolvedFolder);
|
|
10812
11528
|
if (json) {
|
|
10813
|
-
|
|
11529
|
+
emitJson12(stdout, "teamspace folders delete", data, filePath);
|
|
10814
11530
|
return;
|
|
10815
11531
|
}
|
|
10816
|
-
|
|
11532
|
+
writeLine12(stdout, `Deleted folder "${resolvedFolder.value}".`);
|
|
10817
11533
|
});
|
|
10818
11534
|
const resources = teamspace.command("resources").description("Manage teamspace resources");
|
|
10819
|
-
resources.command("publish").description("Publish a resource to a teamspace folder").argument("<resource>", "resource UUID or exact name",
|
|
11535
|
+
resources.command("publish").description("Publish a resource to a teamspace folder").argument("<resource>", "resource UUID or exact name", parseUuidOrSlugSelector10).requiredOption("--to <folder>", "target folder", parseUuidOrSlugSelector10).action(async function action(resource, commandOptions) {
|
|
10820
11536
|
const { api, json, readOnly } = createTeamspaceApi(this, filePath);
|
|
10821
|
-
|
|
11537
|
+
ensureWritable9("teamspace resources publish", readOnly, "write");
|
|
10822
11538
|
const folder = await resolveFolderSelector2(api, commandOptions.to);
|
|
10823
11539
|
const data = await api.publishResource({
|
|
10824
11540
|
resourceId: resource.value,
|
|
10825
11541
|
targetFolderId: folder.value
|
|
10826
11542
|
});
|
|
10827
11543
|
if (json) {
|
|
10828
|
-
|
|
11544
|
+
emitJson12(stdout, "teamspace resources publish", data, filePath);
|
|
10829
11545
|
return;
|
|
10830
11546
|
}
|
|
10831
|
-
|
|
11547
|
+
writeLine12(stdout, `Published resource "${resource.value}" to folder "${folder.value}".`);
|
|
10832
11548
|
});
|
|
10833
|
-
resources.command("unpublish").description("Unpublish a resource from teamspace").argument("<resource>", "resource UUID or exact name",
|
|
11549
|
+
resources.command("unpublish").description("Unpublish a resource from teamspace").argument("<resource>", "resource UUID or exact name", parseUuidOrSlugSelector10).action(async function action(resource) {
|
|
10834
11550
|
const { api, json, readOnly } = createTeamspaceApi(this, filePath);
|
|
10835
|
-
|
|
11551
|
+
ensureWritable9("teamspace resources unpublish", readOnly, "write");
|
|
10836
11552
|
const data = await api.unpublishResource(resource.value);
|
|
10837
11553
|
if (json) {
|
|
10838
|
-
|
|
11554
|
+
emitJson12(stdout, "teamspace resources unpublish", data, filePath);
|
|
10839
11555
|
return;
|
|
10840
11556
|
}
|
|
10841
|
-
|
|
11557
|
+
writeLine12(stdout, `Unpublished resource "${resource.value}".`);
|
|
10842
11558
|
});
|
|
10843
11559
|
}
|
|
10844
11560
|
|
|
@@ -10846,12 +11562,13 @@ function registerTeamspaceCommands(program, options = {}) {
|
|
|
10846
11562
|
var require2 = createRequire(import.meta.url);
|
|
10847
11563
|
var { version } = require2("../package.json");
|
|
10848
11564
|
function buildProgram(options = {}) {
|
|
10849
|
-
const program = new
|
|
11565
|
+
const program = new Command11();
|
|
10850
11566
|
program.name("zinkee").description("CLI for Zinkee API v2").version(version).enablePositionalOptions().showHelpAfterError().option("--profile <name>", "select a profile from config").option("--base-url <url>", "override the configured base URL").option("--api-key <token>", "override the configured API key").option("--read-only", "run in read-only mode").option("--example", "show examples for a command").option("--json", "emit JSON output").option("--install-completion [shell]", "install shell completion (bash, zsh, fish, powershell)").option("--show-completion [shell]", "print shell completion script for the current shell");
|
|
10851
11567
|
registerProfilesCommands(program, options);
|
|
10852
11568
|
registerAutomationsCommands(program, options);
|
|
10853
11569
|
registerConfigCommands(program, options);
|
|
10854
11570
|
registerDisplaysCommands(program, options);
|
|
11571
|
+
registerDocumentTemplatesCommands(program, options);
|
|
10855
11572
|
registerFilesCommands(program, options);
|
|
10856
11573
|
registerNavigationCommands(program, options);
|
|
10857
11574
|
registerSchemasCommands(program, options);
|
|
@@ -10996,9 +11713,9 @@ function getCompletions(program, request, deps = {}) {
|
|
|
10996
11713
|
|
|
10997
11714
|
// src/completion/install.ts
|
|
10998
11715
|
import { execFileSync } from "child_process";
|
|
10999
|
-
import { mkdirSync as mkdirSync2, readFileSync as
|
|
11716
|
+
import { mkdirSync as mkdirSync2, readFileSync as readFileSync11, writeFileSync as writeFileSync4 } from "fs";
|
|
11000
11717
|
import { homedir as homedir2, platform } from "os";
|
|
11001
|
-
import { basename as
|
|
11718
|
+
import { basename as basename3, dirname as dirname2, join as join2 } from "path";
|
|
11002
11719
|
|
|
11003
11720
|
// src/completion/scripts.ts
|
|
11004
11721
|
var PROGRAM = "zinkee";
|
|
@@ -11120,7 +11837,7 @@ function defaultPowerShellProfile(env) {
|
|
|
11120
11837
|
function detectShell(env) {
|
|
11121
11838
|
const fromEnv = env.shellEnv;
|
|
11122
11839
|
if (fromEnv) {
|
|
11123
|
-
const name =
|
|
11840
|
+
const name = basename3(fromEnv).toLowerCase().replace(/\.exe$/, "");
|
|
11124
11841
|
if (name === "bash") {
|
|
11125
11842
|
return "bash";
|
|
11126
11843
|
}
|
|
@@ -11218,7 +11935,7 @@ ${BLOCK_END}
|
|
|
11218
11935
|
}
|
|
11219
11936
|
function readFileOrEmpty(path) {
|
|
11220
11937
|
try {
|
|
11221
|
-
return
|
|
11938
|
+
return readFileSync11(path, "utf8");
|
|
11222
11939
|
} catch (error) {
|
|
11223
11940
|
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") {
|
|
11224
11941
|
return "";
|
|
@@ -11228,7 +11945,7 @@ function readFileOrEmpty(path) {
|
|
|
11228
11945
|
}
|
|
11229
11946
|
function writeFileEnsuringDir(path, content) {
|
|
11230
11947
|
mkdirSync2(dirname2(path), { recursive: true });
|
|
11231
|
-
|
|
11948
|
+
writeFileSync4(path, content, "utf8");
|
|
11232
11949
|
}
|
|
11233
11950
|
function installCompletion(shell, env) {
|
|
11234
11951
|
const target = resolveTarget(shell, env);
|