zinkee 0.1.37 → 0.1.38

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
@@ -461,7 +461,7 @@ var commandRegistry = {
461
461
  command: "displays cross-widget-filter set",
462
462
  accessLevel: "write",
463
463
  supportsExample: true,
464
- supportsRaw: false,
464
+ supportsRaw: true,
465
465
  output: writeOutput
466
466
  },
467
467
  "displays cross-widget-filter delete": {
@@ -4036,40 +4036,86 @@ var specificExamples = {
4036
4036
  ]),
4037
4037
  "displays cross-widget-filter set": buildCommandExamples([
4038
4038
  {
4039
- description: "Link one source widget/field to several target widgets through the same field.",
4039
+ description: "Single configuration with flags: link one source widget/field to several targets. The whole array is replaced.",
4040
4040
  command: "zinkee --json displays cross-widget-filter set 0f6f062f-1478-4df2-96a1-c495d037d260 --source-widget 11111111-1111-4111-a111-111111111111 --source-field c60b8526-5835-4c9f-aecd-9a16c7704a34 --target 22222222-2222-4222-a222-222222222222:c60b8526-5835-4c9f-aecd-9a16c7704a34 --target 33333333-3333-4333-a333-333333333333:c60b8526-5835-4c9f-aecd-9a16c7704a34",
4041
- raw: `{
4042
- "source": {
4043
- "widgetId": "11111111-1111-4111-a111-111111111111",
4044
- "fieldId": "c60b8526-5835-4c9f-aecd-9a16c7704a34"
4045
- },
4046
- "targets": [
4047
- {
4048
- "widgetId": "22222222-2222-4222-a222-222222222222",
4041
+ raw: `[
4042
+ {
4043
+ "source": {
4044
+ "widgetId": "11111111-1111-4111-a111-111111111111",
4049
4045
  "fieldId": "c60b8526-5835-4c9f-aecd-9a16c7704a34"
4050
4046
  },
4047
+ "targets": [
4048
+ {
4049
+ "widgetId": "22222222-2222-4222-a222-222222222222",
4050
+ "fieldId": "c60b8526-5835-4c9f-aecd-9a16c7704a34"
4051
+ },
4052
+ {
4053
+ "widgetId": "33333333-3333-4333-a333-333333333333",
4054
+ "fieldId": "c60b8526-5835-4c9f-aecd-9a16c7704a34"
4055
+ }
4056
+ ]
4057
+ }
4058
+ ]`
4059
+ },
4051
4060
  {
4052
- "widgetId": "33333333-3333-4333-a333-333333333333",
4061
+ description: "Several independent configurations with --raw (each source filters its own targets). A widget cannot be a target of two configurations.",
4062
+ command: `zinkee --json displays cross-widget-filter set 0f6f062f-1478-4df2-96a1-c495d037d260 --raw '[{"source":{"widgetId":"11111111-1111-4111-a111-111111111111","fieldId":"c60b8526-5835-4c9f-aecd-9a16c7704a34"},"targets":[{"widgetId":"22222222-2222-4222-a222-222222222222","fieldId":"c60b8526-5835-4c9f-aecd-9a16c7704a34"}]},{"source":{"widgetId":"44444444-4444-4444-a444-444444444444","fieldId":"a8f1d7e3-2b5c-4d9e-8a1b-3c4d5e6f7890"},"targets":[{"widgetId":"55555555-5555-4555-a555-555555555555","fieldId":"a8f1d7e3-2b5c-4d9e-8a1b-3c4d5e6f7890"}]}]'`,
4063
+ raw: `[
4064
+ {
4065
+ "source": {
4066
+ "widgetId": "11111111-1111-4111-a111-111111111111",
4053
4067
  "fieldId": "c60b8526-5835-4c9f-aecd-9a16c7704a34"
4054
- }
4055
- ]
4056
- }`
4057
4068
  },
4058
- {
4059
- description: "Filter one target widget by the status field of the source.",
4060
- command: "zinkee --json displays cross-widget-filter set 0f6f062f-1478-4df2-96a1-c495d037d260 --source-widget 11111111-1111-4111-a111-111111111111 --source-field a8f1d7e3-2b5c-4d9e-8a1b-3c4d5e6f7890 --target 66666666-6666-4666-a666-666666666666:a8f1d7e3-2b5c-4d9e-8a1b-3c4d5e6f7890",
4061
- raw: `{
4062
- "source": {
4063
- "widgetId": "11111111-1111-4111-a111-111111111111",
4064
- "fieldId": "a8f1d7e3-2b5c-4d9e-8a1b-3c4d5e6f7890"
4069
+ "targets": [
4070
+ {
4071
+ "widgetId": "22222222-2222-4222-a222-222222222222",
4072
+ "fieldId": "c60b8526-5835-4c9f-aecd-9a16c7704a34"
4073
+ }
4074
+ ]
4065
4075
  },
4066
- "targets": [
4076
+ {
4077
+ "source": {
4078
+ "widgetId": "44444444-4444-4444-a444-444444444444",
4079
+ "fieldId": "a8f1d7e3-2b5c-4d9e-8a1b-3c4d5e6f7890"
4080
+ },
4081
+ "targets": [
4082
+ {
4083
+ "widgetId": "55555555-5555-4555-a555-555555555555",
4084
+ "fieldId": "a8f1d7e3-2b5c-4d9e-8a1b-3c4d5e6f7890"
4085
+ }
4086
+ ]
4087
+ }
4088
+ ]`
4089
+ },
4067
4090
  {
4068
- "widgetId": "66666666-6666-4666-a666-666666666666",
4091
+ description: "Hierarchy chain with --raw-file: a target of one configuration is the source of the next (click Parent \u2192 filters Child, click Child \u2192 filters Grandchild).",
4092
+ command: "zinkee --json displays cross-widget-filter set 0f6f062f-1478-4df2-96a1-c495d037d260 --raw-file cross-widget-filter.json",
4093
+ raw: `[
4094
+ {
4095
+ "source": {
4096
+ "widgetId": "11111111-1111-4111-a111-111111111111",
4097
+ "fieldId": "c60b8526-5835-4c9f-aecd-9a16c7704a34"
4098
+ },
4099
+ "targets": [
4100
+ {
4101
+ "widgetId": "22222222-2222-4222-a222-222222222222",
4102
+ "fieldId": "c60b8526-5835-4c9f-aecd-9a16c7704a34"
4103
+ }
4104
+ ]
4105
+ },
4106
+ {
4107
+ "source": {
4108
+ "widgetId": "22222222-2222-4222-a222-222222222222",
4069
4109
  "fieldId": "a8f1d7e3-2b5c-4d9e-8a1b-3c4d5e6f7890"
4070
- }
4071
- ]
4072
- }`
4110
+ },
4111
+ "targets": [
4112
+ {
4113
+ "widgetId": "33333333-3333-4333-a333-333333333333",
4114
+ "fieldId": "a8f1d7e3-2b5c-4d9e-8a1b-3c4d5e6f7890"
4115
+ }
4116
+ ]
4117
+ }
4118
+ ]`
4073
4119
  }
4074
4120
  ]),
4075
4121
  "schemas list": buildCommandExamples([
@@ -4962,18 +5008,20 @@ var specificExamples = {
4962
5008
  }
4963
5009
  }
4964
5010
  ],
4965
- "crossWidgetFilter": {
4966
- "source": {
4967
- "widgetId": "11111111-1111-4111-a111-111111111111",
4968
- "fieldId": "c60b8526-5835-4c9f-aecd-9a16c7704a34"
4969
- },
4970
- "targets": [
4971
- {
4972
- "widgetId": "22222222-2222-4222-a222-222222222222",
5011
+ "crossWidgetFilter": [
5012
+ {
5013
+ "sourceWidget": {
5014
+ "widgetId": "11111111-1111-4111-a111-111111111111",
4973
5015
  "fieldId": "c60b8526-5835-4c9f-aecd-9a16c7704a34"
4974
- }
4975
- ]
4976
- },
5016
+ },
5017
+ "targetWidgets": [
5018
+ {
5019
+ "widgetId": "22222222-2222-4222-a222-222222222222",
5020
+ "fieldId": "c60b8526-5835-4c9f-aecd-9a16c7704a34"
5021
+ }
5022
+ ]
5023
+ }
5024
+ ],
4977
5025
  "navigationTargets": [
4978
5026
  {
4979
5027
  "id": "nav-target-customer",
@@ -9226,20 +9274,54 @@ function buildNavigationTargetBody(options) {
9226
9274
  }
9227
9275
  return body;
9228
9276
  }
9277
+ function readRawArray(raw, rawFile) {
9278
+ if (raw && rawFile) {
9279
+ throw new CliError("invalid_cli_usage", 'Use either "--raw" or "--raw-file", not both.');
9280
+ }
9281
+ const source = rawFile ? readFileSync4(rawFile, "utf8") : raw;
9282
+ if (!source) {
9283
+ return [];
9284
+ }
9285
+ try {
9286
+ const parsed = JSON.parse(source);
9287
+ if (!Array.isArray(parsed)) {
9288
+ throw new CliError("invalid_cli_usage", "Raw cross widget filter payload must be a JSON array of configurations.");
9289
+ }
9290
+ return parsed;
9291
+ } catch (error) {
9292
+ if (error instanceof CliError) throw error;
9293
+ throw new CliError("invalid_cli_usage", "Raw JSON payload is invalid.");
9294
+ }
9295
+ }
9229
9296
  function buildCrossWidgetFilterBody(options) {
9230
- return {
9231
- source: {
9232
- widgetId: options.sourceWidget,
9233
- fieldId: options.sourceField
9234
- },
9235
- targets: options.target.map((entry) => {
9236
- const [widgetId, fieldId] = entry.split(":");
9237
- if (!widgetId || !fieldId) {
9238
- throw new CliError("invalid_cli_usage", `Invalid --target entry "${entry}". Use <widgetId:fieldId>.`);
9239
- }
9240
- return { widgetId, fieldId };
9241
- })
9297
+ if (options.raw !== void 0 || options.rawFile !== void 0) {
9298
+ return readRawArray(options.raw, options.rawFile);
9299
+ }
9300
+ if (!options.sourceWidget || !options.sourceField) {
9301
+ throw new CliError(
9302
+ "invalid_cli_usage",
9303
+ "Provide --source-widget and --source-field, or --raw/--raw-file with the full configuration array."
9304
+ );
9305
+ }
9306
+ const source = {
9307
+ widgetId: options.sourceWidget,
9308
+ fieldId: options.sourceField
9242
9309
  };
9310
+ if (options.sourceSchema) {
9311
+ source.schemaId = options.sourceSchema;
9312
+ }
9313
+ return [
9314
+ {
9315
+ source,
9316
+ targets: (options.target ?? []).map((entry) => {
9317
+ const [widgetId, fieldId] = entry.split(":");
9318
+ if (!widgetId || !fieldId) {
9319
+ throw new CliError("invalid_cli_usage", `Invalid --target entry "${entry}". Use <widgetId:fieldId>.`);
9320
+ }
9321
+ return { widgetId, fieldId };
9322
+ })
9323
+ }
9324
+ ];
9243
9325
  }
9244
9326
  function registerDisplaysCommands(program, options = {}) {
9245
9327
  const filePath = options.configPath ?? defaultConfigPath;
@@ -9586,9 +9668,9 @@ function registerDisplaysCommands(program, options = {}) {
9586
9668
  emitJson4(stdout, "displays cross-widget-filter get", item);
9587
9669
  return;
9588
9670
  }
9589
- printTable(item ? [item] : [], void 0, stdout);
9671
+ printTable(item ?? [], void 0, stdout);
9590
9672
  });
9591
- cross.command("set").description("Set cross widget filter").argument("<display>", "display uuid or slug", parseUuidOrSlugSelector3).requiredOption("--source-widget <id>").requiredOption("--source-field <id>").requiredOption("--target <widget:field>", "repeatable target", (v, p = []) => [...p, v], []).action(async function action(display, commandOptions) {
9673
+ cross.command("set").description("Set cross widget filter (replaces the whole array of configurations)").argument("<display>", "display uuid or slug", parseUuidOrSlugSelector3).option("--source-widget <id>", "source widget id (single-configuration mode)").option("--source-field <id>", "source field id (single-configuration mode)").option("--source-schema <id>", "source schema id, only for HIERARCHY source widgets").option("--target <widget:field>", "repeatable target (single-configuration mode)", (v, p = []) => [...p, v], []).option("--raw <json>", "full array of configurations as JSON (for several configurations)").option("--raw-file <path>", "path to a JSON file with the full array of configurations").action(async function action(display, commandOptions) {
9592
9674
  const { api, json, readOnly } = createDisplaysApi(this, filePath);
9593
9675
  ensureWritable3("displays cross-widget-filter set", readOnly, "write");
9594
9676
  const data = await api.setCrossWidgetFilter(display, buildCrossWidgetFilterBody(commandOptions));