@lucianpacurar/iso20022.js 0.2.12 → 0.2.13

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.d.ts CHANGED
@@ -889,6 +889,8 @@ interface SEPAMultiCreditPaymentInstructionGroup {
889
889
  payments: AtLeastOne$4<SEPACreditPaymentInstruction>;
890
890
  /** Optional category purpose code for this payment information block. */
891
891
  categoryPurpose?: ExternalCategoryPurpose;
892
+ /** Indicates whether transactions should be booked in batch. Defaults to false. */
893
+ batchBooking?: boolean;
892
894
  }
893
895
  /**
894
896
  * Configuration for SEPA Multi Credit Payment Initiation.
@@ -938,7 +940,6 @@ declare class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
938
940
  messageId: string;
939
941
  creationDate: Date;
940
942
  paymentInstructions: AtLeastOne$4<SEPAMultiCreditPaymentInstructionGroup>;
941
- paymentInformationIdBase: string;
942
943
  private formattedPaymentSum;
943
944
  private totalTransactionCount;
944
945
  /**
@@ -1382,7 +1383,6 @@ declare class SEPADirectDebitPaymentInitiation extends PaymentInitiation {
1382
1383
  messageId: string;
1383
1384
  creationDate: Date;
1384
1385
  paymentInstructions: AtLeastOne$1<SEPADirectDebitPaymentInstructionGroup>;
1385
- paymentInformationIdBase: string;
1386
1386
  private formattedPaymentSum;
1387
1387
  private totalTransactionCount;
1388
1388
  /**
package/dist/index.js CHANGED
@@ -2063,59 +2063,6 @@ var fxp = {
2063
2063
  XMLBuilder: XMLBuilder
2064
2064
  };
2065
2065
 
2066
- /**
2067
- * Convert array of 16 byte values to UUID string format of the form:
2068
- * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
2069
- */
2070
- var byteToHex = [];
2071
- for (var i = 0; i < 256; ++i) {
2072
- byteToHex.push((i + 0x100).toString(16).slice(1));
2073
- }
2074
- function unsafeStringify(arr, offset = 0) {
2075
- // Note: Be careful editing this code! It's been tuned for performance
2076
- // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
2077
- //
2078
- // Note to future-self: No, you can't remove the `toLowerCase()` call.
2079
- // REF: https://github.com/uuidjs/uuid/pull/677#issuecomment-1757351351
2080
- return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
2081
- }
2082
-
2083
- // Unique ID creation requires a high quality random # generator. In the browser we therefore
2084
- // require the crypto API and do not support built-in fallback to lower quality random number
2085
- // generators (like Math.random()).
2086
-
2087
- var getRandomValues;
2088
- var rnds8 = new Uint8Array(16);
2089
- function rng() {
2090
- // lazy load so that environments that need to polyfill have a chance to do so
2091
- if (!getRandomValues) {
2092
- // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
2093
- getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
2094
- if (!getRandomValues) {
2095
- throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
2096
- }
2097
- }
2098
- return getRandomValues(rnds8);
2099
- }
2100
-
2101
- var randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
2102
- var native = {
2103
- randomUUID
2104
- };
2105
-
2106
- function v4(options, buf, offset) {
2107
- if (native.randomUUID && !buf && !options) {
2108
- return native.randomUUID();
2109
- }
2110
- options = options || {};
2111
- var rnds = options.random || (options.rng || rng)();
2112
-
2113
- // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
2114
- rnds[6] = rnds[6] & 0x0f | 0x40;
2115
- rnds[8] = rnds[8] & 0x3f | 0x80;
2116
- return unsafeStringify(rnds);
2117
- }
2118
-
2119
2066
  /**
2120
2067
  * Base error class for all ISO 20022 related errors in the library.
2121
2068
  * Extends the native Error class with proper stack trace capture.
@@ -7278,9 +7225,65 @@ const exportMessageHeader = (header) => {
7278
7225
  return obj;
7279
7226
  };
7280
7227
 
7228
+ /**
7229
+ * Convert array of 16 byte values to UUID string format of the form:
7230
+ * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
7231
+ */
7232
+ var byteToHex = [];
7233
+ for (var i = 0; i < 256; ++i) {
7234
+ byteToHex.push((i + 0x100).toString(16).slice(1));
7235
+ }
7236
+ function unsafeStringify(arr, offset = 0) {
7237
+ // Note: Be careful editing this code! It's been tuned for performance
7238
+ // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
7239
+ //
7240
+ // Note to future-self: No, you can't remove the `toLowerCase()` call.
7241
+ // REF: https://github.com/uuidjs/uuid/pull/677#issuecomment-1757351351
7242
+ return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
7243
+ }
7244
+
7245
+ // Unique ID creation requires a high quality random # generator. In the browser we therefore
7246
+ // require the crypto API and do not support built-in fallback to lower quality random number
7247
+ // generators (like Math.random()).
7248
+
7249
+ var getRandomValues;
7250
+ var rnds8 = new Uint8Array(16);
7251
+ function rng() {
7252
+ // lazy load so that environments that need to polyfill have a chance to do so
7253
+ if (!getRandomValues) {
7254
+ // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
7255
+ getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
7256
+ if (!getRandomValues) {
7257
+ throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
7258
+ }
7259
+ }
7260
+ return getRandomValues(rnds8);
7261
+ }
7262
+
7263
+ var randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
7264
+ var native = {
7265
+ randomUUID
7266
+ };
7267
+
7268
+ function v4(options, buf, offset) {
7269
+ if (native.randomUUID && !buf && !options) {
7270
+ return native.randomUUID();
7271
+ }
7272
+ options = options || {};
7273
+ var rnds = options.random || (options.rng || rng)();
7274
+
7275
+ // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
7276
+ rnds[6] = rnds[6] & 0x0f | 0x40;
7277
+ rnds[8] = rnds[8] & 0x3f | 0x80;
7278
+ return unsafeStringify(rnds);
7279
+ }
7280
+
7281
7281
  const sanitize = (value, length) => {
7282
7282
  return value.slice(0, length);
7283
7283
  };
7284
+ const generateId = () => {
7285
+ return v4().replace(/-/g, '');
7286
+ };
7284
7287
 
7285
7288
  /**
7286
7289
  * Abstract base class for ISO20022 payment initiation (PAIN) messages.
@@ -7446,10 +7449,9 @@ class SWIFTCreditPaymentInitiation extends PaymentInitiation {
7446
7449
  super({ type: 'swift' });
7447
7450
  this.initiatingParty = config.initiatingParty;
7448
7451
  this.paymentInstructions = config.paymentInstructions;
7449
- this.messageId =
7450
- config.messageId || v4().replace(/-/g, '').substring(0, 35);
7452
+ this.messageId = config.messageId || generateId();
7451
7453
  this.creationDate = config.creationDate || new Date();
7452
- this.paymentInformationId = sanitize(v4(), 35);
7454
+ this.paymentInformationId = generateId();
7453
7455
  this.validate();
7454
7456
  }
7455
7457
  /**
@@ -7479,7 +7481,7 @@ class SWIFTCreditPaymentInitiation extends PaymentInitiation {
7479
7481
  * @returns {Object} The credit transfer object.
7480
7482
  */
7481
7483
  creditTransfer(paymentInstruction) {
7482
- const paymentInstructionId = sanitize(paymentInstruction.id || v4(), 35);
7484
+ const paymentInstructionId = sanitize(paymentInstruction.id || generateId(), 35);
7483
7485
  const amount = Dinero({
7484
7486
  amount: paymentInstruction.amount,
7485
7487
  currency: paymentInstruction.currency,
@@ -7665,10 +7667,10 @@ class SEPACreditPaymentInitiation extends PaymentInitiation {
7665
7667
  super({ type: 'sepa' });
7666
7668
  this.initiatingParty = config.initiatingParty;
7667
7669
  this.paymentInstructions = config.paymentInstructions;
7668
- this.messageId = config.messageId || v4().replace(/-/g, '');
7670
+ this.messageId = config.messageId || generateId();
7669
7671
  this.creationDate = config.creationDate || new Date();
7670
7672
  this.formattedPaymentSum = this.sumPaymentInstructions(this.paymentInstructions);
7671
- this.paymentInformationId = sanitize(v4(), 35);
7673
+ this.paymentInformationId = generateId();
7672
7674
  this.categoryPurpose = config.categoryPurpose;
7673
7675
  this.validate();
7674
7676
  }
@@ -7718,8 +7720,8 @@ class SEPACreditPaymentInitiation extends PaymentInitiation {
7718
7720
  * @returns {Object} The payment information object formatted according to SEPA specifications.
7719
7721
  */
7720
7722
  creditTransfer(instruction) {
7721
- const paymentInstructionId = sanitize(instruction.id || v4(), 35);
7722
- const endToEndId = sanitize(instruction.endToEndId || instruction.id || v4(), 35);
7723
+ const paymentInstructionId = sanitize(instruction.id || generateId(), 35);
7724
+ const endToEndId = sanitize(instruction.endToEndId || instruction.id || generateId(), 35);
7723
7725
  const dinero = Dinero({
7724
7726
  amount: instruction.amount,
7725
7727
  currency: instruction.currency,
@@ -7928,7 +7930,6 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
7928
7930
  messageId;
7929
7931
  creationDate;
7930
7932
  paymentInstructions;
7931
- paymentInformationIdBase;
7932
7933
  formattedPaymentSum;
7933
7934
  totalTransactionCount;
7934
7935
  /**
@@ -7939,9 +7940,8 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
7939
7940
  super({ type: 'sepa' });
7940
7941
  this.initiatingParty = config.initiatingParty;
7941
7942
  this.paymentInstructions = config.paymentInstructions;
7942
- this.messageId = config.messageId || v4().replace(/-/g, '');
7943
+ this.messageId = config.messageId || generateId();
7943
7944
  this.creationDate = config.creationDate || new Date();
7944
- this.paymentInformationIdBase = sanitize(v4(), 35);
7945
7945
  this.totalTransactionCount = this.countAllTransactions();
7946
7946
  this.formattedPaymentSum = this.sumAllPayments();
7947
7947
  this.validate();
@@ -8011,8 +8011,8 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
8011
8011
  * @returns {Object} The payment information object formatted according to SEPA specifications.
8012
8012
  */
8013
8013
  creditTransfer(instruction) {
8014
- const paymentInstructionId = sanitize(instruction.id || v4(), 35);
8015
- const endToEndId = sanitize(instruction.endToEndId || instruction.id || v4(), 35);
8014
+ const paymentInstructionId = sanitize(instruction.id || generateId(), 35);
8015
+ const endToEndId = sanitize(instruction.endToEndId || instruction.id || generateId(), 35);
8016
8016
  const dinero = Dinero({
8017
8017
  amount: instruction.amount,
8018
8018
  currency: instruction.currency,
@@ -8050,17 +8050,19 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
8050
8050
  serialize() {
8051
8051
  const builder = PaymentInitiation.getBuilder();
8052
8052
  // Generate one PmtInf entry per individual payment
8053
- const paymentInfoEntries = this.paymentInstructions.flatMap((group, groupIndex) => {
8054
- return group.payments.map((payment, paymentIndex) => {
8053
+ const paymentInfoEntries = this.paymentInstructions.flatMap((group) => {
8054
+ return group.payments.map((payment) => {
8055
8055
  const dinero = Dinero({
8056
8056
  amount: payment.amount,
8057
8057
  currency: payment.currency,
8058
8058
  });
8059
- const pmtInfId = sanitize(`${this.paymentInformationIdBase}-${groupIndex + 1}-${paymentIndex + 1}`, 35);
8059
+ const pmtInfId = generateId();
8060
8060
  const requestedExecutionDate = payment.requestedPaymentExecutionDate || new Date();
8061
+ const batchBooking = group.batchBooking !== undefined ? group.batchBooking : false;
8061
8062
  return {
8062
8063
  PmtInfId: pmtInfId,
8063
8064
  PmtMtd: 'TRF',
8065
+ BtchBookg: batchBooking,
8064
8066
  NbOfTxs: '1',
8065
8067
  CtrlSum: dinero.toFormat('0.00'),
8066
8068
  PmtTpInf: {
@@ -8223,10 +8225,13 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
8223
8225
  }),
8224
8226
  };
8225
8227
  });
8228
+ // Extract batch booking
8229
+ const batchBooking = pmtInf.BtchBookg === 'true' || pmtInf.BtchBookg === true;
8226
8230
  return {
8227
8231
  initiatingParty: groupInitiatingParty,
8228
8232
  payments: payments,
8229
8233
  ...(categoryPurpose && { categoryPurpose }),
8234
+ batchBooking: batchBooking,
8230
8235
  };
8231
8236
  });
8232
8237
  // Return new instance
@@ -8271,9 +8276,9 @@ class RTPCreditPaymentInitiation extends PaymentInitiation {
8271
8276
  super({ type: 'rtp' });
8272
8277
  this.initiatingParty = config.initiatingParty;
8273
8278
  this.paymentInstructions = config.paymentInstructions;
8274
- this.messageId = config.messageId || v4().replace(/-/g, '');
8279
+ this.messageId = config.messageId || generateId();
8275
8280
  this.creationDate = config.creationDate || new Date();
8276
- this.paymentInformationId = sanitize(v4(), 35);
8281
+ this.paymentInformationId = generateId();
8277
8282
  this.formattedPaymentSum = this.sumPaymentInstructions(this.paymentInstructions);
8278
8283
  this.validate();
8279
8284
  }
@@ -8310,8 +8315,8 @@ class RTPCreditPaymentInitiation extends PaymentInitiation {
8310
8315
  * @returns {Object} The payment information object formatted according to SEPA specifications.
8311
8316
  */
8312
8317
  creditTransfer(instruction) {
8313
- const paymentInstructionId = sanitize(instruction.id || v4(), 35);
8314
- const endToEndId = sanitize(instruction.endToEndId || instruction.id || v4(), 35);
8318
+ const paymentInstructionId = sanitize(instruction.id || generateId(), 35);
8319
+ const endToEndId = sanitize(instruction.endToEndId || instruction.id || generateId(), 35);
8315
8320
  const dinero = Dinero({
8316
8321
  amount: instruction.amount,
8317
8322
  currency: instruction.currency,
@@ -8586,9 +8591,9 @@ class ACHCreditPaymentInitiation extends PaymentInitiation {
8586
8591
  super({ type: 'ach' });
8587
8592
  this.initiatingParty = config.initiatingParty;
8588
8593
  this.paymentInstructions = config.paymentInstructions;
8589
- this.messageId = config.messageId || v4().replace(/-/g, '');
8594
+ this.messageId = config.messageId || generateId();
8590
8595
  this.creationDate = config.creationDate || new Date();
8591
- this.paymentInformationId = sanitize(v4(), 35);
8596
+ this.paymentInformationId = generateId();
8592
8597
  this.localInstrument =
8593
8598
  config.localInstrument || ACHLocalInstrumentCode.CorporateCreditDebit;
8594
8599
  this.serviceLevel = 'NURG'; // Normal Urgency
@@ -8635,8 +8640,8 @@ class ACHCreditPaymentInitiation extends PaymentInitiation {
8635
8640
  * @returns {Object} The payment information object formatted according to ACH specifications.
8636
8641
  */
8637
8642
  creditTransfer(instruction) {
8638
- const paymentInstructionId = sanitize(instruction.id || v4(), 35);
8639
- const endToEndId = sanitize(instruction.endToEndId || instruction.id || v4(), 35);
8643
+ const paymentInstructionId = sanitize(instruction.id || generateId(), 35);
8644
+ const endToEndId = sanitize(instruction.endToEndId || instruction.id || generateId(), 35);
8640
8645
  const dinero = Dinero({
8641
8646
  amount: instruction.amount,
8642
8647
  currency: instruction.currency,
@@ -8859,7 +8864,6 @@ class SEPADirectDebitPaymentInitiation extends PaymentInitiation {
8859
8864
  messageId;
8860
8865
  creationDate;
8861
8866
  paymentInstructions;
8862
- paymentInformationIdBase;
8863
8867
  formattedPaymentSum;
8864
8868
  totalTransactionCount;
8865
8869
  /**
@@ -8870,9 +8874,8 @@ class SEPADirectDebitPaymentInitiation extends PaymentInitiation {
8870
8874
  super({ type: 'sepa' });
8871
8875
  this.initiatingParty = config.initiatingParty;
8872
8876
  this.paymentInstructions = config.paymentInstructions;
8873
- this.messageId = config.messageId || v4().replace(/-/g, '');
8877
+ this.messageId = config.messageId || generateId();
8874
8878
  this.creationDate = config.creationDate || new Date();
8875
- this.paymentInformationIdBase = sanitize(v4(), 35);
8876
8879
  this.totalTransactionCount = this.countAllTransactions();
8877
8880
  this.formattedPaymentSum = this.sumAllPayments();
8878
8881
  this.validate();
@@ -8942,7 +8945,7 @@ class SEPADirectDebitPaymentInitiation extends PaymentInitiation {
8942
8945
  * @returns {Object} The payment information object formatted according to SEPA direct debit specifications.
8943
8946
  */
8944
8947
  directDebitTransfer(instruction) {
8945
- const endToEndId = sanitize(instruction.endToEndId || instruction.id || v4(), 35);
8948
+ const endToEndId = sanitize(instruction.endToEndId || instruction.id || generateId(), 35);
8946
8949
  const dinero = Dinero({
8947
8950
  amount: instruction.amount,
8948
8951
  currency: instruction.currency,
@@ -9012,8 +9015,8 @@ class SEPADirectDebitPaymentInitiation extends PaymentInitiation {
9012
9015
  serialize() {
9013
9016
  const builder = PaymentInitiation.getBuilder();
9014
9017
  // Generate one PmtInf entry per creditor group
9015
- const paymentInfoEntries = this.paymentInstructions.map((group, groupIndex) => {
9016
- const pmtInfId = sanitize(`${this.paymentInformationIdBase}-${groupIndex + 1}`, 35);
9018
+ const paymentInfoEntries = this.paymentInstructions.map((group) => {
9019
+ const pmtInfId = generateId();
9017
9020
  const localInstrument = group.localInstrument || 'CORE';
9018
9021
  const batchBooking = group.batchBooking !== undefined ? group.batchBooking : false;
9019
9022
  // Calculate sum for this group
package/dist/index.mjs CHANGED
@@ -2061,59 +2061,6 @@ var fxp = {
2061
2061
  XMLBuilder: XMLBuilder
2062
2062
  };
2063
2063
 
2064
- /**
2065
- * Convert array of 16 byte values to UUID string format of the form:
2066
- * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
2067
- */
2068
- var byteToHex = [];
2069
- for (var i = 0; i < 256; ++i) {
2070
- byteToHex.push((i + 0x100).toString(16).slice(1));
2071
- }
2072
- function unsafeStringify(arr, offset = 0) {
2073
- // Note: Be careful editing this code! It's been tuned for performance
2074
- // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
2075
- //
2076
- // Note to future-self: No, you can't remove the `toLowerCase()` call.
2077
- // REF: https://github.com/uuidjs/uuid/pull/677#issuecomment-1757351351
2078
- return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
2079
- }
2080
-
2081
- // Unique ID creation requires a high quality random # generator. In the browser we therefore
2082
- // require the crypto API and do not support built-in fallback to lower quality random number
2083
- // generators (like Math.random()).
2084
-
2085
- var getRandomValues;
2086
- var rnds8 = new Uint8Array(16);
2087
- function rng() {
2088
- // lazy load so that environments that need to polyfill have a chance to do so
2089
- if (!getRandomValues) {
2090
- // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
2091
- getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
2092
- if (!getRandomValues) {
2093
- throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
2094
- }
2095
- }
2096
- return getRandomValues(rnds8);
2097
- }
2098
-
2099
- var randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
2100
- var native = {
2101
- randomUUID
2102
- };
2103
-
2104
- function v4(options, buf, offset) {
2105
- if (native.randomUUID && !buf && !options) {
2106
- return native.randomUUID();
2107
- }
2108
- options = options || {};
2109
- var rnds = options.random || (options.rng || rng)();
2110
-
2111
- // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
2112
- rnds[6] = rnds[6] & 0x0f | 0x40;
2113
- rnds[8] = rnds[8] & 0x3f | 0x80;
2114
- return unsafeStringify(rnds);
2115
- }
2116
-
2117
2064
  /**
2118
2065
  * Base error class for all ISO 20022 related errors in the library.
2119
2066
  * Extends the native Error class with proper stack trace capture.
@@ -7276,9 +7223,65 @@ const exportMessageHeader = (header) => {
7276
7223
  return obj;
7277
7224
  };
7278
7225
 
7226
+ /**
7227
+ * Convert array of 16 byte values to UUID string format of the form:
7228
+ * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
7229
+ */
7230
+ var byteToHex = [];
7231
+ for (var i = 0; i < 256; ++i) {
7232
+ byteToHex.push((i + 0x100).toString(16).slice(1));
7233
+ }
7234
+ function unsafeStringify(arr, offset = 0) {
7235
+ // Note: Be careful editing this code! It's been tuned for performance
7236
+ // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
7237
+ //
7238
+ // Note to future-self: No, you can't remove the `toLowerCase()` call.
7239
+ // REF: https://github.com/uuidjs/uuid/pull/677#issuecomment-1757351351
7240
+ return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
7241
+ }
7242
+
7243
+ // Unique ID creation requires a high quality random # generator. In the browser we therefore
7244
+ // require the crypto API and do not support built-in fallback to lower quality random number
7245
+ // generators (like Math.random()).
7246
+
7247
+ var getRandomValues;
7248
+ var rnds8 = new Uint8Array(16);
7249
+ function rng() {
7250
+ // lazy load so that environments that need to polyfill have a chance to do so
7251
+ if (!getRandomValues) {
7252
+ // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
7253
+ getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
7254
+ if (!getRandomValues) {
7255
+ throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
7256
+ }
7257
+ }
7258
+ return getRandomValues(rnds8);
7259
+ }
7260
+
7261
+ var randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
7262
+ var native = {
7263
+ randomUUID
7264
+ };
7265
+
7266
+ function v4(options, buf, offset) {
7267
+ if (native.randomUUID && !buf && !options) {
7268
+ return native.randomUUID();
7269
+ }
7270
+ options = options || {};
7271
+ var rnds = options.random || (options.rng || rng)();
7272
+
7273
+ // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
7274
+ rnds[6] = rnds[6] & 0x0f | 0x40;
7275
+ rnds[8] = rnds[8] & 0x3f | 0x80;
7276
+ return unsafeStringify(rnds);
7277
+ }
7278
+
7279
7279
  const sanitize = (value, length) => {
7280
7280
  return value.slice(0, length);
7281
7281
  };
7282
+ const generateId = () => {
7283
+ return v4().replace(/-/g, '');
7284
+ };
7282
7285
 
7283
7286
  /**
7284
7287
  * Abstract base class for ISO20022 payment initiation (PAIN) messages.
@@ -7444,10 +7447,9 @@ class SWIFTCreditPaymentInitiation extends PaymentInitiation {
7444
7447
  super({ type: 'swift' });
7445
7448
  this.initiatingParty = config.initiatingParty;
7446
7449
  this.paymentInstructions = config.paymentInstructions;
7447
- this.messageId =
7448
- config.messageId || v4().replace(/-/g, '').substring(0, 35);
7450
+ this.messageId = config.messageId || generateId();
7449
7451
  this.creationDate = config.creationDate || new Date();
7450
- this.paymentInformationId = sanitize(v4(), 35);
7452
+ this.paymentInformationId = generateId();
7451
7453
  this.validate();
7452
7454
  }
7453
7455
  /**
@@ -7477,7 +7479,7 @@ class SWIFTCreditPaymentInitiation extends PaymentInitiation {
7477
7479
  * @returns {Object} The credit transfer object.
7478
7480
  */
7479
7481
  creditTransfer(paymentInstruction) {
7480
- const paymentInstructionId = sanitize(paymentInstruction.id || v4(), 35);
7482
+ const paymentInstructionId = sanitize(paymentInstruction.id || generateId(), 35);
7481
7483
  const amount = Dinero({
7482
7484
  amount: paymentInstruction.amount,
7483
7485
  currency: paymentInstruction.currency,
@@ -7663,10 +7665,10 @@ class SEPACreditPaymentInitiation extends PaymentInitiation {
7663
7665
  super({ type: 'sepa' });
7664
7666
  this.initiatingParty = config.initiatingParty;
7665
7667
  this.paymentInstructions = config.paymentInstructions;
7666
- this.messageId = config.messageId || v4().replace(/-/g, '');
7668
+ this.messageId = config.messageId || generateId();
7667
7669
  this.creationDate = config.creationDate || new Date();
7668
7670
  this.formattedPaymentSum = this.sumPaymentInstructions(this.paymentInstructions);
7669
- this.paymentInformationId = sanitize(v4(), 35);
7671
+ this.paymentInformationId = generateId();
7670
7672
  this.categoryPurpose = config.categoryPurpose;
7671
7673
  this.validate();
7672
7674
  }
@@ -7716,8 +7718,8 @@ class SEPACreditPaymentInitiation extends PaymentInitiation {
7716
7718
  * @returns {Object} The payment information object formatted according to SEPA specifications.
7717
7719
  */
7718
7720
  creditTransfer(instruction) {
7719
- const paymentInstructionId = sanitize(instruction.id || v4(), 35);
7720
- const endToEndId = sanitize(instruction.endToEndId || instruction.id || v4(), 35);
7721
+ const paymentInstructionId = sanitize(instruction.id || generateId(), 35);
7722
+ const endToEndId = sanitize(instruction.endToEndId || instruction.id || generateId(), 35);
7721
7723
  const dinero = Dinero({
7722
7724
  amount: instruction.amount,
7723
7725
  currency: instruction.currency,
@@ -7926,7 +7928,6 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
7926
7928
  messageId;
7927
7929
  creationDate;
7928
7930
  paymentInstructions;
7929
- paymentInformationIdBase;
7930
7931
  formattedPaymentSum;
7931
7932
  totalTransactionCount;
7932
7933
  /**
@@ -7937,9 +7938,8 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
7937
7938
  super({ type: 'sepa' });
7938
7939
  this.initiatingParty = config.initiatingParty;
7939
7940
  this.paymentInstructions = config.paymentInstructions;
7940
- this.messageId = config.messageId || v4().replace(/-/g, '');
7941
+ this.messageId = config.messageId || generateId();
7941
7942
  this.creationDate = config.creationDate || new Date();
7942
- this.paymentInformationIdBase = sanitize(v4(), 35);
7943
7943
  this.totalTransactionCount = this.countAllTransactions();
7944
7944
  this.formattedPaymentSum = this.sumAllPayments();
7945
7945
  this.validate();
@@ -8009,8 +8009,8 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
8009
8009
  * @returns {Object} The payment information object formatted according to SEPA specifications.
8010
8010
  */
8011
8011
  creditTransfer(instruction) {
8012
- const paymentInstructionId = sanitize(instruction.id || v4(), 35);
8013
- const endToEndId = sanitize(instruction.endToEndId || instruction.id || v4(), 35);
8012
+ const paymentInstructionId = sanitize(instruction.id || generateId(), 35);
8013
+ const endToEndId = sanitize(instruction.endToEndId || instruction.id || generateId(), 35);
8014
8014
  const dinero = Dinero({
8015
8015
  amount: instruction.amount,
8016
8016
  currency: instruction.currency,
@@ -8048,17 +8048,19 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
8048
8048
  serialize() {
8049
8049
  const builder = PaymentInitiation.getBuilder();
8050
8050
  // Generate one PmtInf entry per individual payment
8051
- const paymentInfoEntries = this.paymentInstructions.flatMap((group, groupIndex) => {
8052
- return group.payments.map((payment, paymentIndex) => {
8051
+ const paymentInfoEntries = this.paymentInstructions.flatMap((group) => {
8052
+ return group.payments.map((payment) => {
8053
8053
  const dinero = Dinero({
8054
8054
  amount: payment.amount,
8055
8055
  currency: payment.currency,
8056
8056
  });
8057
- const pmtInfId = sanitize(`${this.paymentInformationIdBase}-${groupIndex + 1}-${paymentIndex + 1}`, 35);
8057
+ const pmtInfId = generateId();
8058
8058
  const requestedExecutionDate = payment.requestedPaymentExecutionDate || new Date();
8059
+ const batchBooking = group.batchBooking !== undefined ? group.batchBooking : false;
8059
8060
  return {
8060
8061
  PmtInfId: pmtInfId,
8061
8062
  PmtMtd: 'TRF',
8063
+ BtchBookg: batchBooking,
8062
8064
  NbOfTxs: '1',
8063
8065
  CtrlSum: dinero.toFormat('0.00'),
8064
8066
  PmtTpInf: {
@@ -8221,10 +8223,13 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
8221
8223
  }),
8222
8224
  };
8223
8225
  });
8226
+ // Extract batch booking
8227
+ const batchBooking = pmtInf.BtchBookg === 'true' || pmtInf.BtchBookg === true;
8224
8228
  return {
8225
8229
  initiatingParty: groupInitiatingParty,
8226
8230
  payments: payments,
8227
8231
  ...(categoryPurpose && { categoryPurpose }),
8232
+ batchBooking: batchBooking,
8228
8233
  };
8229
8234
  });
8230
8235
  // Return new instance
@@ -8269,9 +8274,9 @@ class RTPCreditPaymentInitiation extends PaymentInitiation {
8269
8274
  super({ type: 'rtp' });
8270
8275
  this.initiatingParty = config.initiatingParty;
8271
8276
  this.paymentInstructions = config.paymentInstructions;
8272
- this.messageId = config.messageId || v4().replace(/-/g, '');
8277
+ this.messageId = config.messageId || generateId();
8273
8278
  this.creationDate = config.creationDate || new Date();
8274
- this.paymentInformationId = sanitize(v4(), 35);
8279
+ this.paymentInformationId = generateId();
8275
8280
  this.formattedPaymentSum = this.sumPaymentInstructions(this.paymentInstructions);
8276
8281
  this.validate();
8277
8282
  }
@@ -8308,8 +8313,8 @@ class RTPCreditPaymentInitiation extends PaymentInitiation {
8308
8313
  * @returns {Object} The payment information object formatted according to SEPA specifications.
8309
8314
  */
8310
8315
  creditTransfer(instruction) {
8311
- const paymentInstructionId = sanitize(instruction.id || v4(), 35);
8312
- const endToEndId = sanitize(instruction.endToEndId || instruction.id || v4(), 35);
8316
+ const paymentInstructionId = sanitize(instruction.id || generateId(), 35);
8317
+ const endToEndId = sanitize(instruction.endToEndId || instruction.id || generateId(), 35);
8313
8318
  const dinero = Dinero({
8314
8319
  amount: instruction.amount,
8315
8320
  currency: instruction.currency,
@@ -8584,9 +8589,9 @@ class ACHCreditPaymentInitiation extends PaymentInitiation {
8584
8589
  super({ type: 'ach' });
8585
8590
  this.initiatingParty = config.initiatingParty;
8586
8591
  this.paymentInstructions = config.paymentInstructions;
8587
- this.messageId = config.messageId || v4().replace(/-/g, '');
8592
+ this.messageId = config.messageId || generateId();
8588
8593
  this.creationDate = config.creationDate || new Date();
8589
- this.paymentInformationId = sanitize(v4(), 35);
8594
+ this.paymentInformationId = generateId();
8590
8595
  this.localInstrument =
8591
8596
  config.localInstrument || ACHLocalInstrumentCode.CorporateCreditDebit;
8592
8597
  this.serviceLevel = 'NURG'; // Normal Urgency
@@ -8633,8 +8638,8 @@ class ACHCreditPaymentInitiation extends PaymentInitiation {
8633
8638
  * @returns {Object} The payment information object formatted according to ACH specifications.
8634
8639
  */
8635
8640
  creditTransfer(instruction) {
8636
- const paymentInstructionId = sanitize(instruction.id || v4(), 35);
8637
- const endToEndId = sanitize(instruction.endToEndId || instruction.id || v4(), 35);
8641
+ const paymentInstructionId = sanitize(instruction.id || generateId(), 35);
8642
+ const endToEndId = sanitize(instruction.endToEndId || instruction.id || generateId(), 35);
8638
8643
  const dinero = Dinero({
8639
8644
  amount: instruction.amount,
8640
8645
  currency: instruction.currency,
@@ -8857,7 +8862,6 @@ class SEPADirectDebitPaymentInitiation extends PaymentInitiation {
8857
8862
  messageId;
8858
8863
  creationDate;
8859
8864
  paymentInstructions;
8860
- paymentInformationIdBase;
8861
8865
  formattedPaymentSum;
8862
8866
  totalTransactionCount;
8863
8867
  /**
@@ -8868,9 +8872,8 @@ class SEPADirectDebitPaymentInitiation extends PaymentInitiation {
8868
8872
  super({ type: 'sepa' });
8869
8873
  this.initiatingParty = config.initiatingParty;
8870
8874
  this.paymentInstructions = config.paymentInstructions;
8871
- this.messageId = config.messageId || v4().replace(/-/g, '');
8875
+ this.messageId = config.messageId || generateId();
8872
8876
  this.creationDate = config.creationDate || new Date();
8873
- this.paymentInformationIdBase = sanitize(v4(), 35);
8874
8877
  this.totalTransactionCount = this.countAllTransactions();
8875
8878
  this.formattedPaymentSum = this.sumAllPayments();
8876
8879
  this.validate();
@@ -8940,7 +8943,7 @@ class SEPADirectDebitPaymentInitiation extends PaymentInitiation {
8940
8943
  * @returns {Object} The payment information object formatted according to SEPA direct debit specifications.
8941
8944
  */
8942
8945
  directDebitTransfer(instruction) {
8943
- const endToEndId = sanitize(instruction.endToEndId || instruction.id || v4(), 35);
8946
+ const endToEndId = sanitize(instruction.endToEndId || instruction.id || generateId(), 35);
8944
8947
  const dinero = Dinero({
8945
8948
  amount: instruction.amount,
8946
8949
  currency: instruction.currency,
@@ -9010,8 +9013,8 @@ class SEPADirectDebitPaymentInitiation extends PaymentInitiation {
9010
9013
  serialize() {
9011
9014
  const builder = PaymentInitiation.getBuilder();
9012
9015
  // Generate one PmtInf entry per creditor group
9013
- const paymentInfoEntries = this.paymentInstructions.map((group, groupIndex) => {
9014
- const pmtInfId = sanitize(`${this.paymentInformationIdBase}-${groupIndex + 1}`, 35);
9016
+ const paymentInfoEntries = this.paymentInstructions.map((group) => {
9017
+ const pmtInfId = generateId();
9015
9018
  const localInstrument = group.localInstrument || 'CORE';
9016
9019
  const batchBooking = group.batchBooking !== undefined ? group.batchBooking : false;
9017
9020
  // Calculate sum for this group
@@ -15,6 +15,8 @@ export interface SEPAMultiCreditPaymentInstructionGroup {
15
15
  payments: AtLeastOne<SEPACreditPaymentInstruction>;
16
16
  /** Optional category purpose code for this payment information block. */
17
17
  categoryPurpose?: ExternalCategoryPurpose;
18
+ /** Indicates whether transactions should be booked in batch. Defaults to false. */
19
+ batchBooking?: boolean;
18
20
  }
19
21
  /**
20
22
  * Configuration for SEPA Multi Credit Payment Initiation.
@@ -64,7 +66,6 @@ export declare class SEPAMultiCreditPaymentInitiation extends PaymentInitiation
64
66
  messageId: string;
65
67
  creationDate: Date;
66
68
  paymentInstructions: AtLeastOne<SEPAMultiCreditPaymentInstructionGroup>;
67
- paymentInformationIdBase: string;
68
69
  private formattedPaymentSum;
69
70
  private totalTransactionCount;
70
71
  /**
@@ -78,7 +78,6 @@ export declare class SEPADirectDebitPaymentInitiation extends PaymentInitiation
78
78
  messageId: string;
79
79
  creationDate: Date;
80
80
  paymentInstructions: AtLeastOne<SEPADirectDebitPaymentInstructionGroup>;
81
- paymentInformationIdBase: string;
82
81
  private formattedPaymentSum;
83
82
  private totalTransactionCount;
84
83
  /**
@@ -1 +1,2 @@
1
1
  export declare const sanitize: (value: string, length: 35) => string;
2
+ export declare const generateId: () => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucianpacurar/iso20022.js",
3
- "version": "0.2.12",
3
+ "version": "0.2.13",
4
4
  "readme": "README.md",
5
5
  "description": "Library to create payment messages.",
6
6
  "main": "dist/index.js",