facturas 0.20.2 → 0.20.4

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.
@@ -10,7 +10,7 @@ import {
10
10
  } from "./chunk-C2KX652X.mjs";
11
11
  import {
12
12
  createPadronService
13
- } from "./chunk-JP3LVU7K.mjs";
13
+ } from "./chunk-UOIZQMA6.mjs";
14
14
  import {
15
15
  arcaMinorUnitsToNumber,
16
16
  assertArcaMinorUnits,
@@ -22,10 +22,10 @@ import {
22
22
  roundHalfEvenRatio,
23
23
  serializeArcaExchangeRate,
24
24
  toIsoDate
25
- } from "./chunk-3NOKGXXX.mjs";
25
+ } from "./chunk-6U4NRHFP.mjs";
26
26
  import {
27
27
  createWsmtxcaService
28
- } from "./chunk-VF3XJXBG.mjs";
28
+ } from "./chunk-WG6TAMBB.mjs";
29
29
  import {
30
30
  ArcaConfigurationError,
31
31
  ArcaError,
@@ -3906,6 +3906,7 @@ async function runOperation(wsfe, operation, input, prepare, options, context, r
3906
3906
  environment,
3907
3907
  taxId,
3908
3908
  sequence: sequenceRecord,
3909
+ sequenceTaxId: sequence.taxId,
3909
3910
  coordinates: sequence.coordinates,
3910
3911
  select: select ?? (() => wsfe),
3911
3912
  options,
@@ -3945,6 +3946,7 @@ async function runOperation(wsfe, operation, input, prepare, options, context, r
3945
3946
  const claimed = {
3946
3947
  v: 1,
3947
3948
  key: idempotencyKey,
3949
+ issuerTaxId: taxId,
3948
3950
  number,
3949
3951
  claimedAt: (/* @__PURE__ */ new Date()).toISOString()
3950
3952
  };
@@ -3993,7 +3995,7 @@ async function runOperation(wsfe, operation, input, prepare, options, context, r
3993
3995
  readSettledRecord(recorded),
3994
3996
  options,
3995
3997
  taxId,
3996
- (other) => storeCall(() => store.get(settledKey(environment, taxId, other)))
3998
+ (owner, other) => storeCall(() => store.get(settledKey(environment, owner, other)))
3997
3999
  );
3998
4000
  }
3999
4001
  return await settle2(
@@ -4046,7 +4048,7 @@ async function recordConflict(store, key, outcome) {
4046
4048
  function readSettledRecord(json) {
4047
4049
  try {
4048
4050
  const record = JSON.parse(json);
4049
- if (record?.v !== 1 && record?.v !== 2 || !Number.isSafeInteger(record.number) || (record.kind === "conflict" ? !record.found || typeof record.found !== "object" : record.kind !== "superseded" || typeof record.by !== "string")) {
4051
+ if (record?.v !== 1 && record?.v !== 2 || !Number.isSafeInteger(record.number) || (record.kind === "conflict" ? !record.found || typeof record.found !== "object" : record.kind !== "superseded" || typeof record.by !== "string" || record.byTaxId !== void 0 && typeof record.byTaxId !== "string")) {
4050
4052
  throw new Error("Invalid settled structure");
4051
4053
  }
4052
4054
  if (record.kind === "conflict" && record.v === 1) {
@@ -4072,7 +4074,7 @@ async function settledOutcome(select, reservation, settled, options, taxId, sett
4072
4074
  true
4073
4075
  );
4074
4076
  const empty = outcome.kind === "indeterminate" && outcome.lookup.kind === "not_found";
4075
- if (!empty && (outcome.kind !== "conflict" || await successionDisputed(settled.by, settledFor))) {
4077
+ if (!empty && (outcome.kind !== "conflict" || await successionDisputed(settled, taxId, settledFor))) {
4076
4078
  return outcome;
4077
4079
  }
4078
4080
  return {
@@ -4083,7 +4085,11 @@ async function settledOutcome(select, reservation, settled, options, taxId, sett
4083
4085
  number: settled.number
4084
4086
  },
4085
4087
  attempt: replayEvidence(reservation.service),
4086
- lookup: { kind: "superseded", by: settled.by },
4088
+ lookup: {
4089
+ kind: "superseded",
4090
+ by: settled.by,
4091
+ byTaxId: settled.byTaxId ?? taxId
4092
+ },
4087
4093
  ...requestEvidence(
4088
4094
  preparedFromRecord(reservation).data,
4089
4095
  reservation.number,
@@ -4091,10 +4097,11 @@ async function settledOutcome(select, reservation, settled, options, taxId, sett
4091
4097
  )
4092
4098
  };
4093
4099
  }
4094
- async function successionDisputed(key, settledFor) {
4095
- let next = key;
4100
+ async function successionDisputed(superseded, taxId, settledFor) {
4101
+ let owner = superseded.byTaxId ?? taxId;
4102
+ let next = superseded.by;
4096
4103
  for (let hop = 0; hop < 16; hop += 1) {
4097
- const json = await settledFor(next);
4104
+ const json = await settledFor(owner, next);
4098
4105
  if (json === null) {
4099
4106
  return false;
4100
4107
  }
@@ -4102,6 +4109,7 @@ async function successionDisputed(key, settledFor) {
4102
4109
  if (record.kind === "conflict") {
4103
4110
  return true;
4104
4111
  }
4112
+ owner = record.byTaxId ?? owner;
4105
4113
  next = record.by;
4106
4114
  }
4107
4115
  return true;
@@ -4844,13 +4852,9 @@ async function recoverOperation(select, key, inputOptions, context) {
4844
4852
  readSettledRecord(recorded),
4845
4853
  options,
4846
4854
  context.taxId,
4847
- (other) => storeCall(
4855
+ (owner, other) => storeCall(
4848
4856
  () => store.get(
4849
- settledKey(
4850
- context.environment,
4851
- context.taxId,
4852
- other
4853
- )
4857
+ settledKey(context.environment, owner, other)
4854
4858
  )
4855
4859
  )
4856
4860
  );
@@ -4990,6 +4994,7 @@ async function runSequenceBarrier({
4990
4994
  environment,
4991
4995
  taxId,
4992
4996
  sequence,
4997
+ sequenceTaxId,
4993
4998
  coordinates,
4994
4999
  select,
4995
5000
  options,
@@ -5004,12 +5009,13 @@ async function runSequenceBarrier({
5004
5009
  if (claimed.resolvedAt !== void 0) {
5005
5010
  return {};
5006
5011
  }
5007
- const settled = settledKey(environment, taxId, claimed.key);
5012
+ const owner = claimed.issuerTaxId ?? taxId;
5013
+ const settled = settledKey(environment, owner, claimed.key);
5008
5014
  if (await storeCall(() => store.get(settled)) !== null) {
5009
5015
  return {};
5010
5016
  }
5011
5017
  const reservation = await storeCall(
5012
- () => store.get(attemptKey(environment, taxId, claimed.key))
5018
+ () => store.get(attemptKey(environment, owner, claimed.key))
5013
5019
  );
5014
5020
  if (reservation === null) {
5015
5021
  return {};
@@ -5020,7 +5026,7 @@ async function runSequenceBarrier({
5020
5026
  kind: "indeterminate",
5021
5027
  attempted: { ...coordinates, number: record.number },
5022
5028
  attempt: replayEvidence(options.service),
5023
- lookup: { kind: "blocked", by: claimed.key }
5029
+ lookup: { kind: "blocked", by: claimed.key, byTaxId: owner }
5024
5030
  }
5025
5031
  };
5026
5032
  const outcome = await recordConflict(
@@ -5028,12 +5034,18 @@ async function runSequenceBarrier({
5028
5034
  settled,
5029
5035
  await consultReservation(
5030
5036
  select,
5031
- record,
5037
+ // This call's certificate may not be the one that claimed. Without a
5038
+ // represented CUIT, it would read its own numbering instead of the one
5039
+ // the claim advanced.
5040
+ {
5041
+ ...record,
5042
+ representedTaxId: record.representedTaxId ?? sequenceTaxId
5043
+ },
5032
5044
  {
5033
5045
  forceRefresh: options.forceRefresh,
5034
5046
  ...options.abortSignal === void 0 ? {} : { abortSignal: options.abortSignal }
5035
5047
  },
5036
- taxId
5048
+ owner
5037
5049
  )
5038
5050
  );
5039
5051
  if (outcome.kind === "authorized" || outcome.kind === "conflict") {
@@ -5054,6 +5066,7 @@ async function runSequenceBarrier({
5054
5066
  kind: "superseded",
5055
5067
  number: record.number,
5056
5068
  by: supersededBy,
5069
+ byTaxId: taxId,
5057
5070
  settledAt: (/* @__PURE__ */ new Date()).toISOString()
5058
5071
  })
5059
5072
  )
@@ -5063,7 +5076,7 @@ async function runSequenceBarrier({
5063
5076
  function readSequenceRecord(json) {
5064
5077
  try {
5065
5078
  const record = JSON.parse(json);
5066
- if (record?.v !== 1 || typeof record.key !== "string" || !Number.isSafeInteger(record.number)) {
5079
+ if (record?.v !== 1 || typeof record.key !== "string" || record.issuerTaxId !== void 0 && typeof record.issuerTaxId !== "string" || !Number.isSafeInteger(record.number)) {
5067
5080
  throw new Error("Invalid sequence structure");
5068
5081
  }
5069
5082
  return record;
@@ -5595,4 +5608,4 @@ export {
5595
5608
  withLease,
5596
5609
  createFileStore
5597
5610
  };
5598
- //# sourceMappingURL=chunk-ZNMTFZ2Q.mjs.map
5611
+ //# sourceMappingURL=chunk-CYXS3F34.mjs.map