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.
@@ -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-VEKUMXHW.mjs";
26
26
  import {
27
27
  createWsmtxcaService
28
- } from "./chunk-VF3XJXBG.mjs";
28
+ } from "./chunk-EXJMG54W.mjs";
29
29
  import {
30
30
  ArcaConfigurationError,
31
31
  ArcaError,
@@ -3876,49 +3876,35 @@ async function runOperation(wsfe, operation, input, prepare, options, context, r
3876
3876
  return await replay(existing);
3877
3877
  }
3878
3878
  const prepared = withinDateWindow(await prepare(), options);
3879
- const sequence = {
3880
- coordinates: {
3881
- salesPoint: prepared.data.salesPoint,
3882
- voucherType: prepared.data.voucherType
3883
- },
3884
- // The sequence belongs to the taxpayer whose numbering ARCA advances.
3885
- taxId: String(options.representedTaxId ?? context.taxId)
3886
- };
3887
- const sequenceRecord = sequenceKey(
3888
- environment,
3889
- sequence.taxId,
3890
- sequence.coordinates.salesPoint,
3891
- sequence.coordinates.voucherType
3892
- );
3879
+ const sequence = sequenceOf(environment, taxId, {
3880
+ representedTaxId,
3881
+ salesPoint: prepared.data.salesPoint,
3882
+ voucherType: prepared.data.voucherType
3883
+ });
3893
3884
  if (!store.withLock) {
3894
3885
  return await claim();
3895
3886
  }
3896
- return await store.withLock(
3897
- sequenceLockKey(
3898
- environment,
3899
- sequence.taxId,
3900
- sequence.coordinates.salesPoint,
3901
- sequence.coordinates.voucherType
3902
- ),
3903
- async () => {
3904
- const barrier = await runSequenceBarrier({
3905
- store,
3906
- environment,
3907
- taxId,
3908
- sequence: sequenceRecord,
3909
- sequenceTaxId: sequence.taxId,
3910
- coordinates: sequence.coordinates,
3911
- select: select ?? (() => wsfe),
3912
- options,
3913
- supersededBy: idempotencyKey,
3914
- readNext: () => nextNumber(wsfe, prepared.data, options)
3915
- });
3916
- return "blocked" in barrier ? {
3917
- ...barrier.blocked,
3918
- ...requestEvidence(prepared.data, void 0, options)
3919
- } : await claim(barrier.reserved);
3887
+ return await store.withLock(sequence.lock, async () => {
3888
+ const prior = await storeCall(() => store.get(key));
3889
+ if (prior !== null) {
3890
+ return await replay(prior, true);
3920
3891
  }
3921
- );
3892
+ const barrier = await runSequenceBarrier({
3893
+ store,
3894
+ environment,
3895
+ taxId,
3896
+ sequence: sequence.marker,
3897
+ sequenceTaxId: sequence.taxId,
3898
+ select: select ?? (() => wsfe),
3899
+ options,
3900
+ supersededBy: idempotencyKey,
3901
+ readNext: () => nextNumber(wsfe, prepared.data, { ...options, number: void 0 })
3902
+ });
3903
+ return "blocked" in barrier ? {
3904
+ ...barrier.blocked,
3905
+ ...requestEvidence(prepared.data, void 0, options)
3906
+ } : await claim(barrier.reserved);
3907
+ });
3922
3908
  function reservation(number) {
3923
3909
  const service = options.service ?? "wsfe";
3924
3910
  const versioned = service === "wsmtxca" || prepared.data.lines !== void 0;
@@ -3937,10 +3923,6 @@ async function runOperation(wsfe, operation, input, prepare, options, context, r
3937
3923
  }
3938
3924
  async function claim(reserved) {
3939
3925
  const coordinated = store.withLock !== void 0;
3940
- const prior = coordinated ? await storeCall(() => store.get(key)) : null;
3941
- if (prior !== null) {
3942
- return await replay(prior, true);
3943
- }
3944
3926
  const number = options.number ?? reserved ?? await nextNumber(wsfe, prepared.data, options);
3945
3927
  const record = reservation(number);
3946
3928
  const claimed = {
@@ -3951,21 +3933,20 @@ async function runOperation(wsfe, operation, input, prepare, options, context, r
3951
3933
  claimedAt: (/* @__PURE__ */ new Date()).toISOString()
3952
3934
  };
3953
3935
  if (coordinated) {
3954
- await storeCall(() => store.set(sequenceRecord, JSON.stringify(claimed)));
3936
+ await storeCall(
3937
+ () => store.set(sequence.marker, JSON.stringify(claimed))
3938
+ );
3955
3939
  }
3956
3940
  if (await storeCall(() => store.add(key, JSON.stringify(record)))) {
3957
- const outcome = await settle2(
3958
- runAuthorization(wsfe, prepared, options, issuer, number)
3941
+ return await settle2(
3942
+ record,
3943
+ runAuthorization(wsfe, prepared, options, issuer, number, {
3944
+ strangerAtNumber: true
3945
+ }),
3946
+ // Without the lock, a retry of this key may write the number while
3947
+ // this claim is still in flight: its 10016 is not marked.
3948
+ { written: claimed, everyRejected: true, racing: !coordinated }
3959
3949
  );
3960
- if (coordinated && outcome.kind !== "indeterminate") {
3961
- await storeCall(
3962
- () => store.set(
3963
- sequenceRecord,
3964
- JSON.stringify({ ...claimed, resolvedAt: (/* @__PURE__ */ new Date()).toISOString() })
3965
- )
3966
- );
3967
- }
3968
- return outcome;
3969
3950
  }
3970
3951
  const winner = await storeCall(() => store.get(key));
3971
3952
  if (winner === null) {
@@ -3986,51 +3967,156 @@ async function runOperation(wsfe, operation, input, prepare, options, context, r
3986
3967
  }
3987
3968
  );
3988
3969
  }
3989
- const consult = async () => {
3990
- const recorded = await storeCall(() => store.get(settled));
3991
- if (recorded !== null) {
3992
- return await settledOutcome(
3993
- select ?? (() => wsfe),
3994
- stored,
3995
- readSettledRecord(recorded),
3996
- options,
3997
- taxId,
3998
- (owner, other) => storeCall(() => store.get(settledKey(environment, owner, other)))
3999
- );
3970
+ return await consultKey(
3971
+ { store, environment, taxId, idempotencyKey },
3972
+ stored,
3973
+ locked,
3974
+ select ?? (() => wsfe),
3975
+ options,
3976
+ resend
3977
+ );
3978
+ }
3979
+ async function resend(current) {
3980
+ const rejected = current.rejectedAt !== void 0;
3981
+ if (rejected) {
3982
+ const held = await clearRejection(current);
3983
+ if (held !== void 0) {
3984
+ return held;
4000
3985
  }
4001
- return await settle2(
4002
- runAuthorization(
4003
- wsfe,
4004
- {
4005
- ...preparedFromRecord(stored),
4006
- ...replayAmounts ? { amounts: replayAmounts } : {}
4007
- },
4008
- options,
4009
- issuer,
4010
- stored.number,
4011
- true
4012
- )
4013
- );
4014
- };
4015
- if (locked || !store.withLock) {
4016
- return await consult();
4017
- }
4018
- return await store.withLock(
4019
- sequenceLockKey(
4020
- environment,
4021
- stored.representedTaxId ?? taxId,
4022
- stored.salesPoint,
4023
- stored.voucherType
3986
+ }
3987
+ return await settle2(
3988
+ current,
3989
+ runAuthorization(
3990
+ wsfe,
3991
+ {
3992
+ ...preparedFromRecord(current),
3993
+ ...replayAmounts ? { amounts: replayAmounts } : {}
3994
+ },
3995
+ options,
3996
+ issuer,
3997
+ current.number,
3998
+ { lookupFirst: !rejected, strangerAtNumber: rejected }
4024
3999
  ),
4025
- consult
4000
+ { everyRejected: rejected, presumed: rejected, racing: rejected }
4026
4001
  );
4027
4002
  }
4028
- async function settle2(running) {
4029
- return await recordConflict(store, settled, await running);
4003
+ async function settle2(record, running, {
4004
+ written,
4005
+ everyRejected = false,
4006
+ presumed = false,
4007
+ racing = false
4008
+ } = {}) {
4009
+ const uncoordinated = !store.withLock;
4010
+ const outcome = await recordConflict(
4011
+ store,
4012
+ settled,
4013
+ await running,
4014
+ !(presumed && uncoordinated)
4015
+ );
4016
+ const marks = outcome.kind === "rejected" && everyRejected && !(uncoordinated && racing && mayHoldNumber(outcome.issues, record.service));
4017
+ if (marks) {
4018
+ const rejected = { ...record, rejectedAt: (/* @__PURE__ */ new Date()).toISOString() };
4019
+ await storeCall(() => store.set(key, JSON.stringify(rejected)));
4020
+ }
4021
+ if (!store.withLock || outcome.kind === "indeterminate" || outcome.kind === "rejected" && !marks) {
4022
+ return outcome;
4023
+ }
4024
+ const { marker } = sequenceOf(environment, taxId, record);
4025
+ const json = written ? null : await storeCall(() => store.get(marker));
4026
+ const claimed = written ?? (json === null ? null : readSequenceRecord(json));
4027
+ if (claimed !== null && isOwnClaim(claimed) && claimed.number === record.number && claimed.resolvedAt === void 0) {
4028
+ const resolved = { ...claimed, resolvedAt: (/* @__PURE__ */ new Date()).toISOString() };
4029
+ await storeCall(() => store.set(marker, JSON.stringify(resolved)));
4030
+ }
4031
+ return outcome;
4032
+ }
4033
+ async function clearRejection(record) {
4034
+ const checked = await settle2(
4035
+ record,
4036
+ consultReservation(select ?? (() => wsfe), record, options, taxId, true),
4037
+ { presumed: true }
4038
+ );
4039
+ if (checked.kind !== "indeterminate" || checked.lookup.kind !== "not_found") {
4040
+ return checked;
4041
+ }
4042
+ const holder = await reclaim(record);
4043
+ if (holder !== void 0) {
4044
+ return withheld(
4045
+ record,
4046
+ { kind: "blocked", by: holder.key, byTaxId: holder.issuerTaxId },
4047
+ options
4048
+ );
4049
+ }
4050
+ const { rejectedAt: _, ...pending } = record;
4051
+ await storeCall(() => store.set(key, JSON.stringify(pending)));
4052
+ }
4053
+ async function reclaim(record) {
4054
+ if (!store.withLock) {
4055
+ return;
4056
+ }
4057
+ const { marker } = sequenceOf(environment, taxId, record);
4058
+ const json = await storeCall(() => store.get(marker));
4059
+ const claimed = json === null ? null : readSequenceRecord(json);
4060
+ if (claimed !== null && !isOwnClaim(claimed) && claimed.resolvedAt === void 0) {
4061
+ return { key: claimed.key, issuerTaxId: claimed.issuerTaxId ?? taxId };
4062
+ }
4063
+ const reopened = {
4064
+ v: 1,
4065
+ key: idempotencyKey,
4066
+ issuerTaxId: taxId,
4067
+ number: record.number,
4068
+ claimedAt: (/* @__PURE__ */ new Date()).toISOString()
4069
+ };
4070
+ await storeCall(() => store.set(marker, JSON.stringify(reopened)));
4071
+ }
4072
+ function isOwnClaim(claimed) {
4073
+ return claimed.key === idempotencyKey && (claimed.issuerTaxId ?? taxId) === taxId;
4030
4074
  }
4031
4075
  }
4032
- async function recordConflict(store, key, outcome) {
4033
- if (outcome.kind !== "conflict") {
4076
+ function sequenceOf(environment, taxId, {
4077
+ representedTaxId,
4078
+ salesPoint,
4079
+ voucherType
4080
+ }) {
4081
+ const owner = representedTaxId ?? taxId;
4082
+ return {
4083
+ taxId: owner,
4084
+ marker: sequenceKey(environment, owner, salesPoint, voucherType),
4085
+ lock: sequenceLockKey(environment, owner, salesPoint, voucherType)
4086
+ };
4087
+ }
4088
+ async function consultKey({ store, environment, taxId, idempotencyKey }, stored, locked, select, options, unrecorded) {
4089
+ const consult = async (current) => {
4090
+ const recorded = await storeCall(
4091
+ () => store.get(settledKey(environment, taxId, idempotencyKey))
4092
+ );
4093
+ if (recorded === null) {
4094
+ return await unrecorded(current);
4095
+ }
4096
+ return await settledOutcome(
4097
+ select,
4098
+ current,
4099
+ readSettledRecord(recorded),
4100
+ options,
4101
+ taxId,
4102
+ (owner, other) => storeCall(() => store.get(settledKey(environment, owner, other)))
4103
+ );
4104
+ };
4105
+ if (locked || !store.withLock) {
4106
+ return await consult(stored);
4107
+ }
4108
+ return await store.withLock(
4109
+ sequenceOf(environment, taxId, stored).lock,
4110
+ async () => {
4111
+ const json = await storeCall(
4112
+ () => store.get(attemptKey(environment, taxId, idempotencyKey))
4113
+ );
4114
+ return await consult(json === null ? stored : readRecord(json));
4115
+ }
4116
+ );
4117
+ }
4118
+ async function recordConflict(store, key, outcome, durable = true) {
4119
+ if (outcome.kind !== "conflict" || !durable) {
4034
4120
  return outcome;
4035
4121
  }
4036
4122
  const record = {
@@ -4077,26 +4163,33 @@ async function settledOutcome(select, reservation, settled, options, taxId, sett
4077
4163
  if (!empty && (outcome.kind !== "conflict" || await successionDisputed(settled, taxId, settledFor))) {
4078
4164
  return outcome;
4079
4165
  }
4166
+ return withheld(
4167
+ reservation,
4168
+ { kind: "superseded", by: settled.by, byTaxId: settled.byTaxId ?? taxId },
4169
+ options,
4170
+ settled.number
4171
+ );
4172
+ }
4173
+ function withheld(reservation, lookup, options, number = reservation.number) {
4080
4174
  return {
4081
4175
  kind: "indeterminate",
4082
4176
  attempted: {
4083
4177
  salesPoint: reservation.salesPoint,
4084
4178
  voucherType: reservation.voucherType,
4085
- number: settled.number
4179
+ number
4086
4180
  },
4087
4181
  attempt: replayEvidence(reservation.service),
4088
- lookup: {
4089
- kind: "superseded",
4090
- by: settled.by,
4091
- byTaxId: settled.byTaxId ?? taxId
4092
- },
4093
- ...requestEvidence(
4094
- preparedFromRecord(reservation).data,
4095
- reservation.number,
4096
- { ...options, service: reservation.service ?? "wsfe" }
4097
- )
4182
+ lookup,
4183
+ ...reservationEvidence(reservation, options)
4098
4184
  };
4099
4185
  }
4186
+ function reservationEvidence(reservation, options) {
4187
+ return requestEvidence(
4188
+ preparedFromRecord(reservation).data,
4189
+ reservation.number,
4190
+ { ...options, service: reservation.service ?? "wsfe" }
4191
+ );
4192
+ }
4100
4193
  async function successionDisputed(superseded, taxId, settledFor) {
4101
4194
  let owner = superseded.byTaxId ?? taxId;
4102
4195
  let next = superseded.by;
@@ -4125,11 +4218,7 @@ function settledConflict(settled, reservation, options) {
4125
4218
  attempt: replayEvidence(reservation.service),
4126
4219
  found: settled.found,
4127
4220
  reason: "This key already recorded another voucher at the reserved number. Reconcile before issuing under a new key.",
4128
- ...requestEvidence(
4129
- preparedFromRecord(reservation).data,
4130
- reservation.number,
4131
- { ...options, service: reservation.service ?? "wsfe" }
4132
- )
4221
+ ...reservationEvidence(reservation, options)
4133
4222
  };
4134
4223
  }
4135
4224
  function validateKeyStore(options, context) {
@@ -4151,7 +4240,7 @@ function validateKeyStore(options, context) {
4151
4240
  function readRecord(json) {
4152
4241
  try {
4153
4242
  const record = JSON.parse(json);
4154
- if (!record || record.v !== 1 && record.v !== 2 || record.v === 2 && record.service === void 0 || !["issue", "creditNote", "debitNote"].includes(record.operation) || typeof record.inputHash !== "string" || !record.sent || !Number.isSafeInteger(record.number) || record.number < 1 || record.number > 99999999 || record.sent.salesPoint !== record.salesPoint || record.sent.voucherType !== record.voucherType) {
4243
+ if (!record || record.v !== 1 && record.v !== 2 || record.v === 2 && record.service === void 0 || !["issue", "creditNote", "debitNote"].includes(record.operation) || typeof record.inputHash !== "string" || !record.sent || record.rejectedAt !== void 0 && typeof record.rejectedAt !== "string" || !Number.isSafeInteger(record.number) || record.number < 1 || record.number > 99999999 || record.sent.salesPoint !== record.salesPoint || record.sent.voucherType !== record.voucherType) {
4155
4244
  throw new Error("Invalid reservation structure");
4156
4245
  }
4157
4246
  normalizeWsfeVoucherInput(record.sent);
@@ -4201,7 +4290,7 @@ async function nextNumber(wsfe, data, options) {
4201
4290
  }
4202
4291
  return number;
4203
4292
  }
4204
- async function runAuthorization(wsfe, { data, voucherClass, amounts }, options, taxId, reservedNumber, replay = false) {
4293
+ async function runAuthorization(wsfe, { data, voucherClass, amounts }, options, taxId, reservedNumber, { lookupFirst = false, strangerAtNumber = false } = {}) {
4205
4294
  const auth = {
4206
4295
  representedTaxId: options.representedTaxId,
4207
4296
  forceRefresh: options.forceRefresh,
@@ -4231,7 +4320,7 @@ async function runAuthorization(wsfe, { data, voucherClass, amounts }, options,
4231
4320
  voucher,
4232
4321
  service: options.service
4233
4322
  };
4234
- if (replay) {
4323
+ if (lookupFirst) {
4235
4324
  const attempt2 = replayEvidence(options.service);
4236
4325
  let lookup;
4237
4326
  try {
@@ -4277,7 +4366,7 @@ async function runAuthorization(wsfe, { data, voucherClass, amounts }, options,
4277
4366
  recovery,
4278
4367
  options,
4279
4368
  includeRawResponse,
4280
- replay
4369
+ strangerAtNumber
4281
4370
  );
4282
4371
  }
4283
4372
  const uncertain = authorization.kind === "indeterminate" ? authorization : {
@@ -4298,9 +4387,9 @@ async function runAuthorization(wsfe, { data, voucherClass, amounts }, options,
4298
4387
  voucher
4299
4388
  });
4300
4389
  }
4301
- async function resolveRejection(authorization, recovery, options, includeRawResponse, replay) {
4390
+ async function resolveRejection(authorization, recovery, options, includeRawResponse, strangerAtNumber) {
4302
4391
  const issues = [...authorization.errors, ...authorization.observations];
4303
- const consult = options.idempotencyKey !== void 0 && (options.service === "wsmtxca" || issues.some((issue) => issue.code === "10016"));
4392
+ const consult = options.idempotencyKey !== void 0 && mayHoldNumber(issues, options.service);
4304
4393
  if (consult) {
4305
4394
  const recovered = await recoverInvoice({
4306
4395
  ...recovery,
@@ -4312,7 +4401,7 @@ async function resolveRejection(authorization, recovery, options, includeRawResp
4312
4401
  },
4313
4402
  includeRawResponse
4314
4403
  ),
4315
- strangerAtNumber: !replay
4404
+ strangerAtNumber
4316
4405
  });
4317
4406
  if (recovered.kind === "authorized" || recovered.kind === "conflict") {
4318
4407
  return recovered;
@@ -4326,6 +4415,9 @@ async function resolveRejection(authorization, recovery, options, includeRawResp
4326
4415
  ...recovery.includedRequest
4327
4416
  };
4328
4417
  }
4418
+ function mayHoldNumber(issues, service = "wsfe") {
4419
+ return service === "wsmtxca" || issues.some((issue) => issue.code === "10016");
4420
+ }
4329
4421
  async function recoverInvoice({
4330
4422
  wsfe,
4331
4423
  auth,
@@ -4376,7 +4468,7 @@ async function recoverInvoice({
4376
4468
  attempted,
4377
4469
  attempt,
4378
4470
  found: { ...toVoucherSummary(lookup.voucher), ...rawResponse },
4379
- reason: "ARCA refused the number this call reserved and another voucher occupies it",
4471
+ reason: "This key never wrote the number it reserved, and another voucher occupies it",
4380
4472
  ...includedRequest
4381
4473
  };
4382
4474
  }
@@ -4816,14 +4908,10 @@ async function recoverOperation(select, key, inputOptions, context) {
4816
4908
  );
4817
4909
  validateOptions(options);
4818
4910
  validateKeyStore({ ...options, idempotencyKey: key }, context);
4911
+ const scope = keyScope(context, key);
4912
+ const { store, environment, taxId } = scope;
4819
4913
  const json = await storeCall(
4820
- () => context.store.get(
4821
- attemptKey(
4822
- context.environment,
4823
- context.taxId,
4824
- key
4825
- )
4826
- )
4914
+ () => store.get(attemptKey(environment, taxId, key))
4827
4915
  );
4828
4916
  if (json === null) {
4829
4917
  throw new ArcaInputError("No reservation exists for this idempotency key", {
@@ -4832,44 +4920,40 @@ async function recoverOperation(select, key, inputOptions, context) {
4832
4920
  });
4833
4921
  }
4834
4922
  const record = readRecord(json);
4835
- const store = context.store;
4836
- const settled = settledKey(
4837
- context.environment,
4838
- context.taxId,
4839
- key
4840
- );
4841
- if (options.representedTaxId !== void 0 && String(options.representedTaxId) !== (record.representedTaxId ?? context?.taxId)) {
4923
+ if (options.representedTaxId !== void 0 && String(options.representedTaxId) !== (record.representedTaxId ?? taxId)) {
4842
4924
  throw new ArcaInputError(
4843
4925
  "Reservation belongs to another represented taxpayer",
4844
4926
  { code: "ARCA_INPUT_IDEMPOTENCY_MISMATCH" }
4845
4927
  );
4846
4928
  }
4847
- const recorded = await storeCall(() => store.get(settled));
4848
- if (recorded !== null) {
4849
- return await settledOutcome(
4850
- select,
4851
- record,
4852
- readSettledRecord(recorded),
4853
- options,
4854
- context.taxId,
4855
- (owner, other) => storeCall(
4856
- () => store.get(
4857
- settledKey(context.environment, owner, other)
4858
- )
4859
- )
4860
- );
4861
- }
4862
- return await recordConflict(
4863
- store,
4864
- settled,
4865
- await consultReservation(
4866
- select,
4867
- record,
4868
- options,
4869
- context.taxId
4870
- )
4929
+ return await consultKey(
4930
+ scope,
4931
+ record,
4932
+ false,
4933
+ select,
4934
+ options,
4935
+ async (current) => {
4936
+ const rejected = current.rejectedAt !== void 0;
4937
+ return await recordConflict(
4938
+ store,
4939
+ settledKey(environment, taxId, key),
4940
+ await consultReservation(select, current, options, taxId, rejected),
4941
+ !rejected || store.withLock !== void 0
4942
+ );
4943
+ }
4871
4944
  );
4872
4945
  }
4946
+ function keyScope(context, idempotencyKey) {
4947
+ if (!context?.store) {
4948
+ throw new ArcaConfigurationError("idempotencyKey requires a store.");
4949
+ }
4950
+ return {
4951
+ store: context.store,
4952
+ environment: context.environment,
4953
+ taxId: context.taxId,
4954
+ idempotencyKey
4955
+ };
4956
+ }
4873
4957
  function consultReservation(select, record, options, taxId, strangerAtNumber = false) {
4874
4958
  const storedOptions = {
4875
4959
  ...options,
@@ -4995,7 +5079,6 @@ async function runSequenceBarrier({
4995
5079
  taxId,
4996
5080
  sequence,
4997
5081
  sequenceTaxId,
4998
- coordinates,
4999
5082
  select,
5000
5083
  options,
5001
5084
  supersededBy,
@@ -5021,13 +5104,15 @@ async function runSequenceBarrier({
5021
5104
  return {};
5022
5105
  }
5023
5106
  const record = readRecord(reservation);
5107
+ if (record.rejectedAt !== void 0) {
5108
+ return {};
5109
+ }
5024
5110
  const blocked = {
5025
- blocked: {
5026
- kind: "indeterminate",
5027
- attempted: { ...coordinates, number: record.number },
5028
- attempt: replayEvidence(options.service),
5029
- lookup: { kind: "blocked", by: claimed.key, byTaxId: owner }
5030
- }
5111
+ blocked: withheld(
5112
+ record,
5113
+ { kind: "blocked", by: claimed.key, byTaxId: owner },
5114
+ options
5115
+ )
5031
5116
  };
5032
5117
  const outcome = await recordConflict(
5033
5118
  store,
@@ -5054,6 +5139,9 @@ async function runSequenceBarrier({
5054
5139
  if (outcome.kind !== "indeterminate" || outcome.lookup.kind !== "not_found") {
5055
5140
  return blocked;
5056
5141
  }
5142
+ if (options.number !== void 0 && options.number !== record.number) {
5143
+ return blocked;
5144
+ }
5057
5145
  const next = await readNext();
5058
5146
  if (next !== record.number) {
5059
5147
  return blocked;
@@ -5608,4 +5696,4 @@ export {
5608
5696
  withLease,
5609
5697
  createFileStore
5610
5698
  };
5611
- //# sourceMappingURL=chunk-5CUMVSJY.mjs.map
5699
+ //# sourceMappingURL=chunk-KBEV7QTU.mjs.map