facturas 0.25.1 → 0.25.2

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.
@@ -5829,7 +5829,7 @@ function resolveReceiverCondition(original, input) {
5829
5829
  function prepareOneCreditNote(original, input, now, kind) {
5830
5830
  assertOriginalExtensions(original);
5831
5831
  const family = voucherFamily(original.voucherType ?? 0);
5832
- if (family.types[2] === original.voucherType) {
5832
+ if (family.types[2] === original.voucherType && !acceptsCreditNoteOriginal(original.voucherType, kind)) {
5833
5833
  invalid5("original must be an invoice or debit note");
5834
5834
  }
5835
5835
  const note = {
@@ -5931,7 +5931,7 @@ function assertNoteReceiver(to) {
5931
5931
  invalid5("to.condition must be a supported receiver condition");
5932
5932
  }
5933
5933
  }
5934
- function assertCreditNoteInput(input) {
5934
+ function assertCreditNoteInput(input, kind = "creditNote") {
5935
5935
  assertIssueObject(input, "input");
5936
5936
  validateIssuanceFields(input);
5937
5937
  if ("associatedPeriod" in input) {
@@ -5945,7 +5945,7 @@ function assertCreditNoteInput(input) {
5945
5945
  );
5946
5946
  }
5947
5947
  assertIssueKeys(input, CREDIT_NOTE_KEYS, "input", "issueCreditNote()");
5948
- const target = assertCreditNoteTargets(input.for);
5948
+ const target = assertCreditNoteTargets(input.for, kind);
5949
5949
  if (input.salesPoint !== void 0) {
5950
5950
  assertCreditNoteBound(input.salesPoint, 99999, "salesPoint");
5951
5951
  }
@@ -5991,7 +5991,7 @@ function assertCreditNoteInput(input) {
5991
5991
  ...input.total === void 0 ? {} : { total: input.total }
5992
5992
  };
5993
5993
  }
5994
- function assertCreditNoteTargets(value) {
5994
+ function assertCreditNoteTargets(value, kind) {
5995
5995
  if (Array.isArray(value)) {
5996
5996
  if (value.length === 0) {
5997
5997
  throw new ArcaInputError(
@@ -6004,7 +6004,7 @@ function assertCreditNoteTargets(value) {
6004
6004
  );
6005
6005
  }
6006
6006
  const targets = value.map(
6007
- (target, index) => assertCreditNoteTarget(target, `for[${index}]`)
6007
+ (target, index) => assertCreditNoteTarget(target, `for[${index}]`, kind)
6008
6008
  );
6009
6009
  const seen = /* @__PURE__ */ new Set();
6010
6010
  for (const [index, target] of targets.entries()) {
@@ -6023,9 +6023,12 @@ function assertCreditNoteTargets(value) {
6023
6023
  }
6024
6024
  return targets;
6025
6025
  }
6026
- return assertCreditNoteTarget(value, "for");
6026
+ return assertCreditNoteTarget(value, "for", kind);
6027
6027
  }
6028
- function assertCreditNoteTarget(value, path) {
6028
+ function acceptsCreditNoteOriginal(voucherType, kind) {
6029
+ return kind === "debitNote" && [3, 8, 13].includes(voucherType);
6030
+ }
6031
+ function assertCreditNoteTarget(value, path, kind) {
6029
6032
  if (value === null || typeof value !== "object" || Array.isArray(value)) {
6030
6033
  throw new ArcaInputError(
6031
6034
  "issueCreditNote requires for: the coordinates of the authorized invoice the note corrects.",
@@ -6045,15 +6048,15 @@ function assertCreditNoteTarget(value, path) {
6045
6048
  for (const [field, max] of TARGET_BOUNDS) {
6046
6049
  assertCreditNoteBound(value[field], max, `${path}.${field}`);
6047
6050
  }
6048
- if (![1, 2, 6, 7, 11, 12, 51, 52, 201, 202, 206, 207, 211, 212].includes(
6051
+ if (!([1, 2, 6, 7, 11, 12, 51, 52, 201, 202, 206, 207, 211, 212].includes(
6049
6052
  value.voucherType
6050
- )) {
6053
+ ) || acceptsCreditNoteOriginal(value.voucherType, kind))) {
6051
6054
  throw new ArcaInputError(
6052
- "issueCreditNote requires an authorized invoice or debit note in a supported family in for.voucherType.",
6055
+ `${kind === "debitNote" ? "issueDebitNote" : "issueCreditNote"} requires an authorized original in a supported family in for.voucherType.`,
6053
6056
  {
6054
6057
  code: "ARCA_INPUT_INVALID_VALUE",
6055
6058
  field: `input.${path}.voucherType`,
6056
- expected: "1, 6 or 11"
6059
+ expected: kind === "debitNote" ? "a supported invoice or debit note, or an ordinary credit note (3, 8, 13)" : "a supported invoice or debit note"
6057
6060
  }
6058
6061
  );
6059
6062
  }
@@ -7283,7 +7286,7 @@ async function issueCreditNote(wsfe, input, inputOptions, context, kind = "credi
7283
7286
  validateOptions(options);
7284
7287
  validateKeyStore(options, context);
7285
7288
  assertIssueObject(input, "input");
7286
- const note = "associatedPeriod" in input && !("for" in input) ? structuredClone(input) : assertCreditNoteInput(input);
7289
+ const note = "associatedPeriod" in input && !("for" in input) ? structuredClone(input) : assertCreditNoteInput(input, kind);
7287
7290
  if (kind === "debitNote" && "all" in note && note.all) {
7288
7291
  throw new ArcaInputError("Debit notes require explicit items", {
7289
7292
  code: "ARCA_INPUT_INVALID_VALUE",
@@ -7322,7 +7325,7 @@ async function prepareNote(wsfe, input, options, context, kind) {
7322
7325
  if ("associatedPeriod" in input && !("for" in input)) {
7323
7326
  return preparePeriodNote(input, options, kind);
7324
7327
  }
7325
- const note = assertCreditNoteInput(input);
7328
+ const note = assertCreditNoteInput(input, kind);
7326
7329
  if (kind === "debitNote" && note.all) {
7327
7330
  throw new ArcaInputError("Debit notes require explicit items", {
7328
7331
  code: "ARCA_INPUT_INVALID_VALUE"
@@ -7365,6 +7368,16 @@ function validateNoteService(targets, options) {
7365
7368
  return;
7366
7369
  }
7367
7370
  for (const target of targets) {
7371
+ if ([3, 8, 13].includes(target.voucherType)) {
7372
+ throw new ArcaInputError(
7373
+ "WSMTXCA notes require an invoice or debit note original.",
7374
+ {
7375
+ code: "ARCA_INPUT_INVALID_VALUE",
7376
+ field: "input.for.voucherType",
7377
+ expected: "a supported invoice or debit note"
7378
+ }
7379
+ );
7380
+ }
7368
7381
  assertWsmtxcaVoucherType(target.voucherType);
7369
7382
  }
7370
7383
  }
@@ -8331,4 +8344,4 @@ export {
8331
8344
  createArcaClient,
8332
8345
  createFileStore
8333
8346
  };
8334
- //# sourceMappingURL=chunk-EL7OXUFE.mjs.map
8347
+ //# sourceMappingURL=chunk-NZ6KEUSM.mjs.map