@eudiplo/cli 10.1.0-main.6e16824 → 10.1.0-main.6fdbc3a

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
@@ -7515,8 +7515,8 @@ var require_formats = __commonJS({
7515
7515
  "use strict";
7516
7516
  Object.defineProperty(exports, "__esModule", { value: true });
7517
7517
  exports.formatNames = exports.fastFormats = exports.fullFormats = void 0;
7518
- function fmtDef(validate, compare) {
7519
- return { validate, compare };
7518
+ function fmtDef(validate, compare2) {
7519
+ return { validate, compare: compare2 };
7520
7520
  }
7521
7521
  exports.fullFormats = {
7522
7522
  // date: http://tools.ietf.org/html/rfc3339#section-5.6
@@ -23315,6 +23315,120 @@ async function atomicWriteFile(path2, data) {
23315
23315
  }
23316
23316
  }
23317
23317
 
23318
+ // src/services/backend-checks.ts
23319
+ function compareVersions(cliVersion, backendVersion2) {
23320
+ const name = "version compatibility";
23321
+ const cli = parse3(cliVersion);
23322
+ const backend = parse3(backendVersion2);
23323
+ if (!cli || !backend) {
23324
+ return {
23325
+ name,
23326
+ status: "warn",
23327
+ message: `CLI ${cliVersion} and backend ${backendVersion2} cannot be compared as versions.`
23328
+ };
23329
+ }
23330
+ if (cli.major !== backend.major) {
23331
+ return {
23332
+ name,
23333
+ status: "fail",
23334
+ message: `CLI ${cliVersion} and backend ${backendVersion2} are different major versions. Install a matching CLI with npm install -g @eudiplo/cli@${backend.major}.`
23335
+ };
23336
+ }
23337
+ if (cli.minor !== backend.minor) {
23338
+ return {
23339
+ name,
23340
+ status: "warn",
23341
+ message: `CLI ${cliVersion} and backend ${backendVersion2} differ in minor version; some commands may not be supported.`
23342
+ };
23343
+ }
23344
+ if (compare(cli, LAST_RELEASE_WITHOUT_ESCAPED_FORM) > 0 && compare(backend, LAST_RELEASE_WITHOUT_ESCAPED_FORM) <= 0) {
23345
+ return {
23346
+ name,
23347
+ status: "warn",
23348
+ message: `CLI ${cliVersion} and backend ${backendVersion2} read the escaped form $\${ of configuration files differently; config plan and import of a tenant folder store values containing \${ or $\${ differently. Upgrade the backend to match the CLI.`
23349
+ };
23350
+ }
23351
+ return {
23352
+ name,
23353
+ status: "pass",
23354
+ message: `CLI ${cliVersion} matches backend ${backendVersion2}.`
23355
+ };
23356
+ }
23357
+ var LAST_RELEASE_WITHOUT_ESCAPED_FORM = {
23358
+ major: 10,
23359
+ minor: 1,
23360
+ patch: 0
23361
+ };
23362
+ function escapedFormWarning(backendVersion2) {
23363
+ const backend = backendVersion2 ? parse3(backendVersion2) : void 0;
23364
+ if (!backend || compare(backend, LAST_RELEASE_WITHOUT_ESCAPED_FORM) > 0)
23365
+ return void 0;
23366
+ return `Warning: the backend (${backendVersion2}) does not read the escaped form $\${ of configuration files, which this CLI sends: values containing \${ or $\${ will be stored differently from what the files say. Upgrade the CLI and the backend together.`;
23367
+ }
23368
+ function compare(left, right) {
23369
+ return left.major - right.major || left.minor - right.minor || left.patch - right.patch;
23370
+ }
23371
+ function readBackendVersion(body) {
23372
+ if (typeof body === "object" && body !== null && "version" in body) {
23373
+ const version = body.version;
23374
+ return typeof version === "string" && version ? version : void 0;
23375
+ }
23376
+ return void 0;
23377
+ }
23378
+ function readProviderHealth(body) {
23379
+ if (!Array.isArray(body)) {
23380
+ throw new Error("the provider health response was not a list");
23381
+ }
23382
+ return body.map((entry) => {
23383
+ const record = entry;
23384
+ return {
23385
+ providerId: String(record.providerId ?? "unknown"),
23386
+ type: String(record.type ?? "unknown"),
23387
+ ok: record.ok === true,
23388
+ latencyMs: typeof record.latencyMs === "number" ? record.latencyMs : void 0,
23389
+ error: typeof record.error === "string" ? record.error : void 0
23390
+ };
23391
+ });
23392
+ }
23393
+ function summarizeProviderHealth(providers) {
23394
+ const name = "KMS providers";
23395
+ if (providers.length === 0) {
23396
+ return {
23397
+ name,
23398
+ status: "warn",
23399
+ message: "No KMS providers are registered for this tenant."
23400
+ };
23401
+ }
23402
+ const failing = providers.filter((provider) => !provider.ok);
23403
+ if (failing.length > 0) {
23404
+ return {
23405
+ name,
23406
+ status: "fail",
23407
+ message: `${failing.length}/${providers.length} provider(s) unhealthy: ${failing.map(
23408
+ (provider) => `${provider.providerId} (${provider.type})${provider.error ? ", health check reported an error" : ""}`
23409
+ ).join(", ")}`
23410
+ };
23411
+ }
23412
+ return {
23413
+ name,
23414
+ status: "pass",
23415
+ message: `${providers.length} provider(s) healthy: ${providers.map(
23416
+ (provider) => `${provider.providerId} (${provider.type}${provider.latencyMs === void 0 ? "" : `, ${provider.latencyMs}ms`})`
23417
+ ).join(", ")}`
23418
+ };
23419
+ }
23420
+ function parse3(version) {
23421
+ const match = /^v?(\d+)\.(\d+)\.(\d+)/.exec(version.trim());
23422
+ if (!match) {
23423
+ return void 0;
23424
+ }
23425
+ return {
23426
+ major: Number(match[1]),
23427
+ minor: Number(match[2]),
23428
+ patch: Number(match[3])
23429
+ };
23430
+ }
23431
+
23318
23432
  // src/services/instance-selection.ts
23319
23433
  function resolveInstance(config, parsed) {
23320
23434
  const name = readStringFlag(parsed.flags, "instance") ?? config.defaultInstance;
@@ -43494,104 +43608,99 @@ var CONFIG_SCHEMAS = [
43494
43608
  }
43495
43609
  ];
43496
43610
 
43497
- // ../../packages/eudiplo-config-format/dist/config-validator.js
43498
- var DISPLAY_COLOR_PATH = /^\/spec\/config\/display\/\d+\/(?:background|text)_color$/;
43499
- var ajv = new import__.Ajv2020({
43500
- allErrors: true,
43501
- strict: false,
43502
- validateFormats: false
43503
- });
43504
- for (const schema of CONFIG_SCHEMAS)
43505
- ajv.addSchema(schema);
43506
- function validateConfigDocument(document) {
43507
- const file = serializeDocument(document);
43508
- const validate = ajv.getSchema(file.$schema);
43509
- if (!validate)
43510
- throw new Error(`No bundled validator for ${file.$schema}`);
43511
- const issues = [];
43512
- if (!validate(file)) {
43513
- for (const issue of validate.errors ?? [])
43514
- issues.push({
43515
- severity: "error",
43516
- code: "CONFIG_SCHEMA_VALIDATION_FAILED",
43517
- path: issue.instancePath || "/",
43518
- message: issue.keyword === "additionalProperties" ? `Unknown property: ${String(issue.params.additionalProperty)}` : issue.keyword === "pattern" && DISPLAY_COLOR_PATH.test(issue.instancePath) ? DISPLAY_COLOR_MESSAGE : issue.message ?? "Invalid configuration",
43519
- resource: { kind: document.kind, id: resourceId(document) }
43520
- });
43521
- }
43522
- const id = document.kind === "Client" ? document.spec.clientId : document.spec.id;
43523
- if (id !== void 0 && id !== resourceId(document))
43524
- issues.push({
43525
- severity: "error",
43526
- code: "RESOURCE_ID_MISMATCH",
43527
- path: document.kind === "Client" ? "/spec/clientId" : "/spec/id",
43528
- message: "Resource identifier does not match metadata.id"
43529
- });
43530
- issues.push(...configRuleIssues(document));
43531
- return issues;
43532
- }
43533
- function configRuleIssues(document) {
43534
- const display = document.spec.config?.display;
43535
- if (document.kind !== "CredentialConfig" || resolveConfigIdentity(serializeDocument(document)).version < 4 || !Array.isArray(display))
43536
- return [];
43537
- return findDuplicateDisplayLocales(display).map((duplicate) => ({
43538
- severity: "error",
43539
- code: "DISPLAY_LOCALE_DUPLICATE",
43540
- path: `/spec/config/display/${duplicate.index}/locale`,
43541
- message: duplicateDisplayLocaleMessage(duplicate),
43542
- resource: { kind: document.kind, id: resourceId(document) }
43543
- }));
43544
- }
43545
-
43546
43611
  // ../../packages/eudiplo-config-format/dist/config-values.js
43547
43612
  var isVariableChar = (char) => char >= "A" && char <= "Z" || char >= "0" && char <= "9" || char === "_";
43548
- function replacePlaceholders(input, replace) {
43613
+ var isLower = (char) => char >= "a" && char <= "z";
43614
+ var isSourceChar = (char) => isLower(char) || char >= "0" && char <= "9" || char === "-";
43615
+ var LOCATOR_CHARS = new Set("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._~/:@+=,#-");
43616
+ var escapeText = (text) => text.replaceAll("${", () => "$${");
43617
+ function replacePlaceholders(input, replace, escapes = "resolve") {
43549
43618
  let output = "";
43619
+ let text = "";
43620
+ const flush = () => {
43621
+ output += escapes === "keep" ? escapeText(text) : text;
43622
+ text = "";
43623
+ };
43550
43624
  let copied = 0;
43625
+ let noClosingBrace = false;
43551
43626
  let start = input.indexOf("${");
43552
43627
  while (start !== -1) {
43553
- let cursor = start + 2;
43554
- while (cursor < input.length && isVariableChar(input[cursor]))
43555
- cursor++;
43556
- const variable = input.slice(start + 2, cursor);
43628
+ if (escapes !== "none" && start > copied && input[start - 1] === "$") {
43629
+ text += `${input.slice(copied, start - 1)}\${`;
43630
+ copied = start + 2;
43631
+ start = input.indexOf("${", copied);
43632
+ continue;
43633
+ }
43634
+ let token;
43557
43635
  let end = -1;
43558
- let fallback;
43559
- if (variable && input[cursor] === "}")
43560
- end = cursor;
43561
- else if (variable && input[cursor] === ":") {
43562
- end = input.indexOf("}", cursor + 1);
43563
- if (end === -1)
43564
- break;
43565
- fallback = input.slice(cursor + 1, end);
43636
+ let cursor = start + 2;
43637
+ if (isLower(input[cursor] ?? "")) {
43638
+ while (cursor < input.length && isSourceChar(input[cursor]))
43639
+ cursor++;
43640
+ const source = input.slice(start + 2, cursor);
43641
+ if (input[cursor] === ":") {
43642
+ const locatorStart = cursor + 1;
43643
+ cursor = locatorStart;
43644
+ while (cursor < input.length && LOCATOR_CHARS.has(input[cursor]))
43645
+ cursor++;
43646
+ if (cursor > locatorStart && input[cursor] === "}") {
43647
+ end = cursor;
43648
+ token = {
43649
+ type: "reference",
43650
+ match: input.slice(start, end + 1),
43651
+ source,
43652
+ locator: input.slice(locatorStart, end)
43653
+ };
43654
+ }
43655
+ }
43656
+ } else {
43657
+ while (cursor < input.length && isVariableChar(input[cursor]))
43658
+ cursor++;
43659
+ const variable = input.slice(start + 2, cursor);
43660
+ let fallback;
43661
+ if (variable && input[cursor] === "}")
43662
+ end = cursor;
43663
+ else if (variable && input[cursor] === ":" && !noClosingBrace) {
43664
+ end = input.indexOf("}", cursor + 1);
43665
+ if (end === -1)
43666
+ noClosingBrace = true;
43667
+ else
43668
+ fallback = input.slice(cursor + 1, end);
43669
+ }
43670
+ if (end !== -1)
43671
+ token = {
43672
+ type: "variable",
43673
+ match: input.slice(start, end + 1),
43674
+ variable,
43675
+ fallback
43676
+ };
43566
43677
  }
43567
- if (end === -1) {
43678
+ if (!token) {
43568
43679
  start = input.indexOf("${", start + 2);
43569
43680
  continue;
43570
43681
  }
43571
- output += input.slice(copied, start);
43572
- output += replace(input.slice(start, end + 1), variable, fallback);
43682
+ const { match } = token;
43683
+ const replacement = replace(token);
43684
+ text += input.slice(copied, start);
43685
+ if (replacement !== void 0)
43686
+ text += replacement;
43687
+ else if (escapes === "keep") {
43688
+ flush();
43689
+ output += match;
43690
+ } else
43691
+ text += match;
43573
43692
  copied = end + 1;
43574
43693
  start = input.indexOf("${", copied);
43575
43694
  }
43576
- return output + input.slice(copied);
43695
+ text += input.slice(copied);
43696
+ flush();
43697
+ return output;
43577
43698
  }
43578
- function resolveConfigVariables(input, env) {
43579
- const issues = [];
43699
+ function mapStrings(input, change) {
43580
43700
  const seen = /* @__PURE__ */ new WeakMap();
43581
43701
  function visit2(value, path2) {
43582
43702
  if (typeof value === "string")
43583
- return replacePlaceholders(value, (match, variable, fallback) => {
43584
- if (env[variable] !== void 0 && env[variable] !== "")
43585
- return env[variable];
43586
- if (fallback !== void 0)
43587
- return fallback;
43588
- issues.push({
43589
- path: path2 || "/",
43590
- variable,
43591
- message: `Unresolved placeholder \${${variable}}: no environment value or default is available`
43592
- });
43593
- return match;
43594
- });
43703
+ return change(value, path2 || "/");
43595
43704
  if (!value || typeof value !== "object" || value instanceof Uint8Array)
43596
43705
  return value;
43597
43706
  if (seen.has(value))
@@ -43607,7 +43716,43 @@ function resolveConfigVariables(input, env) {
43607
43716
  });
43608
43717
  return output;
43609
43718
  }
43610
- return { value: visit2(input, ""), issues };
43719
+ return visit2(input, "");
43720
+ }
43721
+ function resolveConfigVariables(input, env, escapes = "resolve") {
43722
+ const issues = [];
43723
+ const value = mapStrings(input, (text, path2) => replacePlaceholders(text, (token) => {
43724
+ if (token.type === "reference")
43725
+ return void 0;
43726
+ const { variable, fallback } = token;
43727
+ const found = env[variable];
43728
+ if (found !== void 0 && found !== "")
43729
+ return found;
43730
+ if (fallback !== void 0)
43731
+ return fallback;
43732
+ issues.push({
43733
+ path: path2,
43734
+ variable,
43735
+ message: `Unresolved placeholder \${${variable}}: no environment value or default is available`
43736
+ });
43737
+ return void 0;
43738
+ }, escapes));
43739
+ return { value, issues };
43740
+ }
43741
+ function escapeConfigPlaceholders(input) {
43742
+ return mapStrings(input, escapeText);
43743
+ }
43744
+ function readConfigFileValues(input, escapes = "resolve") {
43745
+ const placeholders = [];
43746
+ const references = [];
43747
+ const value = mapStrings(input, (text, path2) => replacePlaceholders(text, ({ type, match }) => {
43748
+ const whole = match === text;
43749
+ if (type === "reference")
43750
+ references.push({ path: path2, reference: match, whole });
43751
+ else
43752
+ placeholders.push({ path: path2, placeholder: match, whole });
43753
+ return void 0;
43754
+ }, escapes));
43755
+ return { value, placeholders, references };
43611
43756
  }
43612
43757
  function stableConfigJson(value) {
43613
43758
  function sort(item) {
@@ -43673,6 +43818,58 @@ function configChanges(before, after, sensitivePaths = [], prefix = "") {
43673
43818
  return changes;
43674
43819
  }
43675
43820
 
43821
+ // ../../packages/eudiplo-config-format/dist/config-validator.js
43822
+ var DISPLAY_COLOR_PATH = /^\/spec\/config\/display\/\d+\/(?:background|text)_color$/;
43823
+ var ajv = new import__.Ajv2020({
43824
+ allErrors: true,
43825
+ strict: false,
43826
+ validateFormats: false
43827
+ });
43828
+ for (const schema of CONFIG_SCHEMAS)
43829
+ ajv.addSchema(schema);
43830
+ function validateConfigDocument(document) {
43831
+ const file = serializeDocument(document);
43832
+ const validate = ajv.getSchema(file.$schema);
43833
+ if (!validate)
43834
+ throw new Error(`No bundled validator for ${file.$schema}`);
43835
+ const issues = [];
43836
+ if (!validate(file)) {
43837
+ for (const issue of validate.errors ?? [])
43838
+ issues.push({
43839
+ severity: "error",
43840
+ code: "CONFIG_SCHEMA_VALIDATION_FAILED",
43841
+ path: issue.instancePath || "/",
43842
+ message: issue.keyword === "additionalProperties" ? `Unknown property: ${String(issue.params.additionalProperty)}` : issue.keyword === "pattern" && DISPLAY_COLOR_PATH.test(issue.instancePath) ? DISPLAY_COLOR_MESSAGE : issue.message ?? "Invalid configuration",
43843
+ resource: { kind: document.kind, id: resourceId(document) }
43844
+ });
43845
+ }
43846
+ const id = document.kind === "Client" ? document.spec.clientId : document.spec.id;
43847
+ if (id !== void 0 && id !== resourceId(document))
43848
+ issues.push({
43849
+ severity: "error",
43850
+ code: "RESOURCE_ID_MISMATCH",
43851
+ path: document.kind === "Client" ? "/spec/clientId" : "/spec/id",
43852
+ message: "Resource identifier does not match metadata.id"
43853
+ });
43854
+ issues.push(...configRuleIssues(document));
43855
+ return issues;
43856
+ }
43857
+ function validateConfigFile(document) {
43858
+ return validateConfigDocument(document.kind === "KmsConfig" ? document : { ...document, spec: readConfigFileValues(document.spec).value });
43859
+ }
43860
+ function configRuleIssues(document) {
43861
+ const display = document.spec.config?.display;
43862
+ if (document.kind !== "CredentialConfig" || resolveConfigIdentity(serializeDocument(document)).version < 4 || !Array.isArray(display))
43863
+ return [];
43864
+ return findDuplicateDisplayLocales(display).map((duplicate) => ({
43865
+ severity: "error",
43866
+ code: "DISPLAY_LOCALE_DUPLICATE",
43867
+ path: `/spec/config/display/${duplicate.index}/locale`,
43868
+ message: duplicateDisplayLocaleMessage(duplicate),
43869
+ resource: { kind: document.kind, id: resourceId(document) }
43870
+ }));
43871
+ }
43872
+
43676
43873
  // ../../packages/eudiplo-config-format/dist/tenant-folder.js
43677
43874
  var TENANT_FOLDER_IMAGES = "images";
43678
43875
  var IMAGE_CONTENT_TYPES = {
@@ -43705,7 +43902,7 @@ async function discoverTenantDirectories(rootPath) {
43705
43902
  const entries = await readdir(rootPath, { withFileTypes: true });
43706
43903
  return entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort(compareCodePoints);
43707
43904
  }
43708
- async function validateTenantsRoot(rootPath, schemas, env) {
43905
+ async function validateTenantsRoot(rootPath, schemas, env, options = {}) {
43709
43906
  if (!existsSync(rootPath)) {
43710
43907
  throw new Error(`Configuration root not found: ${rootPath}`);
43711
43908
  }
@@ -43717,7 +43914,8 @@ async function validateTenantsRoot(rootPath, schemas, env) {
43717
43914
  join4(rootPath, tenantId),
43718
43915
  tenantId,
43719
43916
  schemas,
43720
- env
43917
+ env,
43918
+ options
43721
43919
  )
43722
43920
  );
43723
43921
  }
@@ -43732,7 +43930,9 @@ async function validateTenantDirectory(tenantPath, tenantId, schemas, env, optio
43732
43930
  env,
43733
43931
  errors: [],
43734
43932
  unresolved: [],
43933
+ warnings: [],
43735
43934
  allowUnresolvedPlaceholders: options.allowUnresolvedPlaceholders,
43935
+ folderVariablePolicy: options.folderVariablePolicy,
43736
43936
  resourceCounts: {},
43737
43937
  files: 0
43738
43938
  };
@@ -43743,9 +43943,12 @@ async function validateTenantDirectory(tenantPath, tenantId, schemas, env, optio
43743
43943
  await validateDirectoryEntry(tenantPath, entry, state);
43744
43944
  }
43745
43945
  }
43746
- const warnings = RETIRED_TENANT_FOLDER_FILES.filter(
43747
- ({ file }) => existsSync(join4(tenantPath, file))
43748
- ).map(({ file, issue }) => ({ file, message: issue.message }));
43946
+ const warnings = [
43947
+ ...RETIRED_TENANT_FOLDER_FILES.filter(
43948
+ ({ file }) => existsSync(join4(tenantPath, file))
43949
+ ).map(({ file, issue }) => ({ file, message: issue.message })),
43950
+ ...state.warnings
43951
+ ];
43749
43952
  return {
43750
43953
  id: tenantId,
43751
43954
  valid: state.errors.length === 0,
@@ -43826,16 +44029,15 @@ async function recordValidationOutcome(filePath, relativeFile, resourceType, sch
43826
44029
  filePath,
43827
44030
  relativeFile,
43828
44031
  schemaFile,
43829
- state.getValidator,
43830
- state.env,
43831
- state.errors,
43832
- state.allowUnresolvedPlaceholders ? state.unresolved : state.errors
44032
+ state
43833
44033
  );
43834
44034
  if (isValid) {
43835
44035
  state.resourceCounts[resourceType] = (state.resourceCounts[resourceType] ?? 0) + 1;
43836
44036
  }
43837
44037
  }
43838
- async function validateResourceFile(filePath, relativeFile, schemaFile, getValidator, env, errors, placeholderIssues) {
44038
+ async function validateResourceFile(filePath, relativeFile, schemaFile, state) {
44039
+ const { errors, getValidator } = state;
44040
+ const kind = kindForSchemaFile(schemaFile);
43839
44041
  let raw;
43840
44042
  try {
43841
44043
  raw = await readFile4(filePath, "utf8");
@@ -43854,12 +44056,7 @@ async function validateResourceFile(filePath, relativeFile, schemaFile, getValid
43854
44056
  return false;
43855
44057
  }
43856
44058
  const errorsBefore = errors.length;
43857
- let resolved = resolvePlaceholders(
43858
- payload,
43859
- env,
43860
- relativeFile,
43861
- placeholderIssues
43862
- );
44059
+ let resolved = resolvePlaceholders(payload, relativeFile, kind, state);
43863
44060
  if (errors.length > errorsBefore) {
43864
44061
  return false;
43865
44062
  }
@@ -43887,7 +44084,6 @@ async function validateResourceFile(filePath, relativeFile, schemaFile, getValid
43887
44084
  return false;
43888
44085
  }
43889
44086
  } else {
43890
- const kind = kindForSchemaFile(schemaFile);
43891
44087
  if (kind && resolved && typeof resolved === "object" && !Array.isArray(resolved)) {
43892
44088
  const spec = structuredClone(resolved);
43893
44089
  if (kind === "KeyChain" && spec.key && !spec.keySource) {
@@ -43948,17 +44144,62 @@ function formatErrorPath(issue) {
43948
44144
  const missingProperty = issue.params?.missingProperty;
43949
44145
  return missingProperty;
43950
44146
  }
43951
- function resolvePlaceholders(value, env, file, errors) {
43952
- const result = resolveConfigVariables(value, env);
44147
+ function resolvePlaceholders(value, file, kind, state) {
44148
+ const kms = kind === "KmsConfig";
44149
+ const named = /* @__PURE__ */ new Set();
44150
+ const env = new Proxy(state.env, {
44151
+ get: (target, name) => {
44152
+ if (typeof name !== "string") return void 0;
44153
+ named.add(name);
44154
+ return target[name];
44155
+ }
44156
+ });
44157
+ const result = resolveConfigVariables(value, env, kms ? "none" : "resolve");
44158
+ const refused = /* @__PURE__ */ new Set();
44159
+ if (state.folderVariablePolicy)
44160
+ for (const variable of [...named].sort(compareCodePoints)) {
44161
+ const check = checkFolderVariable(variable, kms);
44162
+ if (check?.refused) {
44163
+ refused.add(variable);
44164
+ state.errors.push({ file, message: check.message, variable });
44165
+ } else if (check)
44166
+ state.warnings.push({ file, message: check.message, variable });
44167
+ }
44168
+ const placeholderIssues = state.allowUnresolvedPlaceholders ? state.unresolved : state.errors;
43953
44169
  for (const issue of result.issues)
43954
- errors.push({
43955
- file,
43956
- path: issue.path,
43957
- message: issue.message,
43958
- variable: issue.variable
43959
- });
44170
+ if (!refused.has(issue.variable))
44171
+ placeholderIssues.push({
44172
+ file,
44173
+ path: issue.path,
44174
+ message: issue.message,
44175
+ variable: issue.variable
44176
+ });
43960
44177
  return result.value;
43961
44178
  }
44179
+ var CLOUD_CREDENTIAL_VARIABLES = /* @__PURE__ */ new Map([
44180
+ ["AWS_ACCESS_KEY_ID", "AWS"],
44181
+ ["AWS_SECRET_ACCESS_KEY", "AWS"],
44182
+ ["AWS_SESSION_TOKEN", "AWS"],
44183
+ ["AWS_CONTAINER_AUTHORIZATION_TOKEN", "AWS"],
44184
+ ["AZURE_CLIENT_SECRET", "Azure"],
44185
+ ["AZURE_CLIENT_CERTIFICATE_PASSWORD", "Azure"],
44186
+ ["AZURE_PASSWORD", "Azure"]
44187
+ ]);
44188
+ function checkFolderVariable(variable, kms) {
44189
+ if (variable === "PUBLIC_URL") return void 0;
44190
+ if (kms)
44191
+ return {
44192
+ refused: false,
44193
+ message: `\${${variable}} is resolved only if the instance lists ${variable} in KMS_TENANT_VARIABLES, which cannot name a setting of EUDIPLO itself`
44194
+ };
44195
+ const provider = CLOUD_CREDENTIAL_VARIABLES.get(variable);
44196
+ if (provider)
44197
+ return {
44198
+ refused: true,
44199
+ message: `\${${variable}} holds the ${provider} credentials of the instance, which a file of a tenant folder cannot use`
44200
+ };
44201
+ return void 0;
44202
+ }
43962
44203
 
43963
44204
  // src/commands/config/portability/folder-bundle.ts
43964
44205
  import { createHash as createHash3 } from "node:crypto";
@@ -43990,13 +44231,13 @@ import {
43990
44231
 
43991
44232
  // src/commands/config/portability/migrations.ts
43992
44233
  function upgradeDocument(input) {
43993
- const result = migrateDocument(input, validateConfigDocument);
44234
+ const result = migrateDocument(input, validateConfigFile);
43994
44235
  return { ...result, document: serializeDocument(result.document) };
43995
44236
  }
43996
44237
 
43997
44238
  // src/commands/config/portability/upgrade.ts
43998
44239
  var codec = new ConfigBundleCodec();
43999
- function parse3(text, path2) {
44240
+ function parse4(text, path2) {
44000
44241
  try {
44001
44242
  return JSON.parse(text);
44002
44243
  } catch {
@@ -44129,7 +44370,7 @@ async function upgradeFolder(source, parsed, context) {
44129
44370
  for (const file of await folderFiles(source)) {
44130
44371
  if (extname(file) !== ".json" || relative2(source, file).split(sep2).includes("images"))
44131
44372
  continue;
44132
- const input = parse3(await readFile5(file, "utf8"), file);
44373
+ const input = parse4(await readFile5(file, "utf8"), file);
44133
44374
  const path2 = relative2(source, file).split(sep2).join("/");
44134
44375
  const retired = RETIRED_TENANT_FOLDER_FILES.find(
44135
44376
  (entry) => path2 === entry.file || path2.endsWith(`/${entry.file}`)
@@ -44219,7 +44460,7 @@ async function upgradeFile(parsed, context) {
44219
44460
  );
44220
44461
  if (info.isDirectory()) return upgradeFolder(source, parsed, context);
44221
44462
  const zipped = extname(source).toLowerCase() === ".zip";
44222
- const input = zipped ? codec.decode(await readFile5(source)) : parse3(await readFile5(source, "utf8"), source);
44463
+ const input = zipped ? codec.decode(await readFile5(source)) : parse4(await readFile5(source, "utf8"), source);
44223
44464
  const output = upgradeJson(input, source, context);
44224
44465
  const changed = report(input, output, name, parsed, context);
44225
44466
  if (parsed.flags.check === true) return changed ? 1 : 0;
@@ -44270,10 +44511,14 @@ function folderEnvironment(allowList, source) {
44270
44511
  }
44271
44512
  var VALUE_KEYS = /* @__PURE__ */ new Set(["before", "after", "message"]);
44272
44513
  function maskFilledText(text, filled) {
44273
- const secrets = [...filled].map(([variable, secret]) => ({
44274
- secret,
44275
- placeholder: `\${${variable}}`
44276
- })).sort((left, right) => right.secret.length - left.secret.length);
44514
+ const secrets = [...filled].flatMap(([variable, secret]) => {
44515
+ const placeholder = `\${${variable}}`;
44516
+ const escaped = escapeConfigPlaceholders(secret);
44517
+ return escaped === secret ? [{ secret, placeholder }] : [
44518
+ { secret, placeholder },
44519
+ { secret: escaped, placeholder }
44520
+ ];
44521
+ }).sort((left, right) => right.secret.length - left.secret.length);
44277
44522
  for (const { secret, placeholder } of secrets) {
44278
44523
  if (text === secret) return placeholder;
44279
44524
  if (secret.length >= MIN_MASKED_LENGTH)
@@ -44402,7 +44647,11 @@ async function resourceFiles(tenantRoot, resource) {
44402
44647
  }
44403
44648
  async function loadDocument(tenantRoot, file, kind, env) {
44404
44649
  const payload = JSON.parse(await readFile6(join6(tenantRoot, file), "utf8"));
44405
- const resolved = resolveConfigVariables(payload, env).value;
44650
+ const resolved = resolveConfigVariables(
44651
+ payload,
44652
+ env,
44653
+ kind === "KmsConfig" ? "none" : "keep"
44654
+ ).value;
44406
44655
  const document = normalizeDocument(
44407
44656
  isConfigDocument(resolved) ? resolved : wrapBare(kind, resolved, file)
44408
44657
  );
@@ -44622,7 +44871,7 @@ async function runPortabilityCommand(action, config, parsed, context) {
44622
44871
  const allowEnv = readStringFlag(parsed.flags, "allow-env");
44623
44872
  if (allowEnv !== void 0 && !folder)
44624
44873
  throw new Error(
44625
- "--allow-env applies to a tenant folder only; a bundle's placeholders are resolved by the server."
44874
+ "--allow-env applies to a tenant folder only; replace the placeholders of a bundle with their values."
44626
44875
  );
44627
44876
  const folderEnv = folderEnvironment(allowEnv, context.env);
44628
44877
  if (folder) {
@@ -44695,6 +44944,13 @@ async function runPortabilityCommand(action, config, parsed, context) {
44695
44944
  body = JSON.stringify(bundle);
44696
44945
  headers = { ...headers, "content-type": "application/json" };
44697
44946
  }
44947
+ if (folder) {
44948
+ const warning = escapedFormWarning(
44949
+ await backendVersion(baseUrl, authHeaders, context)
44950
+ );
44951
+ if (warning) context.stderr.write(`${warning}
44952
+ `);
44953
+ }
44698
44954
  const response = await context.fetch(
44699
44955
  `${baseUrl}/api/config-bundles/${endpoint}?${query}`,
44700
44956
  { method: "POST", headers, body }
@@ -44756,6 +45012,17 @@ async function runPortabilityCommand(action, config, parsed, context) {
44756
45012
  `);
44757
45013
  return result.applicable === false ? 1 : 0;
44758
45014
  }
45015
+ async function backendVersion(baseUrl, headers, context) {
45016
+ try {
45017
+ const response = await context.fetch(`${baseUrl}/api/version`, {
45018
+ headers
45019
+ });
45020
+ if (!response.ok) return void 0;
45021
+ return readBackendVersion(await response.json());
45022
+ } catch {
45023
+ return void 0;
45024
+ }
45025
+ }
44759
45026
  async function exportFolder(baseUrl, headers, output, context) {
44760
45027
  const response = await context.fetch(
44761
45028
  `${baseUrl}/api/config-bundles/export?format=zip`,
@@ -45272,9 +45539,13 @@ async function validateTenantConfig(scope, parsed, context) {
45272
45539
  rootPath,
45273
45540
  basename6(rootPath),
45274
45541
  schemas,
45275
- context.env
45542
+ context.env,
45543
+ // As the backend loads the folder from CONFIG_FOLDER.
45544
+ { folderVariablePolicy: true }
45276
45545
  )
45277
- ] : await validateTenantsRoot(rootPath, schemas, context.env);
45546
+ ] : await validateTenantsRoot(rootPath, schemas, context.env, {
45547
+ folderVariablePolicy: true
45548
+ });
45278
45549
  context.stdout.write(
45279
45550
  format2 === "json" ? `${JSON.stringify(buildJsonReport(results), null, 2)}
45280
45551
  ` : formatTextReport(scope, rootPath, results)
@@ -46946,7 +47217,7 @@ function createDeploymentCommands(context, setExitCode) {
46946
47217
  // package.json
46947
47218
  var package_default = {
46948
47219
  name: "@eudiplo/cli",
46949
- version: "10.1.0-main.6e16824",
47220
+ version: "10.1.0-main.6fdbc3a",
46950
47221
  description: "Deployment-aware command line tools for EUDIPLO",
46951
47222
  private: false,
46952
47223
  type: "module",
@@ -47084,99 +47355,6 @@ function withTrailingSlash(url) {
47084
47355
  return url.href.endsWith("/") ? url : new URL(`${url.href}/`);
47085
47356
  }
47086
47357
 
47087
- // src/services/backend-checks.ts
47088
- function compareVersions(cliVersion, backendVersion) {
47089
- const name = "version compatibility";
47090
- const cli = parse4(cliVersion);
47091
- const backend = parse4(backendVersion);
47092
- if (!cli || !backend) {
47093
- return {
47094
- name,
47095
- status: "warn",
47096
- message: `CLI ${cliVersion} and backend ${backendVersion} cannot be compared as versions.`
47097
- };
47098
- }
47099
- if (cli.major !== backend.major) {
47100
- return {
47101
- name,
47102
- status: "fail",
47103
- message: `CLI ${cliVersion} and backend ${backendVersion} are different major versions. Install a matching CLI with npm install -g @eudiplo/cli@${backend.major}.`
47104
- };
47105
- }
47106
- if (cli.minor !== backend.minor) {
47107
- return {
47108
- name,
47109
- status: "warn",
47110
- message: `CLI ${cliVersion} and backend ${backendVersion} differ in minor version; some commands may not be supported.`
47111
- };
47112
- }
47113
- return {
47114
- name,
47115
- status: "pass",
47116
- message: `CLI ${cliVersion} matches backend ${backendVersion}.`
47117
- };
47118
- }
47119
- function readBackendVersion(body) {
47120
- if (typeof body === "object" && body !== null && "version" in body) {
47121
- const version = body.version;
47122
- return typeof version === "string" && version ? version : void 0;
47123
- }
47124
- return void 0;
47125
- }
47126
- function readProviderHealth(body) {
47127
- if (!Array.isArray(body)) {
47128
- throw new Error("the provider health response was not a list");
47129
- }
47130
- return body.map((entry) => {
47131
- const record = entry;
47132
- return {
47133
- providerId: String(record.providerId ?? "unknown"),
47134
- type: String(record.type ?? "unknown"),
47135
- ok: record.ok === true,
47136
- latencyMs: typeof record.latencyMs === "number" ? record.latencyMs : void 0,
47137
- error: typeof record.error === "string" ? record.error : void 0
47138
- };
47139
- });
47140
- }
47141
- function summarizeProviderHealth(providers) {
47142
- const name = "KMS providers";
47143
- if (providers.length === 0) {
47144
- return {
47145
- name,
47146
- status: "warn",
47147
- message: "No KMS providers are registered for this tenant."
47148
- };
47149
- }
47150
- const failing = providers.filter((provider) => !provider.ok);
47151
- if (failing.length > 0) {
47152
- return {
47153
- name,
47154
- status: "fail",
47155
- message: `${failing.length}/${providers.length} provider(s) unhealthy: ${failing.map(
47156
- (provider) => `${provider.providerId} (${provider.type})${provider.error ? ", health check reported an error" : ""}`
47157
- ).join(", ")}`
47158
- };
47159
- }
47160
- return {
47161
- name,
47162
- status: "pass",
47163
- message: `${providers.length} provider(s) healthy: ${providers.map(
47164
- (provider) => `${provider.providerId} (${provider.type}${provider.latencyMs === void 0 ? "" : `, ${provider.latencyMs}ms`})`
47165
- ).join(", ")}`
47166
- };
47167
- }
47168
- function parse4(version) {
47169
- const match = /^v?(\d+)\.(\d+)\.(\d+)/.exec(version.trim());
47170
- if (!match) {
47171
- return void 0;
47172
- }
47173
- return {
47174
- major: Number(match[1]),
47175
- minor: Number(match[2]),
47176
- patch: Number(match[3])
47177
- };
47178
- }
47179
-
47180
47358
  // src/services/tls-expiry.ts
47181
47359
  import { connect } from "node:tls";
47182
47360
  var defaultExpiryWarningDays = 30;
@@ -47356,15 +47534,15 @@ var versionCompatibilityCheck = {
47356
47534
  message: `The backend version could not be read: ${response.reason}`
47357
47535
  };
47358
47536
  }
47359
- const backendVersion = readBackendVersion(response.body);
47360
- if (!backendVersion) {
47537
+ const backendVersion2 = readBackendVersion(response.body);
47538
+ if (!backendVersion2) {
47361
47539
  return {
47362
47540
  name: "version compatibility",
47363
47541
  status: "warn",
47364
47542
  message: "The backend did not report a version."
47365
47543
  };
47366
47544
  }
47367
- return compareVersions(package_default.version, backendVersion);
47545
+ return compareVersions(package_default.version, backendVersion2);
47368
47546
  })
47369
47547
  };
47370
47548
  var kmsHealthCheck = {