zinkee 0.1.59 → 0.1.61

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/dist/index.js CHANGED
@@ -18,7 +18,7 @@ import {
18
18
  normalizeSchemaFieldUpdatePayload,
19
19
  printTable,
20
20
  toCliError
21
- } from "./chunk-RHSXS2M4.js";
21
+ } from "./chunk-W3BI6KES.js";
22
22
 
23
23
  // src/cli-runner.ts
24
24
  import { realpathSync } from "fs";
@@ -32,6 +32,7 @@ var HOISTABLE_GLOBAL_FLAGS = {
32
32
  "--api-key": "value",
33
33
  "--workspace": "value",
34
34
  "--read-only": "boolean",
35
+ "--idempotency-key": "value",
35
36
  "--json": "boolean"
36
37
  };
37
38
  function isHoistableFlag(flagName) {
@@ -252,7 +253,7 @@ ${list}`
252
253
  };
253
254
  }
254
255
  async function showExamples(commandName, json, stdout, filters = {}) {
255
- const { getCommandExamples } = await import("./examples-EAGYSHFN.js");
256
+ const { getCommandExamples } = await import("./examples-VXDDPC3X.js");
256
257
  const examples = getCommandExamples(commandName, filters);
257
258
  if (examples.length === 0) {
258
259
  throw new CliError("invalid_cli_usage", `No examples registered for "${commandName}".`);
@@ -811,10 +812,22 @@ function resolveRuntimeContext(config, overrides = {}) {
811
812
  }
812
813
 
813
814
  // src/commands/shared.ts
815
+ var IDEMPOTENCY_KEY_PATTERN = /^[A-Za-z0-9._:-]{1,128}$/;
816
+ function validateIdempotencyKey(key) {
817
+ if (key !== void 0 && !IDEMPOTENCY_KEY_PATTERN.test(key)) {
818
+ throw new CliError(
819
+ "invalid_cli_usage",
820
+ `Invalid --idempotency-key "${key}": use 1-128 characters among letters, digits, ".", "_", ":" and "-".`
821
+ );
822
+ }
823
+ return key;
824
+ }
814
825
  function createCommandContext(command, filePath) {
815
826
  try {
827
+ const overrides = command.optsWithGlobals();
828
+ const idempotencyKey = validateIdempotencyKey(overrides.idempotencyKey);
816
829
  const config = readRuntimeConfig(filePath);
817
- const runtime = resolveRuntimeContext(config, command.optsWithGlobals());
830
+ const runtime = resolveRuntimeContext(config, overrides);
818
831
  if (!runtime.baseUrl) {
819
832
  throw new CliError(
820
833
  "configuration_error",
@@ -823,7 +836,7 @@ function createCommandContext(command, filePath) {
823
836
  }
824
837
  const getToken = runtime.session && runtime.workspace ? createWorkspaceTokenProvider({ profile: runtime.profile, ...runtime.session }, runtime.workspace) : void 0;
825
838
  return {
826
- client: new ApiClient({ baseUrl: runtime.baseUrl, apiKey: runtime.apiKey, getToken }),
839
+ client: new ApiClient({ baseUrl: runtime.baseUrl, apiKey: runtime.apiKey, getToken, idempotencyKey }),
827
840
  json: runtime.json,
828
841
  profile: runtime.profile,
829
842
  readOnly: runtime.readOnly
@@ -2721,7 +2734,9 @@ var supportedComparators = /* @__PURE__ */ new Set([
2721
2734
  "lt",
2722
2735
  "lte",
2723
2736
  "contains",
2737
+ "not_contains",
2724
2738
  "in",
2739
+ "between",
2725
2740
  "is_empty",
2726
2741
  "is_not_empty"
2727
2742
  ]);
@@ -2763,8 +2778,13 @@ function normalizeValue(comparator, rawValue) {
2763
2778
  }
2764
2779
  return null;
2765
2780
  }
2766
- if (comparator === "in") {
2781
+ if (comparator === "in" || comparator === "between") {
2767
2782
  const values = rawValue.split(",").map((value) => value.trim()).filter(Boolean);
2783
+ if (comparator === "between" && values.length !== 2) {
2784
+ throw new Error(
2785
+ `Comparator "between" requires exactly two comma-separated values (from,to), got "${rawValue}".`
2786
+ );
2787
+ }
2768
2788
  if (values.length === 0) {
2769
2789
  throw new Error(`Comparator "${comparator}" requires at least one value.`);
2770
2790
  }
@@ -2775,10 +2795,10 @@ function normalizeValue(comparator, rawValue) {
2775
2795
  }
2776
2796
  return rawValue;
2777
2797
  }
2778
- function parseExpression(input) {
2798
+ function parseExpression(input, comparators = supportedComparators) {
2779
2799
  const trimmed = input.trim();
2780
2800
  const [field, comparatorCandidate, rawValue] = trimmed.includes(":") && !trimmed.includes(" ") ? parseColonExpression(trimmed) : parseSpaceExpression(trimmed);
2781
- if (!supportedComparators.has(comparatorCandidate)) {
2801
+ if (!comparators.has(comparatorCandidate)) {
2782
2802
  throw new Error(
2783
2803
  `Unsupported comparator "${comparatorCandidate}" in expression "${input}".`
2784
2804
  );
@@ -2813,6 +2833,9 @@ var COMPARATOR_TO_DISPLAY_OPERATOR = {
2813
2833
  is_empty: "IS_EMPTY",
2814
2834
  is_not_empty: "IS_NOT_EMPTY"
2815
2835
  };
2836
+ var DISPLAY_FILTER_COMPARATORS = new Set(
2837
+ Object.keys(COMPARATOR_TO_DISPLAY_OPERATOR)
2838
+ );
2816
2839
  function toDisplayFilter(parsed) {
2817
2840
  const values = parsed.value === null ? [] : Array.isArray(parsed.value) ? [...parsed.value] : [parsed.value];
2818
2841
  return {
@@ -2823,7 +2846,7 @@ function toDisplayFilter(parsed) {
2823
2846
  }
2824
2847
  function parseFilterExpression(input) {
2825
2848
  try {
2826
- return parseExpression(input);
2849
+ return parseExpression(input, DISPLAY_FILTER_COMPARATORS);
2827
2850
  } catch (error) {
2828
2851
  const message = error instanceof Error ? error.message : "Invalid filter expression.";
2829
2852
  throw new InvalidArgumentError2(message);
@@ -4744,6 +4767,29 @@ import { readFileSync as readFileSync5 } from "fs";
4744
4767
  import { InvalidArgumentError as InvalidArgumentError3 } from "commander";
4745
4768
 
4746
4769
  // src/api/records.ts
4770
+ function isQueryExpression(entry) {
4771
+ return typeof entry === "object" && entry !== null && "comparator" in entry && !("op" in entry);
4772
+ }
4773
+ function toWhereNode(entry) {
4774
+ if (!isQueryExpression(entry)) {
4775
+ return entry;
4776
+ }
4777
+ return {
4778
+ field: entry.field,
4779
+ op: entry.comparator,
4780
+ value: entry.value
4781
+ };
4782
+ }
4783
+ function toSort(entry) {
4784
+ if (typeof entry !== "string") {
4785
+ return entry;
4786
+ }
4787
+ const [field = "", direction = "asc"] = entry.split(":");
4788
+ return {
4789
+ field,
4790
+ direction: direction.toUpperCase()
4791
+ };
4792
+ }
4747
4793
  function jsonOptions6(body, method) {
4748
4794
  return {
4749
4795
  method,
@@ -4807,19 +4853,11 @@ var RecordsApi = class {
4807
4853
  { method: "DELETE" }
4808
4854
  );
4809
4855
  }
4856
+ // Only the CLI forms (comparator expressions, "field:dir" sort strings, limit/offset)
4857
+ // are converted; native payloads from --raw/--where-json reach the API untouched.
4810
4858
  normalizeQueryInput(query) {
4811
- const where = query.where?.map((expression) => ({
4812
- field: expression.field,
4813
- op: expression.comparator,
4814
- value: expression.value
4815
- }));
4816
- const sort = query.sort?.map((entry) => {
4817
- const [field, direction = "asc"] = entry.split(":");
4818
- return {
4819
- field,
4820
- direction: direction.toUpperCase()
4821
- };
4822
- });
4859
+ const where = Array.isArray(query.where) ? query.where.map(toWhereNode) : query.where;
4860
+ const sort = Array.isArray(query.sort) ? query.sort.map(toSort) : query.sort;
4823
4861
  return {
4824
4862
  ...query,
4825
4863
  select: query.select,
@@ -4828,7 +4866,7 @@ var RecordsApi = class {
4828
4866
  page: query.limit !== void 0 || query.offset !== void 0 ? {
4829
4867
  offset: query.offset,
4830
4868
  limit: query.limit
4831
- } : void 0,
4869
+ } : query.page,
4832
4870
  limit: void 0,
4833
4871
  offset: void 0
4834
4872
  };
@@ -5041,13 +5079,45 @@ function toQueryExpressions(expressions) {
5041
5079
  value: expression.value
5042
5080
  }));
5043
5081
  }
5082
+ function parseWhereJson(input) {
5083
+ let parsed;
5084
+ try {
5085
+ parsed = JSON.parse(input);
5086
+ } catch (error) {
5087
+ const message = error instanceof Error ? error.message : "Invalid JSON.";
5088
+ throw new CliError(
5089
+ "invalid_cli_usage",
5090
+ `Failed to parse JSON from --where-json: ${message}`
5091
+ );
5092
+ }
5093
+ if (!Array.isArray(parsed) && !isJsonObject(parsed)) {
5094
+ throw new CliError(
5095
+ "invalid_cli_usage",
5096
+ 'Expected --where-json to contain a JSON array of conditions or a JSON object (a condition or an {"and"|"or": [...]} group).'
5097
+ );
5098
+ }
5099
+ return parsed;
5100
+ }
5101
+ function resolveWhere(options) {
5102
+ const where = toQueryExpressions(options.where);
5103
+ if (options.whereJson !== void 0) {
5104
+ if (where) {
5105
+ throw new CliError(
5106
+ "invalid_cli_usage",
5107
+ 'Provide either "--where" or "--where-json", not both.'
5108
+ );
5109
+ }
5110
+ return parseWhereJson(options.whereJson);
5111
+ }
5112
+ return where;
5113
+ }
5044
5114
  function buildRecordQueryInput(options, allowRaw) {
5045
5115
  const input = allowRaw ? readRawObject(options.raw, options.rawFile) : {};
5046
5116
  if (options.select && options.select.length > 0) {
5047
5117
  input.select = [...options.select];
5048
5118
  }
5049
- const where = toQueryExpressions(options.where);
5050
- if (where && where.length > 0) {
5119
+ const where = resolveWhere(options);
5120
+ if (where !== void 0) {
5051
5121
  input.where = where;
5052
5122
  }
5053
5123
  if (options.search !== void 0) {
@@ -5206,16 +5276,22 @@ function registerRecordsCommands(program, options = {}) {
5206
5276
  }
5207
5277
  emitTable(stdout, recordsData);
5208
5278
  });
5209
- records.command("query").description("Query records for a schema").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector).option("--select <fields>", "field selection (comma-separated, repeatable)", collectSelectValues, []).option("--where <expression>", "where expression", collectWhereExpressions, []).option(
5279
+ records.command("query").description("Query records for a schema").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector).option("--select <fields>", "field selection (comma-separated, repeatable)", collectSelectValues, []).option(
5280
+ "--where <expression>",
5281
+ 'condition "<field> <op> [value]" (repeatable, combined with AND)',
5282
+ collectWhereExpressions,
5283
+ []
5284
+ ).option(
5285
+ "--where-json <json>",
5286
+ 'native where as JSON: an array of conditions (AND) or one condition/{"and"|"or": [...]} group (not combinable with --where)'
5287
+ ).option(
5210
5288
  "--search <term>",
5211
5289
  "free-text search term (matched across the schema's searchable fields)"
5212
5290
  ).option("--sort <field:direction>", "sort field(s)", collectSortValues, []).option("--limit <number>", "limit results", parseNonNegativeInteger).option("--offset <number>", "offset results", parseNonNegativeInteger).option("--raw <json>", "raw JSON object payload").option("--raw-file <path>", "path to a raw JSON object payload").action(async function action(schema, commandOptions) {
5213
5291
  const { api, schemasApi, json } = createRecordsApi(this, filePath);
5292
+ const query = buildRecordQueryInput(commandOptions, true);
5214
5293
  const resolvedSchema = await resolveSchemaSelector(schemasApi, schema);
5215
- const data = await api.queryRecords(
5216
- resolvedSchema,
5217
- buildRecordQueryInput(commandOptions, true)
5218
- );
5294
+ const data = await api.queryRecords(resolvedSchema, query);
5219
5295
  const recordsData = getQueryRecords(data);
5220
5296
  if (json) {
5221
5297
  emitJson(
@@ -6213,7 +6289,7 @@ var require2 = createRequire(import.meta.url);
6213
6289
  var { version } = require2("../package.json");
6214
6290
  function buildProgram(options = {}) {
6215
6291
  const program = new Command4();
6216
- 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("--workspace <workspace>", "workspace name or id for a session profile (or ZINKEE_WORKSPACE)").option("--read-only", "run in read-only mode").option("--example", "show examples for a command").option("--json", "emit JSON output").option("--install-completion [shell]", "install shell completion (bash, zsh, fish, powershell)").option("--show-completion [shell]", "print shell completion script for the current shell");
6292
+ 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("--workspace <workspace>", "workspace name or id for a session profile (or ZINKEE_WORKSPACE)").option("--read-only", "run in read-only mode").option("--idempotency-key <key>", "send this Idempotency-Key on the write request so a retry does not repeat it").option("--example", "show examples for a command").option("--json", "emit JSON output").option("--install-completion [shell]", "install shell completion (bash, zsh, fish, powershell)").option("--show-completion [shell]", "print shell completion script for the current shell");
6217
6293
  registerProfilesCommands(program, options);
6218
6294
  registerSessionCommands(program, options);
6219
6295
  registerAutomationsCommands(program, options);