@rogatio/cli 6.9.0 → 6.10.0

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.
@@ -26335,14 +26335,14 @@ function normalizeOptions(raw) {
26335
26335
  }
26336
26336
  maxCases = maxCasesProperty.value;
26337
26337
  }
26338
- let previewAction2;
26338
+ let previewAction;
26339
26339
  if (previewProperty.present) {
26340
26340
  if (previewProperty.value !== void 0 && typeof previewProperty.value !== "function") {
26341
26341
  return { ok: false };
26342
26342
  }
26343
- previewAction2 = previewProperty.value;
26343
+ previewAction = previewProperty.value;
26344
26344
  }
26345
- return { ok: true, maxCases, previewAction: previewAction2 };
26345
+ return { ok: true, maxCases, previewAction };
26346
26346
  }
26347
26347
  function dryRunProject(operations, cases, options) {
26348
26348
  const normalizedOptions = normalizeOptions(options);
@@ -26470,6 +26470,55 @@ function dryRunProject(operations, cases, options) {
26470
26470
  }
26471
26471
  };
26472
26472
  }
26473
+ function captureSubject(matcher, url) {
26474
+ if (matcher.source.key === "url") return url;
26475
+ try {
26476
+ return new URL(url).hostname;
26477
+ } catch {
26478
+ return null;
26479
+ }
26480
+ }
26481
+ function previewRuleAction(operation, url) {
26482
+ const subject = captureSubject(operation.matcher, url);
26483
+ if (subject === null) return null;
26484
+ const captures = matchUrlCaptures(operation.matcher.source.value, subject);
26485
+ if (captures === null) return null;
26486
+ const expand = (value) => substituteUrlCaptures(value, captures);
26487
+ if (operation.kind === "redirect") {
26488
+ return {
26489
+ kind: "redirect",
26490
+ summary: expand(operation.redirect.destination)
26491
+ };
26492
+ }
26493
+ if (operation.kind === "query") {
26494
+ const values = operation.action.params.map(
26495
+ (param) => param.operation === "remove" ? `${param.name}=<removed>` : `${param.name}=${expand(param.value ?? "")}`
26496
+ ).join(", ");
26497
+ return { kind: "query", summary: values };
26498
+ }
26499
+ if (operation.kind === "header") {
26500
+ if (operation.header.operation === "remove") {
26501
+ return { kind: "header", summary: `${operation.header.name}=<removed>` };
26502
+ }
26503
+ return {
26504
+ kind: "header",
26505
+ summary: `${operation.header.name}=${expand(operation.header.value ?? "")}`
26506
+ };
26507
+ }
26508
+ if (operation.kind === "request-body" && operation.requestBody.mode === "replace") {
26509
+ return {
26510
+ kind: operation.kind,
26511
+ summary: expand(operation.requestBody.body)
26512
+ };
26513
+ }
26514
+ if (operation.kind === "response-body" && "mode" in operation.responseBody && operation.responseBody.mode === "replace") {
26515
+ return {
26516
+ kind: operation.kind,
26517
+ summary: expand(operation.responseBody.body)
26518
+ };
26519
+ }
26520
+ return null;
26521
+ }
26473
26522
 
26474
26523
  // packages/cli/src/server/routes.ts
26475
26524
  function generateCsrfToken() {
@@ -26540,18 +26589,6 @@ function bodyErrorResponse(error) {
26540
26589
  body: { code: "invalid-json", message: "Invalid JSON body" }
26541
26590
  };
26542
26591
  }
26543
- function toMatcherOperations(operations) {
26544
- return operations.map(
26545
- ({ groupId, ruleId, name, matcher, redactSensitiveInLogs }) => ({
26546
- kind: "matcher",
26547
- groupId,
26548
- ruleId,
26549
- name,
26550
- matcher,
26551
- redactSensitiveInLogs
26552
- })
26553
- );
26554
- }
26555
26592
  function isRecord2(value) {
26556
26593
  return typeof value === "object" && value !== null && !Array.isArray(value);
26557
26594
  }
@@ -26864,10 +26901,13 @@ function createRoutes(context) {
26864
26901
  );
26865
26902
  return;
26866
26903
  }
26904
+ const requested = isRecord2(body.options) && typeof body.options.maxCases === "number" && Number.isSafeInteger(body.options.maxCases) && body.options.maxCases > 0 ? body.options.maxCases : void 0;
26905
+ const options = { previewAction: previewRuleAction };
26906
+ if (requested !== void 0) options.maxCases = requested;
26867
26907
  const result = dryRunProject(
26868
- toMatcherOperations(compileResult.operations),
26908
+ compileResult.operations,
26869
26909
  body.cases,
26870
- body.options ?? {}
26910
+ options
26871
26911
  );
26872
26912
  res.writeHead(200, { "Content-Type": "application/json" });
26873
26913
  res.end(JSON.stringify(result));
@@ -27872,7 +27912,41 @@ function generateEditorHtml(apiBase, csrfToken, filePath, aiConfigured) {
27872
27912
  },
27873
27913
  body: JSON.stringify({ project: currentProject, cases, options }),
27874
27914
  });
27875
- return res.json();
27915
+ let payload = null;
27916
+ try {
27917
+ payload = await res.json();
27918
+ } catch (error) {
27919
+ payload = null;
27920
+ }
27921
+ if (!res.ok) {
27922
+ const diagnostics = payload && Array.isArray(payload.diagnostics)
27923
+ ? payload.diagnostics.map(function (diagnostic) {
27924
+ return {
27925
+ code: diagnostic && typeof diagnostic.code === 'string'
27926
+ ? diagnostic.code
27927
+ : 'editor.validation-failed',
27928
+ severity: 'error',
27929
+ path: diagnostic && typeof diagnostic.path === 'string'
27930
+ ? diagnostic.path
27931
+ : '',
27932
+ message: diagnostic && typeof diagnostic.message === 'string'
27933
+ ? diagnostic.message
27934
+ : 'The project could not be tested.',
27935
+ };
27936
+ })
27937
+ : [{
27938
+ code: payload && typeof payload.code === 'string'
27939
+ ? payload.code
27940
+ : 'editor.validation-failed',
27941
+ severity: 'error',
27942
+ path: '',
27943
+ message: payload && typeof payload.message === 'string'
27944
+ ? payload.message
27945
+ : 'The project could not be tested.',
27946
+ }];
27947
+ return { ok: false, diagnostics: diagnostics };
27948
+ }
27949
+ return payload;
27876
27950
  },
27877
27951
  onCancel: () => {
27878
27952
  cancel();
@@ -29947,7 +30021,7 @@ function errorMessage(error) {
29947
30021
  // packages/cli/src/commands/runtime.ts
29948
30022
  import { chmod, mkdir as mkdir4, rm as rm2, writeFile as writeFile4 } from "node:fs/promises";
29949
30023
  import { dirname as dirname7, join as join7, resolve as resolve6 } from "node:path";
29950
- function toMatcherOperations2(operations) {
30024
+ function toMatcherOperations(operations) {
29951
30025
  return operations.map(
29952
30026
  ({ groupId, ruleId, name, matcher, redactSensitiveInLogs }) => ({
29953
30027
  kind: "matcher",
@@ -30239,7 +30313,7 @@ async function runtimeHostCommand(args, options = {}) {
30239
30313
  const normalized = normalizeRuntimePreset({
30240
30314
  version: 1,
30241
30315
  limits: RUNTIME_LIMITS,
30242
- matchers: toMatcherOperations2(compileResult.operations),
30316
+ matchers: toMatcherOperations(compileResult.operations),
30243
30317
  grants: []
30244
30318
  });
30245
30319
  if (!normalized.ok) {
@@ -30284,55 +30358,6 @@ function usageError(message) {
30284
30358
  return `Error: ${message}
30285
30359
  `;
30286
30360
  }
30287
- function captureSubject(matcher, url) {
30288
- if (matcher.source.key === "url") return url;
30289
- try {
30290
- return new URL(url).hostname;
30291
- } catch {
30292
- return null;
30293
- }
30294
- }
30295
- function previewAction(operation, url) {
30296
- const subject = captureSubject(operation.matcher, url);
30297
- if (subject === null) return null;
30298
- const captures = matchUrlCaptures(operation.matcher.source.value, subject);
30299
- if (captures === null) return null;
30300
- const expand = (value) => substituteUrlCaptures(value, captures);
30301
- if (operation.kind === "redirect") {
30302
- return {
30303
- kind: "redirect",
30304
- summary: expand(operation.redirect.destination)
30305
- };
30306
- }
30307
- if (operation.kind === "query") {
30308
- const values = operation.action.params.map(
30309
- (param) => param.operation === "remove" ? `${param.name}=<removed>` : `${param.name}=${expand(param.value ?? "")}`
30310
- ).join(", ");
30311
- return { kind: "query", summary: values };
30312
- }
30313
- if (operation.kind === "header") {
30314
- if (operation.header.operation === "remove") {
30315
- return { kind: "header", summary: `${operation.header.name}=<removed>` };
30316
- }
30317
- return {
30318
- kind: "header",
30319
- summary: `${operation.header.name}=${expand(operation.header.value ?? "")}`
30320
- };
30321
- }
30322
- if (operation.kind === "request-body" && operation.requestBody.mode === "replace") {
30323
- return {
30324
- kind: operation.kind,
30325
- summary: expand(operation.requestBody.body)
30326
- };
30327
- }
30328
- if (operation.kind === "response-body" && "mode" in operation.responseBody && operation.responseBody.mode === "replace") {
30329
- return {
30330
- kind: operation.kind,
30331
- summary: expand(operation.responseBody.body)
30332
- };
30333
- }
30334
- return null;
30335
- }
30336
30361
  function isUrl(value) {
30337
30362
  return parseTestUrl(value).ok;
30338
30363
  }
@@ -30387,7 +30412,7 @@ function addDefaults(cases, defaultMethod, defaultResourceType) {
30387
30412
  );
30388
30413
  }
30389
30414
  function resultOptions(maxCases) {
30390
- const options = { previewAction };
30415
+ const options = { previewAction: previewRuleAction };
30391
30416
  if (maxCases !== void 0) options.maxCases = maxCases;
30392
30417
  return options;
30393
30418
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rogatio/cli",
3
- "version": "6.9.0",
3
+ "version": "6.10.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Local-first browser request and response rules — editor host, file verification, test runner, and runtime dispatch.",