facturas 0.20.3 → 0.20.5

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/cli.mjs CHANGED
@@ -7,12 +7,13 @@ import {
7
7
  createWsaaAuthModule,
8
8
  createWsaaStoreAdapter,
9
9
  discoverArcaClientConfig
10
- } from "./chunk-5CUMVSJY.mjs";
10
+ } from "./chunk-KBEV7QTU.mjs";
11
11
  import "./chunk-C2KX652X.mjs";
12
- import "./chunk-JP3LVU7K.mjs";
13
- import "./chunk-3NOKGXXX.mjs";
14
- import "./chunk-VF3XJXBG.mjs";
15
- import "./chunk-XTKZ5FDN.mjs";
12
+ import "./chunk-UOIZQMA6.mjs";
13
+ import "./chunk-VEKUMXHW.mjs";
14
+ import "./chunk-EXJMG54W.mjs";
15
+ import "./chunk-YPQJRSTA.mjs";
16
+ import "./chunk-B2M64SIK.mjs";
16
17
  import {
17
18
  ArcaConfigurationError,
18
19
  ArcaServiceError,
@@ -109,7 +110,7 @@ function certificateFileName(environment) {
109
110
  function privateKeyFileName(environment) {
110
111
  return `arca-${environment}.key`;
111
112
  }
112
- function discoverCredentials(directory, environment) {
113
+ function discoverCredentials(directory, environment, supplied = {}) {
113
114
  const candidates = (environment === void 0 ? DISCOVERY_ORDER : [environment]).map((candidate) => {
114
115
  const certificateFile = certificateFileName(candidate);
115
116
  const keyFile = privateKeyFileName(candidate);
@@ -122,12 +123,14 @@ function discoverCredentials(directory, environment) {
122
123
  };
123
124
  });
124
125
  const complete = candidates.filter(
125
- (candidate) => candidate.hasCertificate && candidate.hasKey
126
+ (candidate) => (candidate.hasCertificate || supplied.certificatePem) && (candidate.hasKey || supplied.privateKeyPem)
126
127
  );
127
128
  if (complete.length > 1) {
128
129
  return {
129
130
  kind: "ambiguous",
130
- files: complete.map((candidate) => candidate.certificateFile)
131
+ files: complete.map(
132
+ (candidate) => supplied.certificatePem ? candidate.keyFile : candidate.certificateFile
133
+ )
131
134
  };
132
135
  }
133
136
  const [pair] = complete;
@@ -138,8 +141,8 @@ function discoverCredentials(directory, environment) {
138
141
  environment: pair.environment,
139
142
  certificateFile: pair.certificateFile,
140
143
  keyFile: pair.keyFile,
141
- certificatePem: read(directory, pair.certificateFile),
142
- privateKeyPem: read(directory, pair.keyFile)
144
+ certificatePem: supplied.certificatePem || read(directory, pair.certificateFile),
145
+ privateKeyPem: supplied.privateKeyPem || read(directory, pair.keyFile)
143
146
  }
144
147
  };
145
148
  }
@@ -944,30 +947,33 @@ function resolveCheckEnvironment(io, flags) {
944
947
  if (chosen) {
945
948
  return chosen;
946
949
  }
947
- if (flags.cert?.trim() || io.env.ARCA_CERTIFICATE_PEM?.trim()) {
948
- return void 0;
949
- }
950
950
  try {
951
- const discovery = discoverCredentials(resolveDirectory(io, flags.dir));
951
+ const { discovery } = resolveCredentials(io, flags);
952
952
  return discovery.kind === "found" ? discovery.credentials.environment : void 0;
953
953
  } catch {
954
954
  return void 0;
955
955
  }
956
956
  }
957
+ function resolveCredentials(io, flags, environment) {
958
+ const certificatePem = readPem(io, flags.cert, io.env.ARCA_CERTIFICATE_PEM);
959
+ const privateKeyPem = readPem(io, flags.key, io.env.ARCA_PRIVATE_KEY_PEM);
960
+ const discovery = certificatePem && privateKeyPem ? { kind: "none" } : discoverCredentials(resolveDirectory(io, flags.dir), environment, {
961
+ certificatePem,
962
+ privateKeyPem
963
+ });
964
+ return { certificatePem, privateKeyPem, discovery };
965
+ }
957
966
  function resolveConfigLayer(io, flags) {
958
967
  const chosenEnvironment = flags.env?.trim().toLowerCase() || io.env.ARCA_ENVIRONMENT?.trim();
959
968
  let certificatePem;
960
969
  let privateKeyPem;
961
- let discovery = { kind: "none" };
970
+ let discovery;
962
971
  try {
963
- certificatePem = readPem(io, flags.cert, io.env.ARCA_CERTIFICATE_PEM);
964
- privateKeyPem = readPem(io, flags.key, io.env.ARCA_PRIVATE_KEY_PEM);
965
- if (!(certificatePem && privateKeyPem)) {
966
- discovery = discoverCredentials(
967
- resolveDirectory(io, flags.dir),
968
- toEnvironment2(chosenEnvironment)
969
- );
970
- }
972
+ ({ certificatePem, privateKeyPem, discovery } = resolveCredentials(
973
+ io,
974
+ flags,
975
+ toEnvironment2(chosenEnvironment)
976
+ ));
971
977
  } catch (error) {
972
978
  const unknown = describeUnknownError(error);
973
979
  return {
@@ -1009,7 +1015,7 @@ function resolveConfigLayer(io, flags) {
1009
1015
  name: "config",
1010
1016
  ok: true,
1011
1017
  detail: describeSources({
1012
- ...describeCredentialSource(flags, found),
1018
+ ...describeCredentialSource(flags, found, certificatePem),
1013
1019
  taxId: taxId.source,
1014
1020
  ...describeEnvironmentSource(io, flags, config.environment)
1015
1021
  })
@@ -1080,14 +1086,15 @@ function readPem(io, file, fromEnv) {
1080
1086
  const path = isAbsolute2(file) ? file : resolve3(io.cwd, file);
1081
1087
  return readFileSync3(path, "utf8").trim();
1082
1088
  }
1083
- function describeCredentialSource(flags, found) {
1084
- if (found !== void 0) {
1085
- return { credentials: `${found.certificateFile} en este directorio` };
1086
- }
1089
+ function describeCredentialSource(flags, found, suppliedCertificate) {
1087
1090
  const named = [
1088
1091
  ...flags.cert?.trim() ? ["--cert"] : [],
1089
1092
  ...flags.key?.trim() ? ["--key"] : []
1090
1093
  ];
1094
+ if (found !== void 0) {
1095
+ const file = suppliedCertificate ? found.keyFile : found.certificateFile;
1096
+ named.push(`${file} en este directorio`);
1097
+ }
1091
1098
  return named.length === 0 ? {} : { credentials: named.join(" y ") };
1092
1099
  }
1093
1100
  function describeEnvironmentSource(io, flags, environment) {