zinkee 0.1.69 → 0.1.70
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 +35 -0
- package/dist/{chunk-DCC56F2L.js → chunk-SVBC47AD.js} +15 -2
- package/dist/chunk-SVBC47AD.js.map +1 -0
- package/dist/{examples-AJAJZ6QM.js → examples-MT6FVPAD.js} +129 -4
- package/dist/examples-MT6FVPAD.js.map +1 -0
- package/dist/index.js +420 -238
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-DCC56F2L.js.map +0 -1
- package/dist/examples-AJAJZ6QM.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
normalizeSchemaFieldUpdatePayload,
|
|
19
19
|
printTable,
|
|
20
20
|
toCliError
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-SVBC47AD.js";
|
|
22
22
|
|
|
23
23
|
// src/cli-runner.ts
|
|
24
24
|
import { realpathSync } from "fs";
|
|
@@ -253,7 +253,7 @@ ${list}`
|
|
|
253
253
|
};
|
|
254
254
|
}
|
|
255
255
|
async function showExamples(commandName, json, stdout, filters = {}) {
|
|
256
|
-
const { getCommandExamples } = await import("./examples-
|
|
256
|
+
const { getCommandExamples } = await import("./examples-MT6FVPAD.js");
|
|
257
257
|
const examples = getCommandExamples(commandName, filters);
|
|
258
258
|
if (examples.length === 0) {
|
|
259
259
|
throw new CliError("invalid_cli_usage", `No examples registered for "${commandName}".`);
|
|
@@ -1244,6 +1244,190 @@ var AutomationsApi = class {
|
|
|
1244
1244
|
}
|
|
1245
1245
|
};
|
|
1246
1246
|
|
|
1247
|
+
// src/api/records.ts
|
|
1248
|
+
function isQueryExpression(entry) {
|
|
1249
|
+
return typeof entry === "object" && entry !== null && "comparator" in entry && !("op" in entry);
|
|
1250
|
+
}
|
|
1251
|
+
function toWhereNode(entry) {
|
|
1252
|
+
if (!isQueryExpression(entry)) {
|
|
1253
|
+
return entry;
|
|
1254
|
+
}
|
|
1255
|
+
return {
|
|
1256
|
+
field: entry.field,
|
|
1257
|
+
op: entry.comparator,
|
|
1258
|
+
value: entry.value
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1261
|
+
function toSort(entry) {
|
|
1262
|
+
if (typeof entry !== "string") {
|
|
1263
|
+
return entry;
|
|
1264
|
+
}
|
|
1265
|
+
const [field = "", direction = "asc"] = entry.split(":");
|
|
1266
|
+
return {
|
|
1267
|
+
field,
|
|
1268
|
+
direction: direction.toUpperCase()
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1271
|
+
function jsonOptions2(body, method) {
|
|
1272
|
+
return {
|
|
1273
|
+
method,
|
|
1274
|
+
headers: {
|
|
1275
|
+
"content-type": "application/json"
|
|
1276
|
+
},
|
|
1277
|
+
body: JSON.stringify(body)
|
|
1278
|
+
};
|
|
1279
|
+
}
|
|
1280
|
+
var RecordsApi = class {
|
|
1281
|
+
constructor(client) {
|
|
1282
|
+
this.client = client;
|
|
1283
|
+
}
|
|
1284
|
+
listRecords(schema, query) {
|
|
1285
|
+
const params = new URLSearchParams();
|
|
1286
|
+
if (query.limit !== void 0) {
|
|
1287
|
+
params.set("limit", String(query.limit));
|
|
1288
|
+
}
|
|
1289
|
+
if (query.offset !== void 0) {
|
|
1290
|
+
params.set("offset", String(query.offset));
|
|
1291
|
+
}
|
|
1292
|
+
const path = `/api/v2/schemas/${schema.value}/records`;
|
|
1293
|
+
const queryString = params.toString();
|
|
1294
|
+
return this.client.getJson(
|
|
1295
|
+
queryString ? `${path}?${queryString}` : path
|
|
1296
|
+
);
|
|
1297
|
+
}
|
|
1298
|
+
queryRecords(schema, query) {
|
|
1299
|
+
const body = this.normalizeQueryInput(query);
|
|
1300
|
+
return this.client.requestJson(
|
|
1301
|
+
`/api/v2/schemas/${schema.value}/records:query`,
|
|
1302
|
+
jsonOptions2(body, "POST")
|
|
1303
|
+
);
|
|
1304
|
+
}
|
|
1305
|
+
aggregateRecords(schema, input) {
|
|
1306
|
+
const body = Array.isArray(input.where) ? { ...input, where: input.where.map(toWhereNode) } : input;
|
|
1307
|
+
return this.client.requestJson(
|
|
1308
|
+
`/api/v2/schemas/${schema.value}/records:aggregate`,
|
|
1309
|
+
jsonOptions2(body, "POST")
|
|
1310
|
+
);
|
|
1311
|
+
}
|
|
1312
|
+
getRecord(schema, record) {
|
|
1313
|
+
return this.client.getJson(
|
|
1314
|
+
`/api/v2/schemas/${schema.value}/records/${record.value}`
|
|
1315
|
+
);
|
|
1316
|
+
}
|
|
1317
|
+
createRecords(schema, records) {
|
|
1318
|
+
return this.client.requestJson(
|
|
1319
|
+
`/api/v2/schemas/${schema.value}/records`,
|
|
1320
|
+
jsonOptions2({ records }, "POST")
|
|
1321
|
+
);
|
|
1322
|
+
}
|
|
1323
|
+
updateRecord(schema, record, input) {
|
|
1324
|
+
return this.client.requestJson(
|
|
1325
|
+
`/api/v2/schemas/${schema.value}/records/${record.value}`,
|
|
1326
|
+
jsonOptions2(input, "PATCH")
|
|
1327
|
+
);
|
|
1328
|
+
}
|
|
1329
|
+
deleteRecords(schema, recordIds) {
|
|
1330
|
+
return this.client.requestJson(
|
|
1331
|
+
`/api/v2/schemas/${schema.value}/records:delete`,
|
|
1332
|
+
jsonOptions2({ recordIds }, "POST")
|
|
1333
|
+
);
|
|
1334
|
+
}
|
|
1335
|
+
clearRecords(schema) {
|
|
1336
|
+
return this.client.requestJson(
|
|
1337
|
+
`/api/v2/schemas/${schema.value}/records:clear`,
|
|
1338
|
+
{ method: "DELETE" }
|
|
1339
|
+
);
|
|
1340
|
+
}
|
|
1341
|
+
// Only the CLI forms (comparator expressions, "field:dir" sort strings, limit/offset)
|
|
1342
|
+
// are converted; native payloads from --raw/--where-json reach the API untouched.
|
|
1343
|
+
normalizeQueryInput(query) {
|
|
1344
|
+
const where = Array.isArray(query.where) ? query.where.map(toWhereNode) : query.where;
|
|
1345
|
+
const sort = Array.isArray(query.sort) ? query.sort.map(toSort) : query.sort;
|
|
1346
|
+
return {
|
|
1347
|
+
...query,
|
|
1348
|
+
select: query.select,
|
|
1349
|
+
where,
|
|
1350
|
+
sort,
|
|
1351
|
+
page: query.limit !== void 0 || query.offset !== void 0 ? {
|
|
1352
|
+
offset: query.offset,
|
|
1353
|
+
limit: query.limit
|
|
1354
|
+
} : query.page,
|
|
1355
|
+
limit: void 0,
|
|
1356
|
+
offset: void 0
|
|
1357
|
+
};
|
|
1358
|
+
}
|
|
1359
|
+
};
|
|
1360
|
+
|
|
1361
|
+
// src/api/schemas.ts
|
|
1362
|
+
function jsonOptions3(body, method) {
|
|
1363
|
+
return {
|
|
1364
|
+
method,
|
|
1365
|
+
headers: {
|
|
1366
|
+
"content-type": "application/json"
|
|
1367
|
+
},
|
|
1368
|
+
body: JSON.stringify(body)
|
|
1369
|
+
};
|
|
1370
|
+
}
|
|
1371
|
+
var SchemasApi = class {
|
|
1372
|
+
constructor(client) {
|
|
1373
|
+
this.client = client;
|
|
1374
|
+
}
|
|
1375
|
+
listSchemas() {
|
|
1376
|
+
return this.client.getJson("/api/v2/schemas");
|
|
1377
|
+
}
|
|
1378
|
+
getSchema(schema) {
|
|
1379
|
+
return this.client.getJson(`/api/v2/schemas/${schema.value}`);
|
|
1380
|
+
}
|
|
1381
|
+
createSchema(input) {
|
|
1382
|
+
return this.client.requestJson("/api/v2/schemas", jsonOptions3(input, "POST"));
|
|
1383
|
+
}
|
|
1384
|
+
updateSchema(schema, input) {
|
|
1385
|
+
return this.client.requestJson(
|
|
1386
|
+
`/api/v2/schemas/${schema.value}`,
|
|
1387
|
+
jsonOptions3(input, "PATCH")
|
|
1388
|
+
);
|
|
1389
|
+
}
|
|
1390
|
+
setUniqueFields(schema, input) {
|
|
1391
|
+
return this.client.requestJson(
|
|
1392
|
+
`/api/v2/schemas/${schema.value}/unique-fields`,
|
|
1393
|
+
jsonOptions3(input, "PUT")
|
|
1394
|
+
);
|
|
1395
|
+
}
|
|
1396
|
+
deleteSchema(schema) {
|
|
1397
|
+
return this.client.requestJson(
|
|
1398
|
+
`/api/v2/schemas/${schema.value}`,
|
|
1399
|
+
{ method: "DELETE" }
|
|
1400
|
+
);
|
|
1401
|
+
}
|
|
1402
|
+
async listFields(schema) {
|
|
1403
|
+
const result = await this.getSchema(schema);
|
|
1404
|
+
return Array.isArray(result.fields) ? result.fields : [];
|
|
1405
|
+
}
|
|
1406
|
+
getField(schema, field) {
|
|
1407
|
+
return this.client.getJson(
|
|
1408
|
+
`/api/v2/schemas/${schema.value}/fields/${field.value}`
|
|
1409
|
+
);
|
|
1410
|
+
}
|
|
1411
|
+
createField(schema, input) {
|
|
1412
|
+
return this.client.requestJson(
|
|
1413
|
+
`/api/v2/schemas/${schema.value}/fields`,
|
|
1414
|
+
jsonOptions3(input, "POST")
|
|
1415
|
+
);
|
|
1416
|
+
}
|
|
1417
|
+
updateField(schema, field, input) {
|
|
1418
|
+
return this.client.requestJson(
|
|
1419
|
+
`/api/v2/schemas/${schema.value}/fields/${field.value}`,
|
|
1420
|
+
jsonOptions3(input, "PATCH")
|
|
1421
|
+
);
|
|
1422
|
+
}
|
|
1423
|
+
deleteField(schema, field) {
|
|
1424
|
+
return this.client.requestJson(
|
|
1425
|
+
`/api/v2/schemas/${schema.value}/fields/${field.value}`,
|
|
1426
|
+
{ method: "DELETE" }
|
|
1427
|
+
);
|
|
1428
|
+
}
|
|
1429
|
+
};
|
|
1430
|
+
|
|
1247
1431
|
// src/parsers/kv.ts
|
|
1248
1432
|
function splitAssignment(input) {
|
|
1249
1433
|
const separatorIndex = input.indexOf("=");
|
|
@@ -1278,6 +1462,8 @@ function createAutomationsApi(command, filePath) {
|
|
|
1278
1462
|
const { client, ...runtime } = createCommandContext(command, filePath);
|
|
1279
1463
|
return {
|
|
1280
1464
|
api: new AutomationsApi(client),
|
|
1465
|
+
records: new RecordsApi(client),
|
|
1466
|
+
schemas: new SchemasApi(client),
|
|
1281
1467
|
...runtime
|
|
1282
1468
|
};
|
|
1283
1469
|
}
|
|
@@ -1606,6 +1792,99 @@ function readConditions(literalConditions, jsonConditions, label) {
|
|
|
1606
1792
|
)
|
|
1607
1793
|
];
|
|
1608
1794
|
}
|
|
1795
|
+
var TODAY_COMPARATORS = /* @__PURE__ */ new Set(["eq", "ne", "gt", "ge", "lt", "le"]);
|
|
1796
|
+
var MAX_TODAY_OFFSET_DAYS = 3650;
|
|
1797
|
+
var NO_RECORD_ID = "00000000-0000-0000-0000-000000000000";
|
|
1798
|
+
function todayConditionFormatError(input, problem) {
|
|
1799
|
+
return new CliError(
|
|
1800
|
+
"invalid_cli_usage",
|
|
1801
|
+
`Expected --condition-today in the form field:comparator[:\xB1N] (comparator eq, ne, gt, ge, lt or le; N whole days, at most ${MAX_TODAY_OFFSET_DAYS}), received "${input}": ${problem}.`
|
|
1802
|
+
);
|
|
1803
|
+
}
|
|
1804
|
+
function parseTodayCondition(input) {
|
|
1805
|
+
const parts = input.split(":").map((part) => part.trim());
|
|
1806
|
+
if (parts.length < 2 || parts.length > 3 || !parts[0] || !parts[1]) {
|
|
1807
|
+
throw todayConditionFormatError(input, "use field:comparator or field:comparator:\xB1N");
|
|
1808
|
+
}
|
|
1809
|
+
const [field, rawComparator, rawOffset] = parts;
|
|
1810
|
+
const comparator = rawComparator.toLowerCase();
|
|
1811
|
+
if (!TODAY_COMPARATORS.has(comparator)) {
|
|
1812
|
+
throw todayConditionFormatError(input, `comparator "${rawComparator}" does not compare dates`);
|
|
1813
|
+
}
|
|
1814
|
+
let offset = 0;
|
|
1815
|
+
if (rawOffset !== void 0) {
|
|
1816
|
+
if (!/^[+-]?\d+$/.test(rawOffset)) {
|
|
1817
|
+
throw todayConditionFormatError(input, `"${rawOffset}" is not a whole number of days`);
|
|
1818
|
+
}
|
|
1819
|
+
offset = Number(rawOffset);
|
|
1820
|
+
if (Math.abs(offset) > MAX_TODAY_OFFSET_DAYS) {
|
|
1821
|
+
throw todayConditionFormatError(input, `${offset} days is out of range`);
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
return { field, comparator, offset };
|
|
1825
|
+
}
|
|
1826
|
+
function isTimeZone(value) {
|
|
1827
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
1828
|
+
return false;
|
|
1829
|
+
}
|
|
1830
|
+
try {
|
|
1831
|
+
new Intl.DateTimeFormat("en-US", { timeZone: value });
|
|
1832
|
+
return true;
|
|
1833
|
+
} catch {
|
|
1834
|
+
return false;
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
async function resolveSchemaUuid(schemas, schemaReference) {
|
|
1838
|
+
const selector = parseUuidOrSlugSelector(schemaReference);
|
|
1839
|
+
if (selector.kind === "uuid") {
|
|
1840
|
+
return selector;
|
|
1841
|
+
}
|
|
1842
|
+
const match = (await schemas.listSchemas()).find((entry) => entry.slug === selector.value);
|
|
1843
|
+
if (!match || typeof match.id !== "string") {
|
|
1844
|
+
throw new CliError("invalid_cli_usage", `Schema "${selector.value}" not found.`);
|
|
1845
|
+
}
|
|
1846
|
+
return { kind: "uuid", value: match.id };
|
|
1847
|
+
}
|
|
1848
|
+
async function readWorkspaceTimeZone(apis, schemaReference) {
|
|
1849
|
+
const schema = await resolveSchemaUuid(apis.schemas, schemaReference);
|
|
1850
|
+
const result = await apis.records.aggregateRecords(schema, {
|
|
1851
|
+
metrics: [{ op: "count" }],
|
|
1852
|
+
where: [{ field: "id", op: "eq", value: NO_RECORD_ID }]
|
|
1853
|
+
});
|
|
1854
|
+
const timeZone = result?.meta?.timezone;
|
|
1855
|
+
if (!isTimeZone(timeZone)) {
|
|
1856
|
+
throw new CliError(
|
|
1857
|
+
"invalid_cli_usage",
|
|
1858
|
+
`Could not read the workspace time zone that --condition-today needs. Use --condition-json with "ianaTimeZone" instead.`
|
|
1859
|
+
);
|
|
1860
|
+
}
|
|
1861
|
+
return timeZone;
|
|
1862
|
+
}
|
|
1863
|
+
async function withTodayConditions(apis, options, schemaReference, schemaFlag) {
|
|
1864
|
+
const specs = (options.conditionToday ?? []).map(parseTodayCondition);
|
|
1865
|
+
if (specs.length === 0) {
|
|
1866
|
+
return options;
|
|
1867
|
+
}
|
|
1868
|
+
if (typeof schemaReference !== "string" || schemaReference.trim().length === 0) {
|
|
1869
|
+
throw new CliError(
|
|
1870
|
+
"invalid_cli_usage",
|
|
1871
|
+
`--condition-today needs the table of the condition: provide ${schemaFlag}.`
|
|
1872
|
+
);
|
|
1873
|
+
}
|
|
1874
|
+
const ianaTimeZone = await readWorkspaceTimeZone(apis, schemaReference.trim());
|
|
1875
|
+
const todayConditions = specs.map(
|
|
1876
|
+
(spec) => JSON.stringify({
|
|
1877
|
+
field: spec.field,
|
|
1878
|
+
comparator: spec.comparator,
|
|
1879
|
+
values: [JSON.stringify({ type: "today", offset: spec.offset, ianaTimeZone })]
|
|
1880
|
+
})
|
|
1881
|
+
);
|
|
1882
|
+
return { ...options, conditionJson: [...options.conditionJson ?? [], ...todayConditions] };
|
|
1883
|
+
}
|
|
1884
|
+
function rawConfigValue(raw, rawFile, key) {
|
|
1885
|
+
const input = readJsonObjectOption(raw, rawFile, "--raw", "--raw-file");
|
|
1886
|
+
return isJsonObject(input.config) ? input.config[key] : void 0;
|
|
1887
|
+
}
|
|
1609
1888
|
function resolveFolder(folders, selector) {
|
|
1610
1889
|
if (selector.kind === "uuid") {
|
|
1611
1890
|
const match = folders.find((folder) => folder.id === selector.value);
|
|
@@ -1812,14 +2091,55 @@ function buildActionInput(options, mode) {
|
|
|
1812
2091
|
if (options.targetSchema !== void 0) {
|
|
1813
2092
|
config.targetSchemaId = options.targetSchema;
|
|
1814
2093
|
}
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
2094
|
+
const isSendEmail = input.type === "send_email";
|
|
2095
|
+
const toRecipients = options.to ?? [];
|
|
2096
|
+
if (isSendEmail) {
|
|
2097
|
+
if ((options.var?.length ?? 0) > 0) {
|
|
2098
|
+
throw new CliError(
|
|
2099
|
+
"invalid_cli_usage",
|
|
2100
|
+
'send_email variables are objects ({"sourceType","fieldId","actionId"}): set config.variables with "--raw-file", not "--var".'
|
|
2101
|
+
);
|
|
2102
|
+
}
|
|
2103
|
+
if (toRecipients.length > 0) {
|
|
2104
|
+
config.to = [...toRecipients];
|
|
2105
|
+
}
|
|
2106
|
+
if ((options.cc?.length ?? 0) > 0) {
|
|
2107
|
+
config.cc = [...options.cc ?? []];
|
|
2108
|
+
}
|
|
2109
|
+
if ((options.bcc?.length ?? 0) > 0) {
|
|
2110
|
+
config.bcc = [...options.bcc ?? []];
|
|
2111
|
+
}
|
|
2112
|
+
if (options.replyTo !== void 0) {
|
|
2113
|
+
config.replyTo = options.replyTo;
|
|
2114
|
+
}
|
|
2115
|
+
if (options.subject !== void 0) {
|
|
2116
|
+
config.subject = options.subject;
|
|
2117
|
+
}
|
|
2118
|
+
if (options.message !== void 0) {
|
|
2119
|
+
config.body = options.message;
|
|
2120
|
+
}
|
|
2121
|
+
} else {
|
|
2122
|
+
if ((options.cc?.length ?? 0) > 0 || (options.bcc?.length ?? 0) > 0 || options.replyTo !== void 0) {
|
|
2123
|
+
throw new CliError(
|
|
2124
|
+
"invalid_cli_usage",
|
|
2125
|
+
'"--cc", "--bcc" and "--reply-to" are only for send_email actions: add "--type send_email".'
|
|
2126
|
+
);
|
|
2127
|
+
}
|
|
2128
|
+
if (toRecipients.length > 1) {
|
|
2129
|
+
throw new CliError(
|
|
2130
|
+
"invalid_cli_usage",
|
|
2131
|
+
'send_message takes one "--to"; repeat "--to" only for send_email.'
|
|
2132
|
+
);
|
|
2133
|
+
}
|
|
2134
|
+
if (toRecipients.length === 1) {
|
|
2135
|
+
mappings.recipients = toRecipients[0];
|
|
2136
|
+
}
|
|
2137
|
+
if (options.subject !== void 0) {
|
|
2138
|
+
mappings.subject = options.subject;
|
|
2139
|
+
}
|
|
2140
|
+
if (options.message !== void 0) {
|
|
2141
|
+
mappings.body = options.message;
|
|
2142
|
+
}
|
|
1823
2143
|
}
|
|
1824
2144
|
if (!isEmptyObject(mappings)) {
|
|
1825
2145
|
config.fieldMapping = mappings;
|
|
@@ -2062,12 +2382,17 @@ function addTriggerPayloadOptions(command) {
|
|
|
2062
2382
|
[]
|
|
2063
2383
|
).option(
|
|
2064
2384
|
"--condition <field:comparator:value>",
|
|
2065
|
-
"trigger condition (use field:comparator for comparators without value: chg, ie, ine)",
|
|
2385
|
+
"trigger condition (use field:comparator for comparators without value: chg, ie, ine); the value is split on commas, so use --condition-json or --condition-today for JSON values",
|
|
2066
2386
|
collectValues,
|
|
2067
2387
|
[]
|
|
2068
2388
|
).option(
|
|
2069
2389
|
"--condition-json <json>",
|
|
2070
|
-
|
|
2390
|
+
'trigger condition as JSON: {"field","comparator","values"}; each value is a string, JSON included (written as text)',
|
|
2391
|
+
collectValues,
|
|
2392
|
+
[]
|
|
2393
|
+
).option(
|
|
2394
|
+
"--condition-today <field:comparator[:\xB1N]>",
|
|
2395
|
+
"date condition relative to today in the workspace time zone, e.g. due-date:eq:+5 or created:lt:-30 (comparators eq, ne, gt, ge, lt, le); needs --trigger-schema or config.schemaId",
|
|
2071
2396
|
collectValues,
|
|
2072
2397
|
[]
|
|
2073
2398
|
).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");
|
|
@@ -2076,10 +2401,14 @@ var ACTION_TYPES_HELP = `
|
|
|
2076
2401
|
Action types and their flags:
|
|
2077
2402
|
create_record --target-schema, --map, --map-json
|
|
2078
2403
|
update_record --target-schema, --use-trigger-record, --map,
|
|
2079
|
-
--condition, --condition-json
|
|
2080
|
-
search_records --target-schema, --condition, --condition-json
|
|
2081
|
-
|
|
2404
|
+
--condition, --condition-json, --condition-today
|
|
2405
|
+
search_records --target-schema, --condition, --condition-json,
|
|
2406
|
+
--condition-today
|
|
2407
|
+
send_message --to, --subject, --message (in-app notification, not an email)
|
|
2082
2408
|
(--map / --map-json also accepted for extra keys)
|
|
2409
|
+
send_email --connection, --to, --cc, --bcc, --reply-to, --subject,
|
|
2410
|
+
--message; variables and attachments via --raw-file
|
|
2411
|
+
(see --example "automations actions add")
|
|
2083
2412
|
http_request --method, --url, --header, --body, --content-type,
|
|
2084
2413
|
--timeout-ms, --var, --auth-mode, --connection
|
|
2085
2414
|
execute_plugin --plugin, --arg, --arg-json
|
|
@@ -2089,17 +2418,32 @@ Action types and their flags:
|
|
|
2089
2418
|
function addActionPayloadOptions(command) {
|
|
2090
2419
|
return command.option(
|
|
2091
2420
|
"--type <type>",
|
|
2092
|
-
"action type (create_record|update_record|search_records|send_message|http_request|execute_plugin|generate_document|invoicing)"
|
|
2421
|
+
"action type (create_record|update_record|search_records|send_message|send_email|http_request|execute_plugin|generate_document|invoicing)"
|
|
2093
2422
|
).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(
|
|
2094
2423
|
"--condition <field:comparator:value>",
|
|
2095
|
-
"action condition (use field:comparator for comparators without value: ie, ine)",
|
|
2424
|
+
"action condition (use field:comparator for comparators without value: ie, ine); the value is split on commas, so use --condition-json or --condition-today for JSON values",
|
|
2096
2425
|
collectValues,
|
|
2097
2426
|
[]
|
|
2098
|
-
).option(
|
|
2427
|
+
).option(
|
|
2428
|
+
"--condition-json <json>",
|
|
2429
|
+
'action condition as JSON: {"field","comparator","values"}; each value is a string (JSON included, written as text) or {"rawValue"|"source"}',
|
|
2430
|
+
collectValues,
|
|
2431
|
+
[]
|
|
2432
|
+
).option(
|
|
2433
|
+
"--condition-today <field:comparator[:\xB1N]>",
|
|
2434
|
+
"date condition relative to today in the workspace time zone, e.g. due-date:eq:+5 (comparators eq, ne, gt, ge, lt, le); needs --target-schema or config.targetSchemaId",
|
|
2435
|
+
collectValues,
|
|
2436
|
+
[]
|
|
2437
|
+
).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(
|
|
2099
2438
|
"--timeout-ms <n>",
|
|
2100
2439
|
"HTTP timeout in milliseconds",
|
|
2101
2440
|
parseNonNegativeInteger
|
|
2102
|
-
).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(
|
|
2441
|
+
).option("--var <key=value>", "HTTP variable", collectValues, []).option("--auth-mode <mode>", "HTTP auth mode").option("--connection <uuid>", "connection id: verified SMTP connection for send_email, stored connection 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(
|
|
2442
|
+
"--to <recipient>",
|
|
2443
|
+
"send_email recipient (repeatable; an address or ${key} declared in config.variables) or the send_message recipient (maps to fieldMapping.recipients)",
|
|
2444
|
+
collectValues,
|
|
2445
|
+
[]
|
|
2446
|
+
).option("--cc <recipient>", "send_email copy recipient (repeatable)", collectValues, []).option("--bcc <recipient>", "send_email blind copy recipient (repeatable)", collectValues, []).option("--reply-to <address>", "send_email reply-to address").option("--subject <text>", "send_email or send_message subject").option("--message <text>", "send_email HTML body (config.body) or send_message body text (fieldMapping.body)").option("--document-template <uuid>", "generate_document template id").option("--target-file-field <uuid>", "generate_document target FileField id").option("--operation <operation>", "invoicing operation (prepare|issue|refund|cancel|create_correction|prepare_fiscal_correction|execute_fiscal_correction)").option("--schema <uuid>", "invoicing source draft, invoice or fiscal correction schema id").option("--input <key=value>", "invoicing literal input (repeatable)", collectValues, []).option("--input-json <key=json>", "invoicing literal or source input (repeatable)", collectValues, []).option("--raw <json>", "raw action JSON payload").option("--raw-file <path>", "path to raw action JSON payload").addHelpText("after", ACTION_TYPES_HELP);
|
|
2103
2447
|
}
|
|
2104
2448
|
function registerAutomationsCommands(program, options = {}) {
|
|
2105
2449
|
const filePath = options.configPath ?? defaultConfigPath;
|
|
@@ -2216,9 +2560,15 @@ function registerAutomationsCommands(program, options = {}) {
|
|
|
2216
2560
|
addTriggerPayloadOptions(
|
|
2217
2561
|
automations.command("create").description("Create an automation").requiredOption("--name <name>", "automation name").option("--description <text>", "automation description").option("--folder <folder>", "folder UUID or exact name", parseUuidOrSlugSelector)
|
|
2218
2562
|
).action(async function action(commandOptions) {
|
|
2219
|
-
const { api, json, readOnly } = createAutomationsApi(this, filePath);
|
|
2563
|
+
const { api, records, schemas, json, readOnly } = createAutomationsApi(this, filePath);
|
|
2220
2564
|
ensureWritable("automations create", readOnly, "write");
|
|
2221
|
-
const
|
|
2565
|
+
const options2 = await withTodayConditions(
|
|
2566
|
+
{ records, schemas },
|
|
2567
|
+
commandOptions,
|
|
2568
|
+
commandOptions.triggerSchema ?? rawConfigValue(commandOptions.raw, commandOptions.rawFile, "schemaId"),
|
|
2569
|
+
'"--trigger-schema"'
|
|
2570
|
+
);
|
|
2571
|
+
const data = await api.createAutomation(await buildAutomationCreateInput(api, options2));
|
|
2222
2572
|
if (json) {
|
|
2223
2573
|
emitJson(stdout, "automations create", data, filePath);
|
|
2224
2574
|
return;
|
|
@@ -2281,11 +2631,17 @@ function registerAutomationsCommands(program, options = {}) {
|
|
|
2281
2631
|
addTriggerPayloadOptions(
|
|
2282
2632
|
trigger.command("set").description("Set the trigger for an automation").argument("<automation>", "automation UUID", parseUuidOrSlugSelector)
|
|
2283
2633
|
).action(async function action(automation, commandOptions) {
|
|
2284
|
-
const { api, json, readOnly } = createAutomationsApi(this, filePath);
|
|
2634
|
+
const { api, records, schemas, json, readOnly } = createAutomationsApi(this, filePath);
|
|
2285
2635
|
ensureWritable("automations trigger set", readOnly, "write");
|
|
2636
|
+
const options2 = await withTodayConditions(
|
|
2637
|
+
{ records, schemas },
|
|
2638
|
+
commandOptions,
|
|
2639
|
+
commandOptions.triggerSchema ?? rawConfigValue(commandOptions.raw, commandOptions.rawFile, "schemaId"),
|
|
2640
|
+
'"--trigger-schema"'
|
|
2641
|
+
);
|
|
2286
2642
|
const data = await api.setTrigger(
|
|
2287
2643
|
automation,
|
|
2288
|
-
buildTriggerInput(
|
|
2644
|
+
buildTriggerInput(options2, "required")
|
|
2289
2645
|
);
|
|
2290
2646
|
if (json) {
|
|
2291
2647
|
emitJson(stdout, "automations trigger set", data, filePath);
|
|
@@ -2306,9 +2662,15 @@ function registerAutomationsCommands(program, options = {}) {
|
|
|
2306
2662
|
addActionPayloadOptions(
|
|
2307
2663
|
actions.command("add").description("Add an action to an automation").argument("<automation>", "automation UUID", parseUuidOrSlugSelector)
|
|
2308
2664
|
).action(async function action(automation, commandOptions) {
|
|
2309
|
-
const { api, json, readOnly } = createAutomationsApi(this, filePath);
|
|
2665
|
+
const { api, records, schemas, json, readOnly } = createAutomationsApi(this, filePath);
|
|
2310
2666
|
ensureWritable("automations actions add", readOnly, "write");
|
|
2311
|
-
const
|
|
2667
|
+
const options2 = await withTodayConditions(
|
|
2668
|
+
{ records, schemas },
|
|
2669
|
+
commandOptions,
|
|
2670
|
+
commandOptions.targetSchema ?? rawConfigValue(commandOptions.raw, commandOptions.rawFile, "targetSchemaId"),
|
|
2671
|
+
'"--target-schema"'
|
|
2672
|
+
);
|
|
2673
|
+
const data = await api.addAction(automation, buildActionInput(options2, "create"));
|
|
2312
2674
|
if (json) {
|
|
2313
2675
|
emitJson(stdout, "automations actions add", data, filePath);
|
|
2314
2676
|
return;
|
|
@@ -2318,9 +2680,15 @@ function registerAutomationsCommands(program, options = {}) {
|
|
|
2318
2680
|
addActionPayloadOptions(
|
|
2319
2681
|
actions.command("update").description("Update an automation action").argument("<automation>", "automation UUID", parseUuidOrSlugSelector).argument("<action>", "action UUID")
|
|
2320
2682
|
).action(async function action(automation, actionId, commandOptions) {
|
|
2321
|
-
const { api, json, readOnly } = createAutomationsApi(this, filePath);
|
|
2683
|
+
const { api, records, schemas, json, readOnly } = createAutomationsApi(this, filePath);
|
|
2322
2684
|
ensureWritable("automations actions update", readOnly, "write");
|
|
2323
|
-
const
|
|
2685
|
+
const options2 = await withTodayConditions(
|
|
2686
|
+
{ records, schemas },
|
|
2687
|
+
commandOptions,
|
|
2688
|
+
commandOptions.targetSchema ?? rawConfigValue(commandOptions.raw, commandOptions.rawFile, "targetSchemaId"),
|
|
2689
|
+
'"--target-schema"'
|
|
2690
|
+
);
|
|
2691
|
+
const data = await api.updateAction(automation, actionId, buildActionInput(options2, "update"));
|
|
2324
2692
|
if (json) {
|
|
2325
2693
|
emitJson(stdout, "automations actions update", data, filePath);
|
|
2326
2694
|
return;
|
|
@@ -2458,7 +2826,7 @@ function registerAutomationsCommands(program, options = {}) {
|
|
|
2458
2826
|
}
|
|
2459
2827
|
|
|
2460
2828
|
// src/api/comments.ts
|
|
2461
|
-
function
|
|
2829
|
+
function jsonOptions4(body, method) {
|
|
2462
2830
|
return {
|
|
2463
2831
|
method,
|
|
2464
2832
|
headers: {
|
|
@@ -2479,7 +2847,7 @@ var CommentsApi = class {
|
|
|
2479
2847
|
createComment(schema, recordId, input) {
|
|
2480
2848
|
return this.client.requestJson(
|
|
2481
2849
|
`/api/v2/schemas/${schema.value}/records/${recordId}/comments`,
|
|
2482
|
-
|
|
2850
|
+
jsonOptions4(input, "POST")
|
|
2483
2851
|
);
|
|
2484
2852
|
}
|
|
2485
2853
|
};
|
|
@@ -2546,7 +2914,7 @@ import { readFileSync as readFileSync3 } from "fs";
|
|
|
2546
2914
|
import { InvalidArgumentError as InvalidArgumentError2 } from "commander";
|
|
2547
2915
|
|
|
2548
2916
|
// src/api/displays.ts
|
|
2549
|
-
function
|
|
2917
|
+
function jsonOptions5(body, method) {
|
|
2550
2918
|
return {
|
|
2551
2919
|
method,
|
|
2552
2920
|
headers: {
|
|
@@ -2569,12 +2937,12 @@ var DisplaysApi = class {
|
|
|
2569
2937
|
return this.client.getJson(`/api/v2/displays/${display.value}`);
|
|
2570
2938
|
}
|
|
2571
2939
|
createDisplay(body) {
|
|
2572
|
-
return this.client.requestJson("/api/v2/displays",
|
|
2940
|
+
return this.client.requestJson("/api/v2/displays", jsonOptions5(body, "POST"));
|
|
2573
2941
|
}
|
|
2574
2942
|
updateDisplay(display, body) {
|
|
2575
2943
|
return this.client.requestJson(
|
|
2576
2944
|
`/api/v2/displays/${display.value}`,
|
|
2577
|
-
|
|
2945
|
+
jsonOptions5(body, "PATCH")
|
|
2578
2946
|
);
|
|
2579
2947
|
}
|
|
2580
2948
|
deleteDisplay(display) {
|
|
@@ -2591,7 +2959,7 @@ var DisplaysApi = class {
|
|
|
2591
2959
|
patchLayout(display, body) {
|
|
2592
2960
|
return this.client.requestJson(
|
|
2593
2961
|
`/api/v2/displays/${display.value}/layout`,
|
|
2594
|
-
|
|
2962
|
+
jsonOptions5(body, "PATCH")
|
|
2595
2963
|
);
|
|
2596
2964
|
}
|
|
2597
2965
|
listTabs(display) {
|
|
@@ -2602,13 +2970,13 @@ var DisplaysApi = class {
|
|
|
2602
2970
|
createTab(display, body) {
|
|
2603
2971
|
return this.client.requestJson(
|
|
2604
2972
|
`/api/v2/displays/${display.value}/tabs`,
|
|
2605
|
-
|
|
2973
|
+
jsonOptions5(body, "POST")
|
|
2606
2974
|
);
|
|
2607
2975
|
}
|
|
2608
2976
|
updateTab(display, tabId, body) {
|
|
2609
2977
|
return this.client.requestJson(
|
|
2610
2978
|
`/api/v2/displays/${display.value}/tabs/${segment2(tabId)}`,
|
|
2611
|
-
|
|
2979
|
+
jsonOptions5(body, "PATCH")
|
|
2612
2980
|
);
|
|
2613
2981
|
}
|
|
2614
2982
|
deleteTab(display, tabId) {
|
|
@@ -2630,13 +2998,13 @@ var DisplaysApi = class {
|
|
|
2630
2998
|
createVariable(display, body) {
|
|
2631
2999
|
return this.client.requestJson(
|
|
2632
3000
|
`/api/v2/displays/${display.value}/variables`,
|
|
2633
|
-
|
|
3001
|
+
jsonOptions5(body, "POST")
|
|
2634
3002
|
);
|
|
2635
3003
|
}
|
|
2636
3004
|
updateVariable(display, variableId, body) {
|
|
2637
3005
|
return this.client.requestJson(
|
|
2638
3006
|
`/api/v2/displays/${display.value}/variables/${segment2(variableId)}`,
|
|
2639
|
-
|
|
3007
|
+
jsonOptions5(body, "PATCH")
|
|
2640
3008
|
);
|
|
2641
3009
|
}
|
|
2642
3010
|
deleteVariable(display, variableId) {
|
|
@@ -2658,13 +3026,13 @@ var DisplaysApi = class {
|
|
|
2658
3026
|
createWidget(display, body) {
|
|
2659
3027
|
return this.client.requestJson(
|
|
2660
3028
|
`/api/v2/displays/${display.value}/widgets`,
|
|
2661
|
-
|
|
3029
|
+
jsonOptions5(body, "POST")
|
|
2662
3030
|
);
|
|
2663
3031
|
}
|
|
2664
3032
|
updateWidget(display, widgetId, body) {
|
|
2665
3033
|
return this.client.requestJson(
|
|
2666
3034
|
`/api/v2/displays/${display.value}/widgets/${segment2(widgetId)}`,
|
|
2667
|
-
|
|
3035
|
+
jsonOptions5(body, "PATCH")
|
|
2668
3036
|
);
|
|
2669
3037
|
}
|
|
2670
3038
|
deleteWidget(display, widgetId) {
|
|
@@ -2676,13 +3044,13 @@ var DisplaysApi = class {
|
|
|
2676
3044
|
createNavigationTarget(display, body) {
|
|
2677
3045
|
return this.client.requestJson(
|
|
2678
3046
|
`/api/v2/displays/${display.value}/navigation-targets`,
|
|
2679
|
-
|
|
3047
|
+
jsonOptions5(body, "POST")
|
|
2680
3048
|
);
|
|
2681
3049
|
}
|
|
2682
3050
|
updateNavigationTarget(display, targetId, body) {
|
|
2683
3051
|
return this.client.requestJson(
|
|
2684
3052
|
`/api/v2/displays/${display.value}/navigation-targets/${segment2(targetId)}`,
|
|
2685
|
-
|
|
3053
|
+
jsonOptions5(body, "PATCH")
|
|
2686
3054
|
);
|
|
2687
3055
|
}
|
|
2688
3056
|
deleteNavigationTarget(display, targetId) {
|
|
@@ -2699,7 +3067,7 @@ var DisplaysApi = class {
|
|
|
2699
3067
|
setCrossWidgetFilter(display, body) {
|
|
2700
3068
|
return this.client.requestJson(
|
|
2701
3069
|
`/api/v2/displays/${display.value}/cross-widget-filter`,
|
|
2702
|
-
|
|
3070
|
+
jsonOptions5(body, "PUT")
|
|
2703
3071
|
);
|
|
2704
3072
|
}
|
|
2705
3073
|
deleteCrossWidgetFilter(display) {
|
|
@@ -2714,13 +3082,13 @@ var DisplaysApi = class {
|
|
|
2714
3082
|
createFolder(body) {
|
|
2715
3083
|
return this.client.requestJson(
|
|
2716
3084
|
"/api/v2/display-folders",
|
|
2717
|
-
|
|
3085
|
+
jsonOptions5(body, "POST")
|
|
2718
3086
|
);
|
|
2719
3087
|
}
|
|
2720
3088
|
updateFolder(folder, body) {
|
|
2721
3089
|
return this.client.requestJson(
|
|
2722
3090
|
`/api/v2/display-folders/${folder.value}`,
|
|
2723
|
-
|
|
3091
|
+
jsonOptions5(body, "PATCH")
|
|
2724
3092
|
);
|
|
2725
3093
|
}
|
|
2726
3094
|
deleteFolder(folder) {
|
|
@@ -2732,7 +3100,7 @@ var DisplaysApi = class {
|
|
|
2732
3100
|
moveDisplay(input) {
|
|
2733
3101
|
return this.client.requestJson(
|
|
2734
3102
|
"/api/v2/display-folders/displays:move",
|
|
2735
|
-
|
|
3103
|
+
jsonOptions5(input, "POST")
|
|
2736
3104
|
);
|
|
2737
3105
|
}
|
|
2738
3106
|
};
|
|
@@ -3796,7 +4164,7 @@ function registerDisplaysCommands(program, options = {}) {
|
|
|
3796
4164
|
import { basename } from "path";
|
|
3797
4165
|
|
|
3798
4166
|
// src/api/document-templates.ts
|
|
3799
|
-
function
|
|
4167
|
+
function jsonOptions6(body, method) {
|
|
3800
4168
|
return {
|
|
3801
4169
|
method,
|
|
3802
4170
|
headers: {
|
|
@@ -3815,13 +4183,13 @@ var DocumentTemplatesApi = class {
|
|
|
3815
4183
|
createTemplate(input) {
|
|
3816
4184
|
return this.client.requestJson(
|
|
3817
4185
|
"/api/v2/document-templates",
|
|
3818
|
-
|
|
4186
|
+
jsonOptions6(input, "POST")
|
|
3819
4187
|
);
|
|
3820
4188
|
}
|
|
3821
4189
|
updateTemplate(template, input) {
|
|
3822
4190
|
return this.client.requestJson(
|
|
3823
4191
|
`/api/v2/document-templates/${encodeURIComponent(template.value)}`,
|
|
3824
|
-
|
|
4192
|
+
jsonOptions6(input, "PATCH")
|
|
3825
4193
|
);
|
|
3826
4194
|
}
|
|
3827
4195
|
deleteTemplate(template) {
|
|
@@ -4494,7 +4862,7 @@ function registerMembersCommands(program, options = {}) {
|
|
|
4494
4862
|
import { readFileSync as readFileSync4 } from "fs";
|
|
4495
4863
|
|
|
4496
4864
|
// src/api/navigation.ts
|
|
4497
|
-
function
|
|
4865
|
+
function jsonOptions7(body, method) {
|
|
4498
4866
|
return {
|
|
4499
4867
|
method,
|
|
4500
4868
|
headers: {
|
|
@@ -4513,13 +4881,13 @@ var NavigationApi = class {
|
|
|
4513
4881
|
createFolder(body) {
|
|
4514
4882
|
return this.client.requestJson(
|
|
4515
4883
|
"/api/v2/navigation/folders",
|
|
4516
|
-
|
|
4884
|
+
jsonOptions7(body, "POST")
|
|
4517
4885
|
);
|
|
4518
4886
|
}
|
|
4519
4887
|
updateFolder(folder, body) {
|
|
4520
4888
|
return this.client.requestJson(
|
|
4521
4889
|
`/api/v2/navigation/folders/${folder.value}`,
|
|
4522
|
-
|
|
4890
|
+
jsonOptions7(body, "PATCH")
|
|
4523
4891
|
);
|
|
4524
4892
|
}
|
|
4525
4893
|
deleteFolder(folder) {
|
|
@@ -4531,7 +4899,7 @@ var NavigationApi = class {
|
|
|
4531
4899
|
moveResource(body) {
|
|
4532
4900
|
return this.client.requestJson(
|
|
4533
4901
|
"/api/v2/navigation/resources:move",
|
|
4534
|
-
|
|
4902
|
+
jsonOptions7(body, "POST")
|
|
4535
4903
|
);
|
|
4536
4904
|
}
|
|
4537
4905
|
};
|
|
@@ -4869,192 +5237,6 @@ function registerProfilesCommands(program, options = {}) {
|
|
|
4869
5237
|
// src/commands/records.ts
|
|
4870
5238
|
import { readFileSync as readFileSync5 } from "fs";
|
|
4871
5239
|
import { InvalidArgumentError as InvalidArgumentError3 } from "commander";
|
|
4872
|
-
|
|
4873
|
-
// src/api/records.ts
|
|
4874
|
-
function isQueryExpression(entry) {
|
|
4875
|
-
return typeof entry === "object" && entry !== null && "comparator" in entry && !("op" in entry);
|
|
4876
|
-
}
|
|
4877
|
-
function toWhereNode(entry) {
|
|
4878
|
-
if (!isQueryExpression(entry)) {
|
|
4879
|
-
return entry;
|
|
4880
|
-
}
|
|
4881
|
-
return {
|
|
4882
|
-
field: entry.field,
|
|
4883
|
-
op: entry.comparator,
|
|
4884
|
-
value: entry.value
|
|
4885
|
-
};
|
|
4886
|
-
}
|
|
4887
|
-
function toSort(entry) {
|
|
4888
|
-
if (typeof entry !== "string") {
|
|
4889
|
-
return entry;
|
|
4890
|
-
}
|
|
4891
|
-
const [field = "", direction = "asc"] = entry.split(":");
|
|
4892
|
-
return {
|
|
4893
|
-
field,
|
|
4894
|
-
direction: direction.toUpperCase()
|
|
4895
|
-
};
|
|
4896
|
-
}
|
|
4897
|
-
function jsonOptions6(body, method) {
|
|
4898
|
-
return {
|
|
4899
|
-
method,
|
|
4900
|
-
headers: {
|
|
4901
|
-
"content-type": "application/json"
|
|
4902
|
-
},
|
|
4903
|
-
body: JSON.stringify(body)
|
|
4904
|
-
};
|
|
4905
|
-
}
|
|
4906
|
-
var RecordsApi = class {
|
|
4907
|
-
constructor(client) {
|
|
4908
|
-
this.client = client;
|
|
4909
|
-
}
|
|
4910
|
-
listRecords(schema, query) {
|
|
4911
|
-
const params = new URLSearchParams();
|
|
4912
|
-
if (query.limit !== void 0) {
|
|
4913
|
-
params.set("limit", String(query.limit));
|
|
4914
|
-
}
|
|
4915
|
-
if (query.offset !== void 0) {
|
|
4916
|
-
params.set("offset", String(query.offset));
|
|
4917
|
-
}
|
|
4918
|
-
const path = `/api/v2/schemas/${schema.value}/records`;
|
|
4919
|
-
const queryString = params.toString();
|
|
4920
|
-
return this.client.getJson(
|
|
4921
|
-
queryString ? `${path}?${queryString}` : path
|
|
4922
|
-
);
|
|
4923
|
-
}
|
|
4924
|
-
queryRecords(schema, query) {
|
|
4925
|
-
const body = this.normalizeQueryInput(query);
|
|
4926
|
-
return this.client.requestJson(
|
|
4927
|
-
`/api/v2/schemas/${schema.value}/records:query`,
|
|
4928
|
-
jsonOptions6(body, "POST")
|
|
4929
|
-
);
|
|
4930
|
-
}
|
|
4931
|
-
aggregateRecords(schema, input) {
|
|
4932
|
-
const body = Array.isArray(input.where) ? { ...input, where: input.where.map(toWhereNode) } : input;
|
|
4933
|
-
return this.client.requestJson(
|
|
4934
|
-
`/api/v2/schemas/${schema.value}/records:aggregate`,
|
|
4935
|
-
jsonOptions6(body, "POST")
|
|
4936
|
-
);
|
|
4937
|
-
}
|
|
4938
|
-
getRecord(schema, record) {
|
|
4939
|
-
return this.client.getJson(
|
|
4940
|
-
`/api/v2/schemas/${schema.value}/records/${record.value}`
|
|
4941
|
-
);
|
|
4942
|
-
}
|
|
4943
|
-
createRecords(schema, records) {
|
|
4944
|
-
return this.client.requestJson(
|
|
4945
|
-
`/api/v2/schemas/${schema.value}/records`,
|
|
4946
|
-
jsonOptions6({ records }, "POST")
|
|
4947
|
-
);
|
|
4948
|
-
}
|
|
4949
|
-
updateRecord(schema, record, input) {
|
|
4950
|
-
return this.client.requestJson(
|
|
4951
|
-
`/api/v2/schemas/${schema.value}/records/${record.value}`,
|
|
4952
|
-
jsonOptions6(input, "PATCH")
|
|
4953
|
-
);
|
|
4954
|
-
}
|
|
4955
|
-
deleteRecords(schema, recordIds) {
|
|
4956
|
-
return this.client.requestJson(
|
|
4957
|
-
`/api/v2/schemas/${schema.value}/records:delete`,
|
|
4958
|
-
jsonOptions6({ recordIds }, "POST")
|
|
4959
|
-
);
|
|
4960
|
-
}
|
|
4961
|
-
clearRecords(schema) {
|
|
4962
|
-
return this.client.requestJson(
|
|
4963
|
-
`/api/v2/schemas/${schema.value}/records:clear`,
|
|
4964
|
-
{ method: "DELETE" }
|
|
4965
|
-
);
|
|
4966
|
-
}
|
|
4967
|
-
// Only the CLI forms (comparator expressions, "field:dir" sort strings, limit/offset)
|
|
4968
|
-
// are converted; native payloads from --raw/--where-json reach the API untouched.
|
|
4969
|
-
normalizeQueryInput(query) {
|
|
4970
|
-
const where = Array.isArray(query.where) ? query.where.map(toWhereNode) : query.where;
|
|
4971
|
-
const sort = Array.isArray(query.sort) ? query.sort.map(toSort) : query.sort;
|
|
4972
|
-
return {
|
|
4973
|
-
...query,
|
|
4974
|
-
select: query.select,
|
|
4975
|
-
where,
|
|
4976
|
-
sort,
|
|
4977
|
-
page: query.limit !== void 0 || query.offset !== void 0 ? {
|
|
4978
|
-
offset: query.offset,
|
|
4979
|
-
limit: query.limit
|
|
4980
|
-
} : query.page,
|
|
4981
|
-
limit: void 0,
|
|
4982
|
-
offset: void 0
|
|
4983
|
-
};
|
|
4984
|
-
}
|
|
4985
|
-
};
|
|
4986
|
-
|
|
4987
|
-
// src/api/schemas.ts
|
|
4988
|
-
function jsonOptions7(body, method) {
|
|
4989
|
-
return {
|
|
4990
|
-
method,
|
|
4991
|
-
headers: {
|
|
4992
|
-
"content-type": "application/json"
|
|
4993
|
-
},
|
|
4994
|
-
body: JSON.stringify(body)
|
|
4995
|
-
};
|
|
4996
|
-
}
|
|
4997
|
-
var SchemasApi = class {
|
|
4998
|
-
constructor(client) {
|
|
4999
|
-
this.client = client;
|
|
5000
|
-
}
|
|
5001
|
-
listSchemas() {
|
|
5002
|
-
return this.client.getJson("/api/v2/schemas");
|
|
5003
|
-
}
|
|
5004
|
-
getSchema(schema) {
|
|
5005
|
-
return this.client.getJson(`/api/v2/schemas/${schema.value}`);
|
|
5006
|
-
}
|
|
5007
|
-
createSchema(input) {
|
|
5008
|
-
return this.client.requestJson("/api/v2/schemas", jsonOptions7(input, "POST"));
|
|
5009
|
-
}
|
|
5010
|
-
updateSchema(schema, input) {
|
|
5011
|
-
return this.client.requestJson(
|
|
5012
|
-
`/api/v2/schemas/${schema.value}`,
|
|
5013
|
-
jsonOptions7(input, "PATCH")
|
|
5014
|
-
);
|
|
5015
|
-
}
|
|
5016
|
-
setUniqueFields(schema, input) {
|
|
5017
|
-
return this.client.requestJson(
|
|
5018
|
-
`/api/v2/schemas/${schema.value}/unique-fields`,
|
|
5019
|
-
jsonOptions7(input, "PUT")
|
|
5020
|
-
);
|
|
5021
|
-
}
|
|
5022
|
-
deleteSchema(schema) {
|
|
5023
|
-
return this.client.requestJson(
|
|
5024
|
-
`/api/v2/schemas/${schema.value}`,
|
|
5025
|
-
{ method: "DELETE" }
|
|
5026
|
-
);
|
|
5027
|
-
}
|
|
5028
|
-
async listFields(schema) {
|
|
5029
|
-
const result = await this.getSchema(schema);
|
|
5030
|
-
return Array.isArray(result.fields) ? result.fields : [];
|
|
5031
|
-
}
|
|
5032
|
-
getField(schema, field) {
|
|
5033
|
-
return this.client.getJson(
|
|
5034
|
-
`/api/v2/schemas/${schema.value}/fields/${field.value}`
|
|
5035
|
-
);
|
|
5036
|
-
}
|
|
5037
|
-
createField(schema, input) {
|
|
5038
|
-
return this.client.requestJson(
|
|
5039
|
-
`/api/v2/schemas/${schema.value}/fields`,
|
|
5040
|
-
jsonOptions7(input, "POST")
|
|
5041
|
-
);
|
|
5042
|
-
}
|
|
5043
|
-
updateField(schema, field, input) {
|
|
5044
|
-
return this.client.requestJson(
|
|
5045
|
-
`/api/v2/schemas/${schema.value}/fields/${field.value}`,
|
|
5046
|
-
jsonOptions7(input, "PATCH")
|
|
5047
|
-
);
|
|
5048
|
-
}
|
|
5049
|
-
deleteField(schema, field) {
|
|
5050
|
-
return this.client.requestJson(
|
|
5051
|
-
`/api/v2/schemas/${schema.value}/fields/${field.value}`,
|
|
5052
|
-
{ method: "DELETE" }
|
|
5053
|
-
);
|
|
5054
|
-
}
|
|
5055
|
-
};
|
|
5056
|
-
|
|
5057
|
-
// src/commands/records.ts
|
|
5058
5240
|
var AGGREGATE_BUCKETS = ["day", "week", "month", "quarter", "year"];
|
|
5059
5241
|
var AGGREGATE_HELP = `
|
|
5060
5242
|
Group by (--group-by <field>[:<bucket>], up to 3):
|