zinkee 0.1.7 → 0.1.9
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/README.md +43 -17
- package/dist/index.js +205 -344
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/schemas.test.ts +229 -6
- package/src/commands/schemas.ts +31 -0
- package/src/index.test.ts +11 -5
- package/src/utils/examples.test.ts +44 -8
- package/src/utils/examples.ts +447 -66
- package/src/utils/schema-fields.ts +571 -86
- package/.claude/settings.local.json +0 -14
package/dist/index.js
CHANGED
|
@@ -674,13 +674,6 @@ var commandRegistry = {
|
|
|
674
674
|
supportsRaw: true,
|
|
675
675
|
output: writeOutput
|
|
676
676
|
},
|
|
677
|
-
"logs list": {
|
|
678
|
-
command: "logs list",
|
|
679
|
-
accessLevel: "read",
|
|
680
|
-
supportsExample: true,
|
|
681
|
-
supportsRaw: false,
|
|
682
|
-
output: readOutput
|
|
683
|
-
},
|
|
684
677
|
"teamspace folders list": {
|
|
685
678
|
command: "teamspace folders list",
|
|
686
679
|
accessLevel: "read",
|
|
@@ -3724,47 +3717,6 @@ var specificExamples = {
|
|
|
3724
3717
|
{ "type": "TEXT", "value": " for follow up." }
|
|
3725
3718
|
]
|
|
3726
3719
|
}
|
|
3727
|
-
]`
|
|
3728
|
-
}
|
|
3729
|
-
]),
|
|
3730
|
-
"logs list": buildCommandExamples([
|
|
3731
|
-
{
|
|
3732
|
-
description: "List the change history for a record (CREATE entry plus UPDATE entries with before/after values per field).",
|
|
3733
|
-
command: `zinkee --json logs list contacts ${SAMPLE_UUID}`,
|
|
3734
|
-
response: `[
|
|
3735
|
-
{
|
|
3736
|
-
"recordId": "550e8400-e29b-41d4-a716-446655440000",
|
|
3737
|
-
"timestamp": "2026-04-22T10:00:00Z",
|
|
3738
|
-
"changeField": "",
|
|
3739
|
-
"change": {
|
|
3740
|
-
"beforeValue": null,
|
|
3741
|
-
"afterValue": null,
|
|
3742
|
-
"author": "developer@zinkee.com",
|
|
3743
|
-
"operation": "CREATE"
|
|
3744
|
-
}
|
|
3745
|
-
},
|
|
3746
|
-
{
|
|
3747
|
-
"recordId": "550e8400-e29b-41d4-a716-446655440000",
|
|
3748
|
-
"timestamp": "2026-04-22T10:15:00Z",
|
|
3749
|
-
"changeField": "status",
|
|
3750
|
-
"change": {
|
|
3751
|
-
"beforeValue": "1",
|
|
3752
|
-
"afterValue": "2",
|
|
3753
|
-
"author": "developer@zinkee.com",
|
|
3754
|
-
"operation": "UPDATE"
|
|
3755
|
-
}
|
|
3756
|
-
},
|
|
3757
|
-
{
|
|
3758
|
-
"recordId": "550e8400-e29b-41d4-a716-446655440000",
|
|
3759
|
-
"timestamp": "2026-04-22T10:20:00Z",
|
|
3760
|
-
"changeField": "amount",
|
|
3761
|
-
"change": {
|
|
3762
|
-
"beforeValue": "1000.00",
|
|
3763
|
-
"afterValue": "1250.50",
|
|
3764
|
-
"author": "developer@zinkee.com",
|
|
3765
|
-
"operation": "UPDATE"
|
|
3766
|
-
}
|
|
3767
|
-
}
|
|
3768
3720
|
]`
|
|
3769
3721
|
}
|
|
3770
3722
|
]),
|
|
@@ -5065,8 +5017,8 @@ function buildSchemaFieldCreateExamples(type) {
|
|
|
5065
5017
|
}
|
|
5066
5018
|
return [
|
|
5067
5019
|
{
|
|
5068
|
-
description: "Create a
|
|
5069
|
-
command:
|
|
5020
|
+
description: "Create a required number field with a default value",
|
|
5021
|
+
command: "zinkee --json schemas fields create contacts --type number --slug amount --label Amount --required true --default 0"
|
|
5070
5022
|
},
|
|
5071
5023
|
{
|
|
5072
5024
|
description: "Create a number field formatted like Moneda",
|
|
@@ -5665,7 +5617,7 @@ ${index + 1}. ${example.description}
|
|
|
5665
5617
|
|
|
5666
5618
|
// src/program.ts
|
|
5667
5619
|
import { createRequire } from "module";
|
|
5668
|
-
import { Command as
|
|
5620
|
+
import { Command as Command9 } from "commander";
|
|
5669
5621
|
|
|
5670
5622
|
// src/commands/config.ts
|
|
5671
5623
|
function getCommandIo(stdout) {
|
|
@@ -8158,117 +8110,9 @@ function registerFilesCommands(program, options = {}) {
|
|
|
8158
8110
|
});
|
|
8159
8111
|
}
|
|
8160
8112
|
|
|
8161
|
-
// src/commands/logs.ts
|
|
8162
|
-
import { InvalidArgumentError as InvalidArgumentError5 } from "commander";
|
|
8163
|
-
|
|
8164
|
-
// src/api/logs.ts
|
|
8165
|
-
function selectorValue6(selector2) {
|
|
8166
|
-
return selector2.value;
|
|
8167
|
-
}
|
|
8168
|
-
var LogsApi = class {
|
|
8169
|
-
constructor(client) {
|
|
8170
|
-
this.client = client;
|
|
8171
|
-
}
|
|
8172
|
-
listLogs(schema, recordId) {
|
|
8173
|
-
return this.client.getJson(
|
|
8174
|
-
`/api/v2/schemas/${selectorValue6(schema)}/records/${recordId}/logs`
|
|
8175
|
-
);
|
|
8176
|
-
}
|
|
8177
|
-
};
|
|
8178
|
-
|
|
8179
|
-
// src/commands/logs.ts
|
|
8180
|
-
function getCommandIo6(stdout) {
|
|
8181
|
-
return stdout ?? process.stdout;
|
|
8182
|
-
}
|
|
8183
|
-
function writeLine6(stdout, value) {
|
|
8184
|
-
stdout.write(`${value}
|
|
8185
|
-
`);
|
|
8186
|
-
}
|
|
8187
|
-
function getGlobalOptions6(command) {
|
|
8188
|
-
return command.optsWithGlobals();
|
|
8189
|
-
}
|
|
8190
|
-
function emitJson6(stdout, commandName, data, ..._extra) {
|
|
8191
|
-
writeLine6(
|
|
8192
|
-
stdout,
|
|
8193
|
-
JSON.stringify(buildJsonSuccess(data, { command: commandName }))
|
|
8194
|
-
);
|
|
8195
|
-
}
|
|
8196
|
-
function toConfigurationError6(filePath, error) {
|
|
8197
|
-
if (error instanceof CliError) {
|
|
8198
|
-
throw error;
|
|
8199
|
-
}
|
|
8200
|
-
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") {
|
|
8201
|
-
throw new CliError("configuration_error", `Config file not found at ${filePath}.`);
|
|
8202
|
-
}
|
|
8203
|
-
if (error instanceof Error) {
|
|
8204
|
-
throw new CliError("configuration_error", error.message);
|
|
8205
|
-
}
|
|
8206
|
-
throw error;
|
|
8207
|
-
}
|
|
8208
|
-
function createLogsApi(command, filePath) {
|
|
8209
|
-
try {
|
|
8210
|
-
const config = readRuntimeConfig(filePath);
|
|
8211
|
-
const runtime = resolveRuntimeContext(config, getGlobalOptions6(command));
|
|
8212
|
-
if (!runtime.baseUrl) {
|
|
8213
|
-
throw new CliError(
|
|
8214
|
-
"configuration_error",
|
|
8215
|
-
`Resolved profile "${runtime.profile}" is missing a base URL.`
|
|
8216
|
-
);
|
|
8217
|
-
}
|
|
8218
|
-
return {
|
|
8219
|
-
api: new LogsApi(
|
|
8220
|
-
new ApiClient({
|
|
8221
|
-
baseUrl: runtime.baseUrl,
|
|
8222
|
-
apiKey: runtime.apiKey
|
|
8223
|
-
})
|
|
8224
|
-
),
|
|
8225
|
-
json: runtime.json
|
|
8226
|
-
};
|
|
8227
|
-
} catch (error) {
|
|
8228
|
-
toConfigurationError6(filePath, error);
|
|
8229
|
-
}
|
|
8230
|
-
}
|
|
8231
|
-
function parseUuidOrSlugSelector5(input) {
|
|
8232
|
-
try {
|
|
8233
|
-
return normalizeUuidOrSlug(input);
|
|
8234
|
-
} catch (error) {
|
|
8235
|
-
const message = error instanceof Error ? error.message : "Invalid selector.";
|
|
8236
|
-
throw new InvalidArgumentError5(message);
|
|
8237
|
-
}
|
|
8238
|
-
}
|
|
8239
|
-
function isJsonObject4(value) {
|
|
8240
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8241
|
-
}
|
|
8242
|
-
function toTableRows3(data) {
|
|
8243
|
-
if (Array.isArray(data)) {
|
|
8244
|
-
return data.map((entry) => isJsonObject4(entry) ? entry : { value: entry });
|
|
8245
|
-
}
|
|
8246
|
-
if (isJsonObject4(data)) {
|
|
8247
|
-
return [data];
|
|
8248
|
-
}
|
|
8249
|
-
return [{ value: data }];
|
|
8250
|
-
}
|
|
8251
|
-
function emitTable3(stdout, data) {
|
|
8252
|
-
printTable(toTableRows3(data), void 0, stdout);
|
|
8253
|
-
}
|
|
8254
|
-
function registerLogsCommands(program, options = {}) {
|
|
8255
|
-
const filePath = options.configPath ?? defaultConfigPath;
|
|
8256
|
-
const stdout = getCommandIo6(options.stdout);
|
|
8257
|
-
const logs = program.command("logs").description("Inspect record change logs");
|
|
8258
|
-
logs.command("list").description("List change logs for a record").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector5).argument("<record>", "record uuid or slug", parseUuidOrSlugSelector5).action(async function action(schema, record) {
|
|
8259
|
-
const { api, json } = createLogsApi(this, filePath);
|
|
8260
|
-
const data = await api.listLogs(schema, record.value);
|
|
8261
|
-
if (json) {
|
|
8262
|
-
emitJson6(stdout, "logs list", data, filePath);
|
|
8263
|
-
return;
|
|
8264
|
-
}
|
|
8265
|
-
emitTable3(stdout, data);
|
|
8266
|
-
});
|
|
8267
|
-
}
|
|
8268
|
-
|
|
8269
8113
|
// src/commands/navigation.ts
|
|
8270
8114
|
import { readFileSync as readFileSync6 } from "fs";
|
|
8271
|
-
import { InvalidArgumentError as
|
|
8115
|
+
import { InvalidArgumentError as InvalidArgumentError5 } from "commander";
|
|
8272
8116
|
|
|
8273
8117
|
// src/api/navigation.ts
|
|
8274
8118
|
function jsonOptions5(body, method) {
|
|
@@ -8280,7 +8124,7 @@ function jsonOptions5(body, method) {
|
|
|
8280
8124
|
body: JSON.stringify(body)
|
|
8281
8125
|
};
|
|
8282
8126
|
}
|
|
8283
|
-
function
|
|
8127
|
+
function selectorValue6(selector2) {
|
|
8284
8128
|
return selector2.value;
|
|
8285
8129
|
}
|
|
8286
8130
|
var NavigationApi = class {
|
|
@@ -8298,13 +8142,13 @@ var NavigationApi = class {
|
|
|
8298
8142
|
}
|
|
8299
8143
|
updateFolder(folder, body) {
|
|
8300
8144
|
return this.client.requestJson(
|
|
8301
|
-
`/api/v2/navigation/folders/${
|
|
8145
|
+
`/api/v2/navigation/folders/${selectorValue6(folder)}`,
|
|
8302
8146
|
jsonOptions5(body, "PATCH")
|
|
8303
8147
|
);
|
|
8304
8148
|
}
|
|
8305
8149
|
deleteFolder(folder) {
|
|
8306
8150
|
return this.client.requestJson(
|
|
8307
|
-
`/api/v2/navigation/folders/${
|
|
8151
|
+
`/api/v2/navigation/folders/${selectorValue6(folder)}`,
|
|
8308
8152
|
{ method: "DELETE" }
|
|
8309
8153
|
);
|
|
8310
8154
|
}
|
|
@@ -8317,20 +8161,20 @@ var NavigationApi = class {
|
|
|
8317
8161
|
};
|
|
8318
8162
|
|
|
8319
8163
|
// src/commands/navigation.ts
|
|
8320
|
-
function
|
|
8164
|
+
function getCommandIo6(stdout) {
|
|
8321
8165
|
return stdout ?? process.stdout;
|
|
8322
8166
|
}
|
|
8323
|
-
function
|
|
8167
|
+
function writeLine6(stdout, value) {
|
|
8324
8168
|
stdout.write(`${value}
|
|
8325
8169
|
`);
|
|
8326
8170
|
}
|
|
8327
|
-
function
|
|
8171
|
+
function getGlobalOptions6(command) {
|
|
8328
8172
|
return command.optsWithGlobals();
|
|
8329
8173
|
}
|
|
8330
|
-
function
|
|
8331
|
-
|
|
8174
|
+
function emitJson6(stdout, commandName, data, configPath) {
|
|
8175
|
+
writeLine6(stdout, JSON.stringify(buildJsonSuccess(data, { command: commandName, configPath })));
|
|
8332
8176
|
}
|
|
8333
|
-
function
|
|
8177
|
+
function toConfigurationError6(filePath, error) {
|
|
8334
8178
|
if (error instanceof CliError) {
|
|
8335
8179
|
throw error;
|
|
8336
8180
|
}
|
|
@@ -8345,7 +8189,7 @@ function toConfigurationError7(filePath, error) {
|
|
|
8345
8189
|
function createNavigationApi(command, filePath) {
|
|
8346
8190
|
try {
|
|
8347
8191
|
const config = readRuntimeConfig(filePath);
|
|
8348
|
-
const runtime = resolveRuntimeContext(config,
|
|
8192
|
+
const runtime = resolveRuntimeContext(config, getGlobalOptions6(command));
|
|
8349
8193
|
if (!runtime.baseUrl) {
|
|
8350
8194
|
throw new CliError("configuration_error", `Resolved profile "${runtime.profile}" is missing a base URL.`);
|
|
8351
8195
|
}
|
|
@@ -8360,7 +8204,7 @@ function createNavigationApi(command, filePath) {
|
|
|
8360
8204
|
readOnly: runtime.readOnly
|
|
8361
8205
|
};
|
|
8362
8206
|
} catch (error) {
|
|
8363
|
-
|
|
8207
|
+
toConfigurationError6(filePath, error);
|
|
8364
8208
|
}
|
|
8365
8209
|
}
|
|
8366
8210
|
function ensureWritable5(commandName, readOnly, mode) {
|
|
@@ -8372,12 +8216,12 @@ function ensureWritable5(commandName, readOnly, mode) {
|
|
|
8372
8216
|
);
|
|
8373
8217
|
}
|
|
8374
8218
|
}
|
|
8375
|
-
function
|
|
8219
|
+
function parseUuidOrSlugSelector5(input) {
|
|
8376
8220
|
try {
|
|
8377
8221
|
return normalizeUuidOrSlug(input);
|
|
8378
8222
|
} catch (error) {
|
|
8379
8223
|
const message = error instanceof Error ? error.message : "Invalid selector.";
|
|
8380
|
-
throw new
|
|
8224
|
+
throw new InvalidArgumentError5(message);
|
|
8381
8225
|
}
|
|
8382
8226
|
}
|
|
8383
8227
|
function parseInteger(value, flagName) {
|
|
@@ -8456,24 +8300,24 @@ function folderRows2(folders) {
|
|
|
8456
8300
|
}
|
|
8457
8301
|
function registerNavigationCommands(program, options = {}) {
|
|
8458
8302
|
const filePath = options.configPath ?? defaultConfigPath;
|
|
8459
|
-
const stdout =
|
|
8303
|
+
const stdout = getCommandIo6(options.stdout);
|
|
8460
8304
|
const navigation = program.command("navigation").description("Manage workspace navigation");
|
|
8461
8305
|
const folders = navigation.command("folders").description("Manage navigation folders");
|
|
8462
8306
|
folders.command("list").description("List navigation folders").action(async function action() {
|
|
8463
8307
|
const { api, json } = createNavigationApi(this, filePath);
|
|
8464
8308
|
const data = await api.listFolders();
|
|
8465
8309
|
if (json) {
|
|
8466
|
-
|
|
8310
|
+
emitJson6(stdout, "navigation folders list", data, filePath);
|
|
8467
8311
|
return;
|
|
8468
8312
|
}
|
|
8469
8313
|
printTable(folderRows2(data), ["id", "order", "name", "resourceCount"], stdout);
|
|
8470
8314
|
});
|
|
8471
|
-
folders.command("get").description("Get a navigation folder by UUID or exact name").argument("<folder>", "folder UUID or exact name",
|
|
8315
|
+
folders.command("get").description("Get a navigation folder by UUID or exact name").argument("<folder>", "folder UUID or exact name", parseUuidOrSlugSelector5).action(async function action(folder) {
|
|
8472
8316
|
const { api, json } = createNavigationApi(this, filePath);
|
|
8473
8317
|
const data = await api.listFolders();
|
|
8474
8318
|
const resolved = resolveFolder2(data, folder);
|
|
8475
8319
|
if (json) {
|
|
8476
|
-
|
|
8320
|
+
emitJson6(stdout, "navigation folders get", resolved, filePath);
|
|
8477
8321
|
return;
|
|
8478
8322
|
}
|
|
8479
8323
|
printTable(folderRows2([resolved]), ["id", "order", "name", "resourceCount"], stdout);
|
|
@@ -8483,12 +8327,12 @@ function registerNavigationCommands(program, options = {}) {
|
|
|
8483
8327
|
ensureWritable5("navigation folders create", readOnly, "write");
|
|
8484
8328
|
const data = await api.createFolder(buildFolderBody(commandOptions));
|
|
8485
8329
|
if (json) {
|
|
8486
|
-
|
|
8330
|
+
emitJson6(stdout, "navigation folders create", data, filePath);
|
|
8487
8331
|
return;
|
|
8488
8332
|
}
|
|
8489
|
-
|
|
8333
|
+
writeLine6(stdout, `Created navigation folder "${String(data.name ?? commandOptions.name)}".`);
|
|
8490
8334
|
});
|
|
8491
|
-
folders.command("update").description("Update a navigation folder").argument("<folder>", "folder UUID or exact name",
|
|
8335
|
+
folders.command("update").description("Update a navigation folder").argument("<folder>", "folder UUID or exact name", parseUuidOrSlugSelector5).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) {
|
|
8492
8336
|
const { api, json, readOnly } = createNavigationApi(this, filePath);
|
|
8493
8337
|
ensureWritable5("navigation folders update", readOnly, "write");
|
|
8494
8338
|
const allFolders = await api.listFolders();
|
|
@@ -8499,54 +8343,54 @@ function registerNavigationCommands(program, options = {}) {
|
|
|
8499
8343
|
}
|
|
8500
8344
|
const data = await api.updateFolder({ kind: "uuid", value: resolved.id }, body);
|
|
8501
8345
|
if (json) {
|
|
8502
|
-
|
|
8346
|
+
emitJson6(stdout, "navigation folders update", data, filePath);
|
|
8503
8347
|
return;
|
|
8504
8348
|
}
|
|
8505
|
-
|
|
8349
|
+
writeLine6(stdout, `Updated navigation folder "${String(data.name ?? resolved.name ?? resolved.id)}".`);
|
|
8506
8350
|
});
|
|
8507
|
-
folders.command("delete").description("Delete a navigation folder").argument("<folder>", "folder UUID or exact name",
|
|
8351
|
+
folders.command("delete").description("Delete a navigation folder").argument("<folder>", "folder UUID or exact name", parseUuidOrSlugSelector5).action(async function action(folder) {
|
|
8508
8352
|
const { api, json, readOnly } = createNavigationApi(this, filePath);
|
|
8509
8353
|
ensureWritable5("navigation folders delete", readOnly, "destructive");
|
|
8510
8354
|
const allFolders = await api.listFolders();
|
|
8511
8355
|
const resolved = resolveFolder2(allFolders, folder);
|
|
8512
8356
|
const data = await api.deleteFolder({ kind: "uuid", value: resolved.id });
|
|
8513
8357
|
if (json) {
|
|
8514
|
-
|
|
8358
|
+
emitJson6(stdout, "navigation folders delete", data, filePath);
|
|
8515
8359
|
return;
|
|
8516
8360
|
}
|
|
8517
|
-
|
|
8361
|
+
writeLine6(stdout, `Deleted navigation folder "${resolved.name ?? resolved.id}".`);
|
|
8518
8362
|
});
|
|
8519
8363
|
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) {
|
|
8520
8364
|
const { api, json, readOnly } = createNavigationApi(this, filePath);
|
|
8521
8365
|
ensureWritable5("navigation resources move", readOnly, "write");
|
|
8522
8366
|
const allFolders = await api.listFolders();
|
|
8523
|
-
const resolved = resolveFolder2(allFolders,
|
|
8367
|
+
const resolved = resolveFolder2(allFolders, parseUuidOrSlugSelector5(commandOptions.to));
|
|
8524
8368
|
const data = await api.moveResource({
|
|
8525
8369
|
resourceId,
|
|
8526
8370
|
resourceType: commandOptions.type.toUpperCase(),
|
|
8527
8371
|
targetFolderId: resolved.id
|
|
8528
8372
|
});
|
|
8529
8373
|
if (json) {
|
|
8530
|
-
|
|
8374
|
+
emitJson6(stdout, "navigation resources move", data, filePath);
|
|
8531
8375
|
return;
|
|
8532
8376
|
}
|
|
8533
|
-
|
|
8377
|
+
writeLine6(stdout, `Moved resource "${resourceId}" to "${resolved.name ?? resolved.id}".`);
|
|
8534
8378
|
});
|
|
8535
8379
|
}
|
|
8536
8380
|
|
|
8537
8381
|
// src/commands/profiles.ts
|
|
8538
|
-
function
|
|
8382
|
+
function getCommandIo7(stdout) {
|
|
8539
8383
|
return stdout ?? process.stdout;
|
|
8540
8384
|
}
|
|
8541
|
-
function
|
|
8385
|
+
function writeLine7(stdout, value) {
|
|
8542
8386
|
stdout.write(`${value}
|
|
8543
8387
|
`);
|
|
8544
8388
|
}
|
|
8545
|
-
function
|
|
8389
|
+
function getGlobalOptions7(command) {
|
|
8546
8390
|
return command.optsWithGlobals();
|
|
8547
8391
|
}
|
|
8548
|
-
function
|
|
8549
|
-
|
|
8392
|
+
function emitJson7(stdout, commandName, data, configPath) {
|
|
8393
|
+
writeLine7(
|
|
8550
8394
|
stdout,
|
|
8551
8395
|
JSON.stringify(buildJsonSuccess(data, { command: commandName, configPath }))
|
|
8552
8396
|
);
|
|
@@ -8589,15 +8433,15 @@ function emitProfilesTable(stdout, data) {
|
|
|
8589
8433
|
}
|
|
8590
8434
|
function registerProfilesCommands(program, options = {}) {
|
|
8591
8435
|
const filePath = options.configPath ?? defaultConfigPath;
|
|
8592
|
-
const stdout =
|
|
8436
|
+
const stdout = getCommandIo7(options.stdout);
|
|
8593
8437
|
const profiles = program.command("profiles").description("Manage local CLI profiles");
|
|
8594
8438
|
profiles.command("list").description("List configured profiles").action(function action() {
|
|
8595
8439
|
const config = readRequiredConfig(filePath);
|
|
8596
8440
|
const data = Object.entries(config.profiles).map(
|
|
8597
8441
|
([name, profile]) => toDisplayProfile(name, profile, config.defaultProfile)
|
|
8598
8442
|
);
|
|
8599
|
-
if (
|
|
8600
|
-
|
|
8443
|
+
if (getGlobalOptions7(this).json) {
|
|
8444
|
+
emitJson7(stdout, "profiles list", data, filePath);
|
|
8601
8445
|
return;
|
|
8602
8446
|
}
|
|
8603
8447
|
emitProfilesTable(stdout, data);
|
|
@@ -8606,8 +8450,8 @@ function registerProfilesCommands(program, options = {}) {
|
|
|
8606
8450
|
const config = readRequiredConfig(filePath);
|
|
8607
8451
|
const profile = getRequiredProfile(config, profileName);
|
|
8608
8452
|
const data = toDisplayProfile(profileName, profile, config.defaultProfile);
|
|
8609
|
-
if (
|
|
8610
|
-
|
|
8453
|
+
if (getGlobalOptions7(this).json) {
|
|
8454
|
+
emitJson7(stdout, "profiles get", data, filePath);
|
|
8611
8455
|
return;
|
|
8612
8456
|
}
|
|
8613
8457
|
emitProfilesTable(stdout, [data]);
|
|
@@ -8621,11 +8465,11 @@ function registerProfilesCommands(program, options = {}) {
|
|
|
8621
8465
|
profile: profileName,
|
|
8622
8466
|
defaultProfile: nextConfig.defaultProfile
|
|
8623
8467
|
};
|
|
8624
|
-
if (
|
|
8625
|
-
|
|
8468
|
+
if (getGlobalOptions7(this).json) {
|
|
8469
|
+
emitJson7(stdout, "profiles use", data, filePath);
|
|
8626
8470
|
return;
|
|
8627
8471
|
}
|
|
8628
|
-
|
|
8472
|
+
writeLine7(stdout, `Using profile "${profileName}".`);
|
|
8629
8473
|
});
|
|
8630
8474
|
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) {
|
|
8631
8475
|
const config = loadConfigForAdd(filePath);
|
|
@@ -8648,11 +8492,11 @@ function registerProfilesCommands(program, options = {}) {
|
|
|
8648
8492
|
nextConfig.profiles[profileName] ?? {},
|
|
8649
8493
|
nextConfig.defaultProfile
|
|
8650
8494
|
);
|
|
8651
|
-
if (
|
|
8652
|
-
|
|
8495
|
+
if (getGlobalOptions7(this).json) {
|
|
8496
|
+
emitJson7(stdout, "profiles add", data, filePath);
|
|
8653
8497
|
return;
|
|
8654
8498
|
}
|
|
8655
|
-
|
|
8499
|
+
writeLine7(stdout, `Added profile "${profileName}".`);
|
|
8656
8500
|
});
|
|
8657
8501
|
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) {
|
|
8658
8502
|
if (commandOptions.apiKey === void 0 && commandOptions.baseUrl === void 0) {
|
|
@@ -8673,11 +8517,11 @@ function registerProfilesCommands(program, options = {}) {
|
|
|
8673
8517
|
nextConfig.profiles[profileName] ?? {},
|
|
8674
8518
|
nextConfig.defaultProfile
|
|
8675
8519
|
);
|
|
8676
|
-
if (
|
|
8677
|
-
|
|
8520
|
+
if (getGlobalOptions7(this).json) {
|
|
8521
|
+
emitJson7(stdout, "profiles update", data, filePath);
|
|
8678
8522
|
return;
|
|
8679
8523
|
}
|
|
8680
|
-
|
|
8524
|
+
writeLine7(stdout, `Updated profile "${profileName}".`);
|
|
8681
8525
|
});
|
|
8682
8526
|
profiles.command("remove").description("Remove a profile from the local config").argument("<profile>", "profile name").action(function action(profileName) {
|
|
8683
8527
|
const config = readRequiredConfig(filePath);
|
|
@@ -8688,17 +8532,17 @@ function registerProfilesCommands(program, options = {}) {
|
|
|
8688
8532
|
profile: profileName,
|
|
8689
8533
|
defaultProfile: nextConfig.defaultProfile
|
|
8690
8534
|
};
|
|
8691
|
-
if (
|
|
8692
|
-
|
|
8535
|
+
if (getGlobalOptions7(this).json) {
|
|
8536
|
+
emitJson7(stdout, "profiles remove", data, filePath);
|
|
8693
8537
|
return;
|
|
8694
8538
|
}
|
|
8695
|
-
|
|
8539
|
+
writeLine7(stdout, `Removed profile "${profileName}".`);
|
|
8696
8540
|
});
|
|
8697
8541
|
}
|
|
8698
8542
|
|
|
8699
8543
|
// src/commands/records.ts
|
|
8700
8544
|
import { readFileSync as readFileSync7 } from "fs";
|
|
8701
|
-
import { InvalidArgumentError as
|
|
8545
|
+
import { InvalidArgumentError as InvalidArgumentError6 } from "commander";
|
|
8702
8546
|
|
|
8703
8547
|
// src/api/records.ts
|
|
8704
8548
|
function jsonOptions6(body, method) {
|
|
@@ -8710,7 +8554,7 @@ function jsonOptions6(body, method) {
|
|
|
8710
8554
|
body: JSON.stringify(body)
|
|
8711
8555
|
};
|
|
8712
8556
|
}
|
|
8713
|
-
function
|
|
8557
|
+
function selectorValue7(selector2) {
|
|
8714
8558
|
return selector2.value;
|
|
8715
8559
|
}
|
|
8716
8560
|
var RecordsApi = class {
|
|
@@ -8725,7 +8569,7 @@ var RecordsApi = class {
|
|
|
8725
8569
|
if (query.offset !== void 0) {
|
|
8726
8570
|
params.set("offset", String(query.offset));
|
|
8727
8571
|
}
|
|
8728
|
-
const path = `/api/v2/schemas/${
|
|
8572
|
+
const path = `/api/v2/schemas/${selectorValue7(schema)}/records`;
|
|
8729
8573
|
const queryString = params.toString();
|
|
8730
8574
|
return this.client.getJson(
|
|
8731
8575
|
queryString ? `${path}?${queryString}` : path
|
|
@@ -8734,30 +8578,30 @@ var RecordsApi = class {
|
|
|
8734
8578
|
queryRecords(schema, query) {
|
|
8735
8579
|
const body = this.normalizeQueryInput(query);
|
|
8736
8580
|
return this.client.requestJson(
|
|
8737
|
-
`/api/v2/schemas/${
|
|
8581
|
+
`/api/v2/schemas/${selectorValue7(schema)}/records:query`,
|
|
8738
8582
|
jsonOptions6(body, "POST")
|
|
8739
8583
|
);
|
|
8740
8584
|
}
|
|
8741
8585
|
getRecord(schema, record) {
|
|
8742
8586
|
return this.client.getJson(
|
|
8743
|
-
`/api/v2/schemas/${
|
|
8587
|
+
`/api/v2/schemas/${selectorValue7(schema)}/records/${selectorValue7(record)}`
|
|
8744
8588
|
);
|
|
8745
8589
|
}
|
|
8746
8590
|
createRecord(schema, input) {
|
|
8747
8591
|
return this.client.requestJson(
|
|
8748
|
-
`/api/v2/schemas/${
|
|
8592
|
+
`/api/v2/schemas/${selectorValue7(schema)}/records`,
|
|
8749
8593
|
jsonOptions6(input, "POST")
|
|
8750
8594
|
);
|
|
8751
8595
|
}
|
|
8752
8596
|
updateRecord(schema, record, input) {
|
|
8753
8597
|
return this.client.requestJson(
|
|
8754
|
-
`/api/v2/schemas/${
|
|
8598
|
+
`/api/v2/schemas/${selectorValue7(schema)}/records/${selectorValue7(record)}`,
|
|
8755
8599
|
jsonOptions6(input, "PATCH")
|
|
8756
8600
|
);
|
|
8757
8601
|
}
|
|
8758
8602
|
deleteRecord(schema, record) {
|
|
8759
8603
|
return this.client.requestJson(
|
|
8760
|
-
`/api/v2/schemas/${
|
|
8604
|
+
`/api/v2/schemas/${selectorValue7(schema)}/records/${selectorValue7(record)}`,
|
|
8761
8605
|
{ method: "DELETE" }
|
|
8762
8606
|
);
|
|
8763
8607
|
}
|
|
@@ -8870,23 +8714,23 @@ function parseExpression(input) {
|
|
|
8870
8714
|
}
|
|
8871
8715
|
|
|
8872
8716
|
// src/commands/records.ts
|
|
8873
|
-
function
|
|
8717
|
+
function getCommandIo8(stdout) {
|
|
8874
8718
|
return stdout ?? process.stdout;
|
|
8875
8719
|
}
|
|
8876
|
-
function
|
|
8720
|
+
function writeLine8(stdout, value) {
|
|
8877
8721
|
stdout.write(`${value}
|
|
8878
8722
|
`);
|
|
8879
8723
|
}
|
|
8880
|
-
function
|
|
8724
|
+
function getGlobalOptions8(command) {
|
|
8881
8725
|
return command.optsWithGlobals();
|
|
8882
8726
|
}
|
|
8883
|
-
function
|
|
8884
|
-
|
|
8727
|
+
function emitJson8(stdout, commandName, data, configPath, meta = {}) {
|
|
8728
|
+
writeLine8(
|
|
8885
8729
|
stdout,
|
|
8886
8730
|
JSON.stringify(buildJsonSuccess(data, { command: commandName, configPath, ...meta }))
|
|
8887
8731
|
);
|
|
8888
8732
|
}
|
|
8889
|
-
function
|
|
8733
|
+
function toConfigurationError7(filePath, error) {
|
|
8890
8734
|
if (error instanceof CliError) {
|
|
8891
8735
|
throw error;
|
|
8892
8736
|
}
|
|
@@ -8901,7 +8745,7 @@ function toConfigurationError8(filePath, error) {
|
|
|
8901
8745
|
function createRecordsApi(command, filePath) {
|
|
8902
8746
|
try {
|
|
8903
8747
|
const config = readRuntimeConfig(filePath);
|
|
8904
|
-
const runtime = resolveRuntimeContext(config,
|
|
8748
|
+
const runtime = resolveRuntimeContext(config, getGlobalOptions8(command));
|
|
8905
8749
|
if (!runtime.baseUrl) {
|
|
8906
8750
|
throw new CliError(
|
|
8907
8751
|
"configuration_error",
|
|
@@ -8920,7 +8764,7 @@ function createRecordsApi(command, filePath) {
|
|
|
8920
8764
|
readOnly: runtime.readOnly
|
|
8921
8765
|
};
|
|
8922
8766
|
} catch (error) {
|
|
8923
|
-
|
|
8767
|
+
toConfigurationError7(filePath, error);
|
|
8924
8768
|
}
|
|
8925
8769
|
}
|
|
8926
8770
|
function ensureWritable6(commandName, readOnly, commandMode) {
|
|
@@ -8935,24 +8779,24 @@ function ensureWritable6(commandName, readOnly, commandMode) {
|
|
|
8935
8779
|
);
|
|
8936
8780
|
}
|
|
8937
8781
|
}
|
|
8938
|
-
function
|
|
8782
|
+
function parseUuidOrSlugSelector6(input) {
|
|
8939
8783
|
try {
|
|
8940
8784
|
return normalizeUuidOrSlug(input);
|
|
8941
8785
|
} catch (error) {
|
|
8942
8786
|
const message = error instanceof Error ? error.message : "Invalid selector.";
|
|
8943
|
-
throw new
|
|
8787
|
+
throw new InvalidArgumentError6(message);
|
|
8944
8788
|
}
|
|
8945
8789
|
}
|
|
8946
8790
|
function parseNonNegativeInteger2(input) {
|
|
8947
8791
|
if (!/^\d+$/.test(input.trim())) {
|
|
8948
|
-
throw new
|
|
8792
|
+
throw new InvalidArgumentError6(`Expected a non-negative integer, received "${input}".`);
|
|
8949
8793
|
}
|
|
8950
8794
|
return Number(input);
|
|
8951
8795
|
}
|
|
8952
8796
|
function parseCommaSeparatedValues(input, label) {
|
|
8953
8797
|
const values = input.split(",").map((value) => value.trim()).filter(Boolean);
|
|
8954
8798
|
if (values.length === 0) {
|
|
8955
|
-
throw new
|
|
8799
|
+
throw new InvalidArgumentError6(`Expected ${label} to contain at least one value.`);
|
|
8956
8800
|
}
|
|
8957
8801
|
return values;
|
|
8958
8802
|
}
|
|
@@ -8961,7 +8805,7 @@ function parseExpressionValue(input) {
|
|
|
8961
8805
|
return parseExpression(input);
|
|
8962
8806
|
} catch (error) {
|
|
8963
8807
|
const message = error instanceof Error ? error.message : "Invalid expression.";
|
|
8964
|
-
throw new
|
|
8808
|
+
throw new InvalidArgumentError6(message);
|
|
8965
8809
|
}
|
|
8966
8810
|
}
|
|
8967
8811
|
function parseKeyValueAssignment(input) {
|
|
@@ -8969,7 +8813,7 @@ function parseKeyValueAssignment(input) {
|
|
|
8969
8813
|
return parseKeyValue(input);
|
|
8970
8814
|
} catch (error) {
|
|
8971
8815
|
const message = error instanceof Error ? error.message : "Invalid assignment.";
|
|
8972
|
-
throw new
|
|
8816
|
+
throw new InvalidArgumentError6(message);
|
|
8973
8817
|
}
|
|
8974
8818
|
}
|
|
8975
8819
|
function parseJsonKeyValueAssignment(input) {
|
|
@@ -8977,7 +8821,7 @@ function parseJsonKeyValueAssignment(input) {
|
|
|
8977
8821
|
return parseJsonAssignment(input);
|
|
8978
8822
|
} catch (error) {
|
|
8979
8823
|
const message = error instanceof Error ? error.message : "Invalid JSON assignment.";
|
|
8980
|
-
throw new
|
|
8824
|
+
throw new InvalidArgumentError6(message);
|
|
8981
8825
|
}
|
|
8982
8826
|
}
|
|
8983
8827
|
function collectStringValues(value, previous = []) {
|
|
@@ -8995,7 +8839,7 @@ function collectKeyValueAssignments(value, previous = []) {
|
|
|
8995
8839
|
function collectJsonAssignments(value, previous = []) {
|
|
8996
8840
|
return [...previous, parseJsonKeyValueAssignment(value)];
|
|
8997
8841
|
}
|
|
8998
|
-
function
|
|
8842
|
+
function isJsonObject4(value) {
|
|
8999
8843
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9000
8844
|
}
|
|
9001
8845
|
function parseRawJsonObject2(input, sourceLabel) {
|
|
@@ -9009,7 +8853,7 @@ function parseRawJsonObject2(input, sourceLabel) {
|
|
|
9009
8853
|
`Failed to parse JSON from ${sourceLabel}: ${message}`
|
|
9010
8854
|
);
|
|
9011
8855
|
}
|
|
9012
|
-
if (!
|
|
8856
|
+
if (!isJsonObject4(parsed)) {
|
|
9013
8857
|
throw new CliError(
|
|
9014
8858
|
"invalid_cli_usage",
|
|
9015
8859
|
`Expected ${sourceLabel} to contain a JSON object.`
|
|
@@ -9103,7 +8947,7 @@ function readRawSetPayload2(raw) {
|
|
|
9103
8947
|
if (setValue === void 0) {
|
|
9104
8948
|
return {};
|
|
9105
8949
|
}
|
|
9106
|
-
if (!
|
|
8950
|
+
if (!isJsonObject4(setValue)) {
|
|
9107
8951
|
throw new CliError(
|
|
9108
8952
|
"invalid_cli_usage",
|
|
9109
8953
|
'Expected raw update payload field "set" to be a JSON object.'
|
|
@@ -9156,17 +9000,17 @@ function buildRecordUpdateInput(options) {
|
|
|
9156
9000
|
}
|
|
9157
9001
|
return input;
|
|
9158
9002
|
}
|
|
9159
|
-
function
|
|
9003
|
+
function toTableRows3(data) {
|
|
9160
9004
|
if (Array.isArray(data)) {
|
|
9161
|
-
return data.map((entry) =>
|
|
9005
|
+
return data.map((entry) => isJsonObject4(entry) ? entry : { value: entry });
|
|
9162
9006
|
}
|
|
9163
|
-
if (
|
|
9007
|
+
if (isJsonObject4(data)) {
|
|
9164
9008
|
return [data];
|
|
9165
9009
|
}
|
|
9166
9010
|
return [{ value: data }];
|
|
9167
9011
|
}
|
|
9168
|
-
function
|
|
9169
|
-
printTable(
|
|
9012
|
+
function emitTable3(stdout, data) {
|
|
9013
|
+
printTable(toTableRows3(data), void 0, stdout);
|
|
9170
9014
|
}
|
|
9171
9015
|
function getQueryRecords(result) {
|
|
9172
9016
|
return Array.isArray(result.records) ? result.records : [];
|
|
@@ -9190,9 +9034,9 @@ async function resolveSchemaSelector(api, selector2) {
|
|
|
9190
9034
|
}
|
|
9191
9035
|
function registerRecordsCommands(program, options = {}) {
|
|
9192
9036
|
const filePath = options.configPath ?? defaultConfigPath;
|
|
9193
|
-
const stdout =
|
|
9037
|
+
const stdout = getCommandIo8(options.stdout);
|
|
9194
9038
|
const records = program.command("records").description("Manage schema records");
|
|
9195
|
-
records.command("list").description("List records for a schema with simple pagination").argument("<schema>", "schema uuid or slug",
|
|
9039
|
+
records.command("list").description("List records for a schema with simple pagination").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector6).option("--limit <number>", "limit results", parseNonNegativeInteger2).option("--offset <number>", "offset results", parseNonNegativeInteger2).action(async function action(schema, commandOptions) {
|
|
9196
9040
|
const { api, schemasApi, json } = createRecordsApi(this, filePath);
|
|
9197
9041
|
const resolvedSchema = await resolveSchemaSelector(schemasApi, schema);
|
|
9198
9042
|
const data = await api.listRecords(
|
|
@@ -9201,7 +9045,7 @@ function registerRecordsCommands(program, options = {}) {
|
|
|
9201
9045
|
);
|
|
9202
9046
|
const recordsData = getQueryRecords(data);
|
|
9203
9047
|
if (json) {
|
|
9204
|
-
|
|
9048
|
+
emitJson8(
|
|
9205
9049
|
stdout,
|
|
9206
9050
|
"records list",
|
|
9207
9051
|
recordsData,
|
|
@@ -9210,9 +9054,9 @@ function registerRecordsCommands(program, options = {}) {
|
|
|
9210
9054
|
);
|
|
9211
9055
|
return;
|
|
9212
9056
|
}
|
|
9213
|
-
|
|
9057
|
+
emitTable3(stdout, recordsData);
|
|
9214
9058
|
});
|
|
9215
|
-
records.command("query").description("Query records for a schema").argument("<schema>", "schema uuid or slug",
|
|
9059
|
+
records.command("query").description("Query records for a schema").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector6).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) {
|
|
9216
9060
|
const { api, schemasApi, json } = createRecordsApi(this, filePath);
|
|
9217
9061
|
const resolvedSchema = await resolveSchemaSelector(schemasApi, schema);
|
|
9218
9062
|
const data = await api.queryRecords(
|
|
@@ -9221,7 +9065,7 @@ function registerRecordsCommands(program, options = {}) {
|
|
|
9221
9065
|
);
|
|
9222
9066
|
const recordsData = getQueryRecords(data);
|
|
9223
9067
|
if (json) {
|
|
9224
|
-
|
|
9068
|
+
emitJson8(
|
|
9225
9069
|
stdout,
|
|
9226
9070
|
"records query",
|
|
9227
9071
|
recordsData,
|
|
@@ -9230,19 +9074,19 @@ function registerRecordsCommands(program, options = {}) {
|
|
|
9230
9074
|
);
|
|
9231
9075
|
return;
|
|
9232
9076
|
}
|
|
9233
|
-
|
|
9077
|
+
emitTable3(stdout, recordsData);
|
|
9234
9078
|
});
|
|
9235
|
-
records.command("get").description("Get a record by UUID or slug").argument("<schema>", "schema uuid or slug",
|
|
9079
|
+
records.command("get").description("Get a record by UUID or slug").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector6).argument("<record>", "record uuid or slug", parseUuidOrSlugSelector6).action(async function action(schema, record) {
|
|
9236
9080
|
const { api, schemasApi, json } = createRecordsApi(this, filePath);
|
|
9237
9081
|
const resolvedSchema = await resolveSchemaSelector(schemasApi, schema);
|
|
9238
9082
|
const data = await api.getRecord(resolvedSchema, record);
|
|
9239
9083
|
if (json) {
|
|
9240
|
-
|
|
9084
|
+
emitJson8(stdout, "records get", data, filePath);
|
|
9241
9085
|
return;
|
|
9242
9086
|
}
|
|
9243
|
-
|
|
9087
|
+
emitTable3(stdout, data);
|
|
9244
9088
|
});
|
|
9245
|
-
records.command("create").description("Create a record").argument("<schema>", "schema uuid or slug",
|
|
9089
|
+
records.command("create").description("Create a record").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector6).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) {
|
|
9246
9090
|
const { api, schemasApi, json, readOnly } = createRecordsApi(this, filePath);
|
|
9247
9091
|
ensureWritable6("records create", readOnly, "write");
|
|
9248
9092
|
const resolvedSchema = await resolveSchemaSelector(schemasApi, schema);
|
|
@@ -9251,12 +9095,12 @@ function registerRecordsCommands(program, options = {}) {
|
|
|
9251
9095
|
buildRecordCreateInput(commandOptions)
|
|
9252
9096
|
);
|
|
9253
9097
|
if (json) {
|
|
9254
|
-
|
|
9098
|
+
emitJson8(stdout, "records create", data, filePath);
|
|
9255
9099
|
return;
|
|
9256
9100
|
}
|
|
9257
|
-
|
|
9101
|
+
writeLine8(stdout, `Created record "${getRecordIdentifier(data)}".`);
|
|
9258
9102
|
});
|
|
9259
|
-
records.command("update").description("Update a record").argument("<schema>", "schema uuid or slug",
|
|
9103
|
+
records.command("update").description("Update a record").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector6).argument("<record>", "record uuid or slug", parseUuidOrSlugSelector6).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) {
|
|
9260
9104
|
const { api, schemasApi, json, readOnly } = createRecordsApi(this, filePath);
|
|
9261
9105
|
ensureWritable6("records update", readOnly, "write");
|
|
9262
9106
|
const resolvedSchema = await resolveSchemaSelector(schemasApi, schema);
|
|
@@ -9266,12 +9110,12 @@ function registerRecordsCommands(program, options = {}) {
|
|
|
9266
9110
|
buildRecordUpdateInput(commandOptions)
|
|
9267
9111
|
);
|
|
9268
9112
|
if (json) {
|
|
9269
|
-
|
|
9113
|
+
emitJson8(stdout, "records update", data, filePath);
|
|
9270
9114
|
return;
|
|
9271
9115
|
}
|
|
9272
|
-
|
|
9116
|
+
writeLine8(stdout, `Updated record "${getRecordIdentifier(data)}".`);
|
|
9273
9117
|
});
|
|
9274
|
-
records.command("delete").description("Delete a record").argument("<schema>", "schema uuid or slug",
|
|
9118
|
+
records.command("delete").description("Delete a record").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector6).argument("<record>", "record uuid or slug", parseUuidOrSlugSelector6).action(async function action(schema, record) {
|
|
9275
9119
|
const { api, schemasApi, json, readOnly } = createRecordsApi(this, filePath);
|
|
9276
9120
|
ensureWritable6("records delete", readOnly, "destructive");
|
|
9277
9121
|
const resolvedSchema = await resolveSchemaSelector(schemasApi, schema);
|
|
@@ -9282,33 +9126,33 @@ function registerRecordsCommands(program, options = {}) {
|
|
|
9282
9126
|
deleted: true
|
|
9283
9127
|
};
|
|
9284
9128
|
if (json) {
|
|
9285
|
-
|
|
9129
|
+
emitJson8(stdout, "records delete", data, filePath);
|
|
9286
9130
|
return;
|
|
9287
9131
|
}
|
|
9288
|
-
|
|
9132
|
+
writeLine8(stdout, `Deleted record "${record.value}" from schema "${schema.value}".`);
|
|
9289
9133
|
});
|
|
9290
9134
|
}
|
|
9291
9135
|
|
|
9292
9136
|
// src/commands/schemas.ts
|
|
9293
9137
|
import { readFileSync as readFileSync8 } from "fs";
|
|
9294
|
-
import { InvalidArgumentError as
|
|
9295
|
-
function
|
|
9138
|
+
import { InvalidArgumentError as InvalidArgumentError7 } from "commander";
|
|
9139
|
+
function getCommandIo9(stdout) {
|
|
9296
9140
|
return stdout ?? process.stdout;
|
|
9297
9141
|
}
|
|
9298
|
-
function
|
|
9142
|
+
function writeLine9(stdout, value) {
|
|
9299
9143
|
stdout.write(`${value}
|
|
9300
9144
|
`);
|
|
9301
9145
|
}
|
|
9302
|
-
function
|
|
9146
|
+
function getGlobalOptions9(command) {
|
|
9303
9147
|
return command.optsWithGlobals();
|
|
9304
9148
|
}
|
|
9305
|
-
function
|
|
9306
|
-
|
|
9149
|
+
function emitJson9(stdout, commandName, data, configPath) {
|
|
9150
|
+
writeLine9(
|
|
9307
9151
|
stdout,
|
|
9308
9152
|
JSON.stringify(buildJsonSuccess(data, { command: commandName, configPath }))
|
|
9309
9153
|
);
|
|
9310
9154
|
}
|
|
9311
|
-
function
|
|
9155
|
+
function toConfigurationError8(filePath, error) {
|
|
9312
9156
|
if (error instanceof CliError) {
|
|
9313
9157
|
throw error;
|
|
9314
9158
|
}
|
|
@@ -9323,7 +9167,7 @@ function toConfigurationError9(filePath, error) {
|
|
|
9323
9167
|
function createSchemasApi(command, filePath) {
|
|
9324
9168
|
try {
|
|
9325
9169
|
const config = readRuntimeConfig(filePath);
|
|
9326
|
-
const runtime = resolveRuntimeContext(config,
|
|
9170
|
+
const runtime = resolveRuntimeContext(config, getGlobalOptions9(command));
|
|
9327
9171
|
if (!runtime.baseUrl) {
|
|
9328
9172
|
throw new CliError(
|
|
9329
9173
|
"configuration_error",
|
|
@@ -9342,7 +9186,7 @@ function createSchemasApi(command, filePath) {
|
|
|
9342
9186
|
readOnly: runtime.readOnly
|
|
9343
9187
|
};
|
|
9344
9188
|
} catch (error) {
|
|
9345
|
-
|
|
9189
|
+
toConfigurationError8(filePath, error);
|
|
9346
9190
|
}
|
|
9347
9191
|
}
|
|
9348
9192
|
function ensureWritable7(commandName, readOnly, commandMode) {
|
|
@@ -9357,12 +9201,12 @@ function ensureWritable7(commandName, readOnly, commandMode) {
|
|
|
9357
9201
|
);
|
|
9358
9202
|
}
|
|
9359
9203
|
}
|
|
9360
|
-
function
|
|
9204
|
+
function parseUuidOrSlugSelector7(input) {
|
|
9361
9205
|
try {
|
|
9362
9206
|
return normalizeUuidOrSlug(input);
|
|
9363
9207
|
} catch (error) {
|
|
9364
9208
|
const message = error instanceof Error ? error.message : "Invalid selector.";
|
|
9365
|
-
throw new
|
|
9209
|
+
throw new InvalidArgumentError7(message);
|
|
9366
9210
|
}
|
|
9367
9211
|
}
|
|
9368
9212
|
function parseBooleanFlag(input) {
|
|
@@ -9373,9 +9217,9 @@ function parseBooleanFlag(input) {
|
|
|
9373
9217
|
if (["false", "0", "no", "n", "off"].includes(normalized)) {
|
|
9374
9218
|
return false;
|
|
9375
9219
|
}
|
|
9376
|
-
throw new
|
|
9220
|
+
throw new InvalidArgumentError7(`Expected a boolean value, received "${input}".`);
|
|
9377
9221
|
}
|
|
9378
|
-
function
|
|
9222
|
+
function isJsonObject5(value) {
|
|
9379
9223
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9380
9224
|
}
|
|
9381
9225
|
function parseRawJsonObject3(input, sourceLabel) {
|
|
@@ -9389,7 +9233,7 @@ function parseRawJsonObject3(input, sourceLabel) {
|
|
|
9389
9233
|
`Failed to parse JSON from ${sourceLabel}: ${message}`
|
|
9390
9234
|
);
|
|
9391
9235
|
}
|
|
9392
|
-
if (!
|
|
9236
|
+
if (!isJsonObject5(parsed)) {
|
|
9393
9237
|
throw new CliError(
|
|
9394
9238
|
"invalid_cli_usage",
|
|
9395
9239
|
`Expected ${sourceLabel} to contain a JSON object.`
|
|
@@ -9464,6 +9308,22 @@ function buildSchemaUpdateInput(options) {
|
|
|
9464
9308
|
}
|
|
9465
9309
|
return input;
|
|
9466
9310
|
}
|
|
9311
|
+
function applyFieldDefaultValue(input, defaultValue) {
|
|
9312
|
+
if (defaultValue === void 0) {
|
|
9313
|
+
return;
|
|
9314
|
+
}
|
|
9315
|
+
const config = input.config;
|
|
9316
|
+
if (config !== void 0 && !isJsonObject5(config)) {
|
|
9317
|
+
throw new CliError(
|
|
9318
|
+
"invalid_cli_usage",
|
|
9319
|
+
'Expected field "config" to be a JSON object when using "--default".'
|
|
9320
|
+
);
|
|
9321
|
+
}
|
|
9322
|
+
input.config = {
|
|
9323
|
+
...config ?? {},
|
|
9324
|
+
defaultValue
|
|
9325
|
+
};
|
|
9326
|
+
}
|
|
9467
9327
|
function buildFieldCreateInput(options) {
|
|
9468
9328
|
const raw = normalizeSchemaFieldCreatePayload(readRawObject4(options.raw, options.rawFile));
|
|
9469
9329
|
const rawType = typeof raw.type === "string" ? raw.type : void 0;
|
|
@@ -9492,7 +9352,8 @@ function buildFieldCreateInput(options) {
|
|
|
9492
9352
|
if (options.required !== void 0) {
|
|
9493
9353
|
input.required = options.required;
|
|
9494
9354
|
}
|
|
9495
|
-
|
|
9355
|
+
applyFieldDefaultValue(input, options.default);
|
|
9356
|
+
if ("config" in input && isJsonObject5(input.config) && isEmptyObject5(input.config)) {
|
|
9496
9357
|
delete input.config;
|
|
9497
9358
|
}
|
|
9498
9359
|
return input;
|
|
@@ -9534,6 +9395,7 @@ function buildFieldUpdateInput(currentType, options) {
|
|
|
9534
9395
|
if (options.required !== void 0) {
|
|
9535
9396
|
input.required = options.required;
|
|
9536
9397
|
}
|
|
9398
|
+
applyFieldDefaultValue(input, options.default);
|
|
9537
9399
|
return input;
|
|
9538
9400
|
}
|
|
9539
9401
|
async function resolveSchemaSelector2(api, selector2) {
|
|
@@ -9569,23 +9431,23 @@ function isEmptyObject5(value) {
|
|
|
9569
9431
|
}
|
|
9570
9432
|
function registerSchemasCommands(program, options = {}) {
|
|
9571
9433
|
const filePath = options.configPath ?? defaultConfigPath;
|
|
9572
|
-
const stdout =
|
|
9434
|
+
const stdout = getCommandIo9(options.stdout);
|
|
9573
9435
|
const schemas = program.command("schemas").description("Manage schemas and schema fields");
|
|
9574
9436
|
schemas.command("list").description("List schemas").action(async function action() {
|
|
9575
9437
|
const { api, json } = createSchemasApi(this, filePath);
|
|
9576
9438
|
const data = await api.listSchemas();
|
|
9577
9439
|
if (json) {
|
|
9578
|
-
|
|
9440
|
+
emitJson9(stdout, "schemas list", data, filePath);
|
|
9579
9441
|
return;
|
|
9580
9442
|
}
|
|
9581
9443
|
emitSchemasTable(stdout, data);
|
|
9582
9444
|
});
|
|
9583
|
-
schemas.command("get").description("Get a schema by UUID or slug").argument("<schema>", "schema uuid or slug",
|
|
9445
|
+
schemas.command("get").description("Get a schema by UUID or slug").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector7).action(async function action(schema) {
|
|
9584
9446
|
const { api, json } = createSchemasApi(this, filePath);
|
|
9585
9447
|
const resolvedSchema = await resolveSchemaSelector2(api, schema);
|
|
9586
9448
|
const data = await api.getSchema(resolvedSchema);
|
|
9587
9449
|
if (json) {
|
|
9588
|
-
|
|
9450
|
+
emitJson9(stdout, "schemas get", data, filePath);
|
|
9589
9451
|
return;
|
|
9590
9452
|
}
|
|
9591
9453
|
emitSchemasTable(stdout, [data]);
|
|
@@ -9601,12 +9463,12 @@ function registerSchemasCommands(program, options = {}) {
|
|
|
9601
9463
|
};
|
|
9602
9464
|
const data = await api.createSchema(input);
|
|
9603
9465
|
if (json) {
|
|
9604
|
-
|
|
9466
|
+
emitJson9(stdout, "schemas create", data, filePath);
|
|
9605
9467
|
return;
|
|
9606
9468
|
}
|
|
9607
|
-
|
|
9469
|
+
writeLine9(stdout, `Created schema "${data.slug ?? commandOptions.slug}".`);
|
|
9608
9470
|
});
|
|
9609
|
-
schemas.command("update").description("Update a schema").argument("<schema>", "schema uuid or slug",
|
|
9471
|
+
schemas.command("update").description("Update a schema").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector7).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) {
|
|
9610
9472
|
const { api, json, readOnly } = createSchemasApi(this, filePath);
|
|
9611
9473
|
ensureWritable7("schemas update", readOnly, "write");
|
|
9612
9474
|
const resolvedSchema = await resolveSchemaSelector2(api, schema);
|
|
@@ -9619,12 +9481,12 @@ function registerSchemasCommands(program, options = {}) {
|
|
|
9619
9481
|
}
|
|
9620
9482
|
const data = await api.updateSchema(resolvedSchema, input);
|
|
9621
9483
|
if (json) {
|
|
9622
|
-
|
|
9484
|
+
emitJson9(stdout, "schemas update", data, filePath);
|
|
9623
9485
|
return;
|
|
9624
9486
|
}
|
|
9625
|
-
|
|
9487
|
+
writeLine9(stdout, `Updated schema "${data.slug ?? schema.value}".`);
|
|
9626
9488
|
});
|
|
9627
|
-
schemas.command("delete").description("Delete a schema").argument("<schema>", "schema uuid or slug",
|
|
9489
|
+
schemas.command("delete").description("Delete a schema").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector7).action(async function action(schema) {
|
|
9628
9490
|
const { api, json, readOnly } = createSchemasApi(this, filePath);
|
|
9629
9491
|
ensureWritable7("schemas delete", readOnly, "destructive");
|
|
9630
9492
|
const resolvedSchema = await resolveSchemaSelector2(api, schema);
|
|
@@ -9634,34 +9496,34 @@ function registerSchemasCommands(program, options = {}) {
|
|
|
9634
9496
|
deleted: true
|
|
9635
9497
|
};
|
|
9636
9498
|
if (json) {
|
|
9637
|
-
|
|
9499
|
+
emitJson9(stdout, "schemas delete", data, filePath);
|
|
9638
9500
|
return;
|
|
9639
9501
|
}
|
|
9640
|
-
|
|
9502
|
+
writeLine9(stdout, `Deleted schema "${schema.value}".`);
|
|
9641
9503
|
});
|
|
9642
9504
|
const fields = schemas.command("fields").description("Manage schema fields");
|
|
9643
|
-
fields.command("list").description("List fields for a schema").argument("<schema>", "schema uuid or slug",
|
|
9505
|
+
fields.command("list").description("List fields for a schema").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector7).action(async function action(schema) {
|
|
9644
9506
|
const { api, json } = createSchemasApi(this, filePath);
|
|
9645
9507
|
const resolvedSchema = await resolveSchemaSelector2(api, schema);
|
|
9646
9508
|
const data = await api.listFields(resolvedSchema);
|
|
9647
9509
|
if (json) {
|
|
9648
|
-
|
|
9510
|
+
emitJson9(stdout, "schemas fields list", data, filePath);
|
|
9649
9511
|
return;
|
|
9650
9512
|
}
|
|
9651
9513
|
emitFieldsTable(stdout, data);
|
|
9652
9514
|
});
|
|
9653
|
-
fields.command("get").description("Get a field by UUID or slug").argument("<schema>", "schema uuid or slug",
|
|
9515
|
+
fields.command("get").description("Get a field by UUID or slug").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector7).argument("<field>", "field uuid or slug", parseUuidOrSlugSelector7).action(async function action(schema, field) {
|
|
9654
9516
|
const { api, json } = createSchemasApi(this, filePath);
|
|
9655
9517
|
const resolvedSchema = await resolveSchemaSelector2(api, schema);
|
|
9656
9518
|
const resolvedField = await resolveFieldSelector(api, resolvedSchema, field);
|
|
9657
9519
|
const data = await api.getField(resolvedSchema, resolvedField);
|
|
9658
9520
|
if (json) {
|
|
9659
|
-
|
|
9521
|
+
emitJson9(stdout, "schemas fields get", data, filePath);
|
|
9660
9522
|
return;
|
|
9661
9523
|
}
|
|
9662
9524
|
emitFieldsTable(stdout, [data]);
|
|
9663
9525
|
});
|
|
9664
|
-
fields.command("create").description(`Create a field in a schema.${buildSchemaFieldCreateHelpText()}`).argument("<schema>", "schema uuid or slug",
|
|
9526
|
+
fields.command("create").description(`Create a field in a schema.${buildSchemaFieldCreateHelpText()}`).argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector7).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) {
|
|
9665
9527
|
const { api, json, readOnly } = createSchemasApi(this, filePath);
|
|
9666
9528
|
ensureWritable7("schemas fields create", readOnly, "write");
|
|
9667
9529
|
const input = buildFieldCreateInput(commandOptions);
|
|
@@ -9673,12 +9535,12 @@ function registerSchemasCommands(program, options = {}) {
|
|
|
9673
9535
|
toFieldCreateError(error, input);
|
|
9674
9536
|
}
|
|
9675
9537
|
if (json) {
|
|
9676
|
-
|
|
9538
|
+
emitJson9(stdout, "schemas fields create", data, filePath);
|
|
9677
9539
|
return;
|
|
9678
9540
|
}
|
|
9679
|
-
|
|
9541
|
+
writeLine9(stdout, `Created field "${data.slug ?? commandOptions.slug}".`);
|
|
9680
9542
|
});
|
|
9681
|
-
fields.command("update").description("Update a field in a schema").argument("<schema>", "schema uuid or slug",
|
|
9543
|
+
fields.command("update").description("Update a field in a schema").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector7).argument("<field>", "field uuid or slug", parseUuidOrSlugSelector7).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) {
|
|
9682
9544
|
const { api, json, readOnly } = createSchemasApi(this, filePath);
|
|
9683
9545
|
ensureWritable7("schemas fields update", readOnly, "write");
|
|
9684
9546
|
const resolvedSchema = await resolveSchemaSelector2(api, schema);
|
|
@@ -9697,12 +9559,12 @@ function registerSchemasCommands(program, options = {}) {
|
|
|
9697
9559
|
}
|
|
9698
9560
|
const data = await api.updateField(resolvedSchema, resolvedField, input);
|
|
9699
9561
|
if (json) {
|
|
9700
|
-
|
|
9562
|
+
emitJson9(stdout, "schemas fields update", data, filePath);
|
|
9701
9563
|
return;
|
|
9702
9564
|
}
|
|
9703
|
-
|
|
9565
|
+
writeLine9(stdout, `Updated field "${data.slug ?? field.value}".`);
|
|
9704
9566
|
});
|
|
9705
|
-
fields.command("delete").description("Delete a field from a schema").argument("<schema>", "schema uuid or slug",
|
|
9567
|
+
fields.command("delete").description("Delete a field from a schema").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector7).argument("<field>", "field uuid or slug", parseUuidOrSlugSelector7).action(async function action(schema, field) {
|
|
9706
9568
|
const { api, json, readOnly } = createSchemasApi(this, filePath);
|
|
9707
9569
|
ensureWritable7("schemas fields delete", readOnly, "destructive");
|
|
9708
9570
|
const resolvedSchema = await resolveSchemaSelector2(api, schema);
|
|
@@ -9714,16 +9576,16 @@ function registerSchemasCommands(program, options = {}) {
|
|
|
9714
9576
|
deleted: true
|
|
9715
9577
|
};
|
|
9716
9578
|
if (json) {
|
|
9717
|
-
|
|
9579
|
+
emitJson9(stdout, "schemas fields delete", data, filePath);
|
|
9718
9580
|
return;
|
|
9719
9581
|
}
|
|
9720
|
-
|
|
9582
|
+
writeLine9(stdout, `Deleted field "${field.value}" from schema "${schema.value}".`);
|
|
9721
9583
|
});
|
|
9722
9584
|
}
|
|
9723
9585
|
|
|
9724
9586
|
// src/commands/teamspace.ts
|
|
9725
9587
|
import { readFileSync as readFileSync9 } from "fs";
|
|
9726
|
-
import { InvalidArgumentError as
|
|
9588
|
+
import { InvalidArgumentError as InvalidArgumentError8 } from "commander";
|
|
9727
9589
|
|
|
9728
9590
|
// src/api/teamspace.ts
|
|
9729
9591
|
function jsonOptions7(body, method) {
|
|
@@ -9735,7 +9597,7 @@ function jsonOptions7(body, method) {
|
|
|
9735
9597
|
body: JSON.stringify(body)
|
|
9736
9598
|
};
|
|
9737
9599
|
}
|
|
9738
|
-
function
|
|
9600
|
+
function selectorValue8(selector2) {
|
|
9739
9601
|
return selector2.value;
|
|
9740
9602
|
}
|
|
9741
9603
|
var TeamspaceApi = class {
|
|
@@ -9761,13 +9623,13 @@ var TeamspaceApi = class {
|
|
|
9761
9623
|
}
|
|
9762
9624
|
updateFolder(folder, input) {
|
|
9763
9625
|
return this.client.requestJson(
|
|
9764
|
-
`/api/v2/teamspaces/folders/${
|
|
9626
|
+
`/api/v2/teamspaces/folders/${selectorValue8(folder)}`,
|
|
9765
9627
|
jsonOptions7(input, "PATCH")
|
|
9766
9628
|
);
|
|
9767
9629
|
}
|
|
9768
9630
|
deleteFolder(folder) {
|
|
9769
9631
|
return this.client.requestJson(
|
|
9770
|
-
`/api/v2/teamspaces/folders/${
|
|
9632
|
+
`/api/v2/teamspaces/folders/${selectorValue8(folder)}`,
|
|
9771
9633
|
{ method: "DELETE" }
|
|
9772
9634
|
);
|
|
9773
9635
|
}
|
|
@@ -9786,23 +9648,23 @@ var TeamspaceApi = class {
|
|
|
9786
9648
|
};
|
|
9787
9649
|
|
|
9788
9650
|
// src/commands/teamspace.ts
|
|
9789
|
-
function
|
|
9651
|
+
function getCommandIo10(stdout) {
|
|
9790
9652
|
return stdout ?? process.stdout;
|
|
9791
9653
|
}
|
|
9792
|
-
function
|
|
9654
|
+
function writeLine10(stdout, value) {
|
|
9793
9655
|
stdout.write(`${value}
|
|
9794
9656
|
`);
|
|
9795
9657
|
}
|
|
9796
|
-
function
|
|
9658
|
+
function getGlobalOptions10(command) {
|
|
9797
9659
|
return command.optsWithGlobals();
|
|
9798
9660
|
}
|
|
9799
|
-
function
|
|
9800
|
-
|
|
9661
|
+
function emitJson10(stdout, commandName, data, configPath) {
|
|
9662
|
+
writeLine10(
|
|
9801
9663
|
stdout,
|
|
9802
9664
|
JSON.stringify(buildJsonSuccess(data, { command: commandName, configPath }))
|
|
9803
9665
|
);
|
|
9804
9666
|
}
|
|
9805
|
-
function
|
|
9667
|
+
function toConfigurationError9(filePath, error) {
|
|
9806
9668
|
if (error instanceof CliError) {
|
|
9807
9669
|
throw error;
|
|
9808
9670
|
}
|
|
@@ -9817,7 +9679,7 @@ function toConfigurationError10(filePath, error) {
|
|
|
9817
9679
|
function createTeamspaceApi(command, filePath) {
|
|
9818
9680
|
try {
|
|
9819
9681
|
const config = readRuntimeConfig(filePath);
|
|
9820
|
-
const runtime = resolveRuntimeContext(config,
|
|
9682
|
+
const runtime = resolveRuntimeContext(config, getGlobalOptions10(command));
|
|
9821
9683
|
if (!runtime.baseUrl) {
|
|
9822
9684
|
throw new CliError(
|
|
9823
9685
|
"configuration_error",
|
|
@@ -9835,7 +9697,7 @@ function createTeamspaceApi(command, filePath) {
|
|
|
9835
9697
|
readOnly: runtime.readOnly
|
|
9836
9698
|
};
|
|
9837
9699
|
} catch (error) {
|
|
9838
|
-
|
|
9700
|
+
toConfigurationError9(filePath, error);
|
|
9839
9701
|
}
|
|
9840
9702
|
}
|
|
9841
9703
|
function ensureWritable8(commandName, readOnly, commandMode) {
|
|
@@ -9850,21 +9712,21 @@ function ensureWritable8(commandName, readOnly, commandMode) {
|
|
|
9850
9712
|
);
|
|
9851
9713
|
}
|
|
9852
9714
|
}
|
|
9853
|
-
function
|
|
9715
|
+
function parseUuidOrSlugSelector8(input) {
|
|
9854
9716
|
try {
|
|
9855
9717
|
return normalizeUuidOrSlug(input);
|
|
9856
9718
|
} catch (error) {
|
|
9857
9719
|
const message = error instanceof Error ? error.message : "Invalid selector.";
|
|
9858
|
-
throw new
|
|
9720
|
+
throw new InvalidArgumentError8(message);
|
|
9859
9721
|
}
|
|
9860
9722
|
}
|
|
9861
9723
|
function parseNonNegativeInteger3(input) {
|
|
9862
9724
|
if (!/^\d+$/.test(input.trim())) {
|
|
9863
|
-
throw new
|
|
9725
|
+
throw new InvalidArgumentError8(`Expected a non-negative integer, received "${input}".`);
|
|
9864
9726
|
}
|
|
9865
9727
|
return Number(input);
|
|
9866
9728
|
}
|
|
9867
|
-
function
|
|
9729
|
+
function isJsonObject6(value) {
|
|
9868
9730
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9869
9731
|
}
|
|
9870
9732
|
function parseRawJsonObject4(input, sourceLabel) {
|
|
@@ -9878,7 +9740,7 @@ function parseRawJsonObject4(input, sourceLabel) {
|
|
|
9878
9740
|
`Failed to parse JSON from ${sourceLabel}: ${message}`
|
|
9879
9741
|
);
|
|
9880
9742
|
}
|
|
9881
|
-
if (!
|
|
9743
|
+
if (!isJsonObject6(parsed)) {
|
|
9882
9744
|
throw new CliError(
|
|
9883
9745
|
"invalid_cli_usage",
|
|
9884
9746
|
`Expected ${sourceLabel} to contain a JSON object.`
|
|
@@ -9950,17 +9812,17 @@ function buildFolderUpdateInput(options) {
|
|
|
9950
9812
|
}
|
|
9951
9813
|
return input;
|
|
9952
9814
|
}
|
|
9953
|
-
function
|
|
9815
|
+
function toTableRows4(data) {
|
|
9954
9816
|
if (Array.isArray(data)) {
|
|
9955
|
-
return data.map((entry) =>
|
|
9817
|
+
return data.map((entry) => isJsonObject6(entry) ? entry : { value: entry });
|
|
9956
9818
|
}
|
|
9957
|
-
if (
|
|
9819
|
+
if (isJsonObject6(data)) {
|
|
9958
9820
|
return [data];
|
|
9959
9821
|
}
|
|
9960
9822
|
return [{ value: data }];
|
|
9961
9823
|
}
|
|
9962
|
-
function
|
|
9963
|
-
printTable(
|
|
9824
|
+
function emitTable4(stdout, data) {
|
|
9825
|
+
printTable(toTableRows4(data), void 0, stdout);
|
|
9964
9826
|
}
|
|
9965
9827
|
function getFolderIdentifier(folder) {
|
|
9966
9828
|
return typeof folder.id === "string" ? folder.id : typeof folder.name === "string" ? folder.name : "unknown";
|
|
@@ -10016,63 +9878,63 @@ async function resolveFolderSelector2(api, selector2) {
|
|
|
10016
9878
|
}
|
|
10017
9879
|
function registerTeamspaceCommands(program, options = {}) {
|
|
10018
9880
|
const filePath = options.configPath ?? defaultConfigPath;
|
|
10019
|
-
const stdout =
|
|
9881
|
+
const stdout = getCommandIo10(options.stdout);
|
|
10020
9882
|
const teamspace = program.command("teamspace").description("Manage teamspace folders and resources");
|
|
10021
9883
|
const folders = teamspace.command("folders").description("Manage teamspace folders");
|
|
10022
9884
|
folders.command("list").description("List teamspace folders").option("--include-resources", "include nested resources").action(async function action(commandOptions) {
|
|
10023
9885
|
const { api, json } = createTeamspaceApi(this, filePath);
|
|
10024
9886
|
const data = await api.listFolders(Boolean(commandOptions.includeResources));
|
|
10025
9887
|
if (json) {
|
|
10026
|
-
|
|
9888
|
+
emitJson10(stdout, "teamspace folders list", data, filePath);
|
|
10027
9889
|
return;
|
|
10028
9890
|
}
|
|
10029
|
-
|
|
9891
|
+
emitTable4(stdout, data);
|
|
10030
9892
|
});
|
|
10031
|
-
folders.command("get").description("Get a teamspace folder by exact name or UUID").argument("<folder>", "folder UUID or exact name",
|
|
9893
|
+
folders.command("get").description("Get a teamspace folder by exact name or UUID").argument("<folder>", "folder UUID or exact name", parseUuidOrSlugSelector8).option("--include-resources", "include nested resources").action(async function action(folder, commandOptions) {
|
|
10032
9894
|
const { api, json } = createTeamspaceApi(this, filePath);
|
|
10033
9895
|
const resolvedFolder = await resolveFolderSelector2(api, folder);
|
|
10034
9896
|
const allFolders = await api.listFolders(Boolean(commandOptions.includeResources));
|
|
10035
9897
|
const data = findFolderEntity(allFolders, resolvedFolder);
|
|
10036
9898
|
if (json) {
|
|
10037
|
-
|
|
9899
|
+
emitJson10(stdout, "teamspace folders get", data, filePath);
|
|
10038
9900
|
return;
|
|
10039
9901
|
}
|
|
10040
|
-
|
|
9902
|
+
emitTable4(stdout, data);
|
|
10041
9903
|
});
|
|
10042
9904
|
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) {
|
|
10043
9905
|
const { api, json, readOnly } = createTeamspaceApi(this, filePath);
|
|
10044
9906
|
ensureWritable8("teamspace folders create", readOnly, "write");
|
|
10045
9907
|
const data = await api.createFolder(buildFolderCreateInput(commandOptions));
|
|
10046
9908
|
if (json) {
|
|
10047
|
-
|
|
9909
|
+
emitJson10(stdout, "teamspace folders create", data, filePath);
|
|
10048
9910
|
return;
|
|
10049
9911
|
}
|
|
10050
|
-
|
|
9912
|
+
writeLine10(stdout, `Created folder "${getFolderIdentifier(data)}".`);
|
|
10051
9913
|
});
|
|
10052
|
-
folders.command("update").description("Update a teamspace folder").argument("<folder>", "folder UUID or exact name",
|
|
9914
|
+
folders.command("update").description("Update a teamspace folder").argument("<folder>", "folder UUID or exact name", parseUuidOrSlugSelector8).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) {
|
|
10053
9915
|
const { api, json, readOnly } = createTeamspaceApi(this, filePath);
|
|
10054
9916
|
ensureWritable8("teamspace folders update", readOnly, "write");
|
|
10055
9917
|
const resolvedFolder = await resolveFolderSelector2(api, folder);
|
|
10056
9918
|
const data = await api.updateFolder(resolvedFolder, buildFolderUpdateInput(commandOptions));
|
|
10057
9919
|
if (json) {
|
|
10058
|
-
|
|
9920
|
+
emitJson10(stdout, "teamspace folders update", data, filePath);
|
|
10059
9921
|
return;
|
|
10060
9922
|
}
|
|
10061
|
-
|
|
9923
|
+
writeLine10(stdout, `Updated folder "${getFolderIdentifier(data)}".`);
|
|
10062
9924
|
});
|
|
10063
|
-
folders.command("delete").description("Delete a teamspace folder").argument("<folder>", "folder UUID or exact name",
|
|
9925
|
+
folders.command("delete").description("Delete a teamspace folder").argument("<folder>", "folder UUID or exact name", parseUuidOrSlugSelector8).action(async function action(folder) {
|
|
10064
9926
|
const { api, json, readOnly } = createTeamspaceApi(this, filePath);
|
|
10065
9927
|
ensureWritable8("teamspace folders delete", readOnly, "destructive");
|
|
10066
9928
|
const resolvedFolder = await resolveFolderSelector2(api, folder);
|
|
10067
9929
|
const data = await api.deleteFolder(resolvedFolder);
|
|
10068
9930
|
if (json) {
|
|
10069
|
-
|
|
9931
|
+
emitJson10(stdout, "teamspace folders delete", data, filePath);
|
|
10070
9932
|
return;
|
|
10071
9933
|
}
|
|
10072
|
-
|
|
9934
|
+
writeLine10(stdout, `Deleted folder "${resolvedFolder.value}".`);
|
|
10073
9935
|
});
|
|
10074
9936
|
const resources = teamspace.command("resources").description("Manage teamspace resources");
|
|
10075
|
-
resources.command("publish").description("Publish a resource to a teamspace folder").argument("<resource>", "resource UUID or exact name",
|
|
9937
|
+
resources.command("publish").description("Publish a resource to a teamspace folder").argument("<resource>", "resource UUID or exact name", parseUuidOrSlugSelector8).requiredOption("--to <folder>", "target folder", parseUuidOrSlugSelector8).action(async function action(resource, commandOptions) {
|
|
10076
9938
|
const { api, json, readOnly } = createTeamspaceApi(this, filePath);
|
|
10077
9939
|
ensureWritable8("teamspace resources publish", readOnly, "write");
|
|
10078
9940
|
const folder = await resolveFolderSelector2(api, commandOptions.to);
|
|
@@ -10081,20 +9943,20 @@ function registerTeamspaceCommands(program, options = {}) {
|
|
|
10081
9943
|
targetFolderId: folder.value
|
|
10082
9944
|
});
|
|
10083
9945
|
if (json) {
|
|
10084
|
-
|
|
9946
|
+
emitJson10(stdout, "teamspace resources publish", data, filePath);
|
|
10085
9947
|
return;
|
|
10086
9948
|
}
|
|
10087
|
-
|
|
9949
|
+
writeLine10(stdout, `Published resource "${resource.value}" to folder "${folder.value}".`);
|
|
10088
9950
|
});
|
|
10089
|
-
resources.command("unpublish").description("Unpublish a resource from teamspace").argument("<resource>", "resource UUID or exact name",
|
|
9951
|
+
resources.command("unpublish").description("Unpublish a resource from teamspace").argument("<resource>", "resource UUID or exact name", parseUuidOrSlugSelector8).action(async function action(resource) {
|
|
10090
9952
|
const { api, json, readOnly } = createTeamspaceApi(this, filePath);
|
|
10091
9953
|
ensureWritable8("teamspace resources unpublish", readOnly, "write");
|
|
10092
9954
|
const data = await api.unpublishResource(resource.value);
|
|
10093
9955
|
if (json) {
|
|
10094
|
-
|
|
9956
|
+
emitJson10(stdout, "teamspace resources unpublish", data, filePath);
|
|
10095
9957
|
return;
|
|
10096
9958
|
}
|
|
10097
|
-
|
|
9959
|
+
writeLine10(stdout, `Unpublished resource "${resource.value}".`);
|
|
10098
9960
|
});
|
|
10099
9961
|
}
|
|
10100
9962
|
|
|
@@ -10102,7 +9964,7 @@ function registerTeamspaceCommands(program, options = {}) {
|
|
|
10102
9964
|
var require2 = createRequire(import.meta.url);
|
|
10103
9965
|
var { version } = require2("../package.json");
|
|
10104
9966
|
function buildProgram(options = {}) {
|
|
10105
|
-
const program = new
|
|
9967
|
+
const program = new Command9();
|
|
10106
9968
|
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");
|
|
10107
9969
|
registerProfilesCommands(program, options);
|
|
10108
9970
|
registerAutomationsCommands(program, options);
|
|
@@ -10113,7 +9975,6 @@ function buildProgram(options = {}) {
|
|
|
10113
9975
|
registerSchemasCommands(program, options);
|
|
10114
9976
|
registerRecordsCommands(program, options);
|
|
10115
9977
|
registerCommentsCommands(program, options);
|
|
10116
|
-
registerLogsCommands(program, options);
|
|
10117
9978
|
registerTeamspaceCommands(program, options);
|
|
10118
9979
|
return program;
|
|
10119
9980
|
}
|