@lucianpacurar/iso20022.js 0.2.14 → 0.2.16

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
@@ -1425,6 +1425,34 @@ declare class SEPADirectDebitPaymentInitiation extends PaymentInitiation {
1425
1425
  RmtInf?: {
1426
1426
  Ustrd: string;
1427
1427
  } | undefined;
1428
+ Dbtr: any;
1429
+ DbtrAcct: {
1430
+ Id: {
1431
+ IBAN: string;
1432
+ };
1433
+ } | {
1434
+ Id: {
1435
+ Othr: {
1436
+ Id: string;
1437
+ };
1438
+ };
1439
+ };
1440
+ DbtrAgt?: {
1441
+ FinInstnId: {
1442
+ BIC: string;
1443
+ ClrSysMmbId?: undefined;
1444
+ };
1445
+ } | {
1446
+ FinInstnId: {
1447
+ ClrSysMmbId: {
1448
+ ClrSysId: {
1449
+ Cd: string;
1450
+ };
1451
+ MmbId: string;
1452
+ };
1453
+ BIC?: undefined;
1454
+ };
1455
+ } | undefined;
1428
1456
  PmtId: {
1429
1457
  EndToEndId: string;
1430
1458
  };
@@ -1455,34 +1483,6 @@ declare class SEPADirectDebitPaymentInitiation extends PaymentInitiation {
1455
1483
  AmdmntInd: boolean;
1456
1484
  };
1457
1485
  };
1458
- DbtrAgt: {
1459
- FinInstnId: {
1460
- BIC: string;
1461
- ClrSysMmbId?: undefined;
1462
- };
1463
- } | {
1464
- FinInstnId: {
1465
- ClrSysMmbId: {
1466
- ClrSysId: {
1467
- Cd: string;
1468
- };
1469
- MmbId: string;
1470
- };
1471
- BIC?: undefined;
1472
- };
1473
- };
1474
- Dbtr: any;
1475
- DbtrAcct: {
1476
- Id: {
1477
- IBAN: string;
1478
- };
1479
- } | {
1480
- Id: {
1481
- Othr: {
1482
- Id: string;
1483
- };
1484
- };
1485
- };
1486
1486
  };
1487
1487
  /**
1488
1488
  * Serializes the SEPA direct debit initiation to an XML string.
@@ -1681,6 +1681,93 @@ declare const BalanceTypeCodeDescriptionMap: {
1681
1681
  };
1682
1682
  type BalanceType = (typeof BalanceTypeCode)[keyof typeof BalanceTypeCode];
1683
1683
 
1684
+ /**
1685
+ * Configuration interface for creating a CashManagementAccountReport instance.
1686
+ */
1687
+ interface CashManagementAccountReportConfig {
1688
+ /** Unique identifier for the message */
1689
+ messageId: string;
1690
+ /** Date and time when the report was created */
1691
+ creationDate: Date;
1692
+ /** Recipient (party without bank and institution) receiving the report */
1693
+ recipient?: {
1694
+ id?: string;
1695
+ name?: string;
1696
+ address?: StructuredAddress;
1697
+ };
1698
+ /** Array of bank account reports included in the report */
1699
+ statements: Statement[];
1700
+ }
1701
+ /**
1702
+ * Represents a Cash Management Account Report (CAMT.052.x).
1703
+ * This class encapsulates the data and functionality related to processing
1704
+ * and accessing information from a CAMT.052 XML file.
1705
+ */
1706
+ declare class CashManagementAccountReport implements GenericISO20022Message {
1707
+ private _messageId;
1708
+ private _creationDate;
1709
+ private _recipient?;
1710
+ private _statements;
1711
+ constructor(config: CashManagementAccountReportConfig);
1712
+ static supportedMessages(): ISO20022MessageTypeName[];
1713
+ get data(): CashManagementAccountReportConfig;
1714
+ static fromDocumentObject(obj: {
1715
+ Document: any;
1716
+ }): CashManagementAccountReport;
1717
+ /**
1718
+ * Creates a CashManagementAccountReport instance from a raw XML string.
1719
+ *
1720
+ * @param {string} rawXml - The raw XML string containing the CAMT.052 data.
1721
+ * @returns {CashManagementAccountReport} A new instance of CashManagementAccountReport.
1722
+ * @throws {Error} If the XML parsing fails or required data is missing.
1723
+ */
1724
+ static fromXML(rawXml: string): CashManagementAccountReport;
1725
+ /**
1726
+ *
1727
+ * @param json - JSON string representing a CashManagementAccountReport
1728
+ * @returns {CashManagementAccountReport} A new instance of CashManagementAccountReport
1729
+ * @throws {Error} If the JSON parsing fails or required data is missing.
1730
+ */
1731
+ static fromJSON(json: string): CashManagementAccountReport;
1732
+ toJSON(): any;
1733
+ serialize(): string;
1734
+ /**
1735
+ * Retrieves all balances from all statements in the report.
1736
+ * @returns {Balance[]} An array of all balances across all statements.
1737
+ */
1738
+ get balances(): Balance[];
1739
+ /**
1740
+ * Retrieves all transactions from all statements in the report.
1741
+ * @returns {Transaction[]} An array of all transactions across all statements.
1742
+ */
1743
+ get transactions(): Transaction[];
1744
+ /**
1745
+ * Retrieves all entries from all statements in the report.
1746
+ * @returns {Entry[]} An array of all entries across all statements.
1747
+ */
1748
+ get entries(): Entry[];
1749
+ /**
1750
+ * Gets the unique identifier for the message.
1751
+ * @returns {string} The message ID.
1752
+ */
1753
+ get messageId(): string;
1754
+ /**
1755
+ * Gets the party receiving the report.
1756
+ * @returns {Party | undefined} The recipient party information, or undefined if no recipient is set.
1757
+ */
1758
+ get recipient(): Party | undefined;
1759
+ /**
1760
+ * Gets the date and time when the report was created.
1761
+ * @returns {Date} The creation date of the report.
1762
+ */
1763
+ get creationDate(): Date;
1764
+ /**
1765
+ * Gets all statements included in the report.
1766
+ * @returns {Statement[]} An array of all statements in the report.
1767
+ */
1768
+ get statements(): Statement[];
1769
+ }
1770
+
1684
1771
  type AtLeastOne<T> = [T, ...T[]];
1685
1772
  /**
1686
1773
  * Configuration interface for the ISO20022 class.
@@ -2500,4 +2587,4 @@ declare class InvalidXmlNamespaceError extends Iso20022JsError {
2500
2587
  constructor(message: string);
2501
2588
  }
2502
2589
 
2503
- export { type ABAAgent, ACHCreditPaymentInitiation, type ACHCreditPaymentInitiationConfig$1 as ACHCreditPaymentInitiationConfig, type ACHCreditPaymentInstruction, type ACHLocalInstrument, ACHLocalInstrumentCode, ACHLocalInstrumentCodeDescriptionMap, type Account, type Agent, type BICAgent, type Balance, type BalanceType, BalanceTypeCode, BalanceTypeCodeDescriptionMap, type BaseAccount, type BaseStatusInformation as BaseStatus, CashManagementEndOfDayReport, type Entry, type GroupStatusInformation as GroupStatus, type IBANAccount, ISO20022, InvalidXmlError, InvalidXmlNamespaceError, Iso20022JsError, type MandateAmendmentInformation, type MandateInformation, type OriginalGroupInformation, type Party, type PaymentStatusInformation as PaymentStatus, PaymentStatusCode, PaymentStatusReport, RTPCreditPaymentInitiation, type RTPCreditPaymentInitiationConfig$1 as RTPCreditPaymentInitiationConfig, type RTPCreditPaymentInstruction, SEPACreditPaymentInitiation, type SEPACreditPaymentInitiationConfig$1 as SEPACreditPaymentInitiationConfig, type SEPACreditPaymentInstruction, SEPADirectDebitPaymentInitiation, type SEPADirectDebitPaymentInitiationConfig$1 as SEPADirectDebitPaymentInitiationConfig, type SEPADirectDebitPaymentInstruction, type SEPADirectDebitPaymentInstructionGroup, type SEPALocalInstrument, SEPAMultiCreditPaymentInitiation, type SEPAMultiCreditPaymentInitiationConfig$1 as SEPAMultiCreditPaymentInitiationConfig, type SEPAMultiCreditPaymentInstructionGroup, type SEPASequenceType, SWIFTCreditPaymentInitiation, type SWIFTCreditPaymentInitiationConfig$1 as SWIFTCreditPaymentInitiationConfig, type SWIFTCreditPaymentInstruction, type Statement, type PaymentStatus as Status, type StatusInformation, type StatusType, type StructuredAddress, type Transaction, type TransactionStatusInformation as TransactionStatus };
2590
+ export { type ABAAgent, ACHCreditPaymentInitiation, type ACHCreditPaymentInitiationConfig$1 as ACHCreditPaymentInitiationConfig, type ACHCreditPaymentInstruction, type ACHLocalInstrument, ACHLocalInstrumentCode, ACHLocalInstrumentCodeDescriptionMap, type Account, type Agent, type BICAgent, type Balance, type BalanceType, BalanceTypeCode, BalanceTypeCodeDescriptionMap, type BaseAccount, type BaseStatusInformation as BaseStatus, CashManagementAccountReport, CashManagementEndOfDayReport, type Entry, type GroupStatusInformation as GroupStatus, type IBANAccount, ISO20022, InvalidXmlError, InvalidXmlNamespaceError, Iso20022JsError, type MandateAmendmentInformation, type MandateInformation, type OriginalGroupInformation, type Party, type PaymentStatusInformation as PaymentStatus, PaymentStatusCode, PaymentStatusReport, RTPCreditPaymentInitiation, type RTPCreditPaymentInitiationConfig$1 as RTPCreditPaymentInitiationConfig, type RTPCreditPaymentInstruction, SEPACreditPaymentInitiation, type SEPACreditPaymentInitiationConfig$1 as SEPACreditPaymentInitiationConfig, type SEPACreditPaymentInstruction, SEPADirectDebitPaymentInitiation, type SEPADirectDebitPaymentInitiationConfig$1 as SEPADirectDebitPaymentInitiationConfig, type SEPADirectDebitPaymentInstruction, type SEPADirectDebitPaymentInstructionGroup, type SEPALocalInstrument, SEPAMultiCreditPaymentInitiation, type SEPAMultiCreditPaymentInitiationConfig$1 as SEPAMultiCreditPaymentInitiationConfig, type SEPAMultiCreditPaymentInstructionGroup, type SEPASequenceType, SWIFTCreditPaymentInitiation, type SWIFTCreditPaymentInitiationConfig$1 as SWIFTCreditPaymentInitiationConfig, type SWIFTCreditPaymentInstruction, type Statement, type PaymentStatus as Status, type StatusInformation, type StatusType, type StructuredAddress, type Transaction, type TransactionStatusInformation as TransactionStatus };
package/dist/index.js CHANGED
@@ -2397,6 +2397,7 @@ const ISO20022Messages = {
2397
2397
  CAMT_004: 'CAMT.004',
2398
2398
  CAMT_005: 'CAMT.005',
2399
2399
  CAMT_006: 'CAMT.006',
2400
+ CAMT_052: 'CAMT.052',
2400
2401
  CAMT_053: 'CAMT.053',
2401
2402
  PAIN_001: 'PAIN.001',
2402
2403
  PAIN_002: 'PAIN.002',
@@ -8177,7 +8178,9 @@ class SEPACreditPaymentInitiation extends PaymentInitiation {
8177
8178
  ReqdExctnDt: this.creationDate.toISOString().split('T').at(0),
8178
8179
  Dbtr: this.party(this.initiatingParty),
8179
8180
  DbtrAcct: this.account(this.initiatingParty.account),
8180
- DbtrAgt: this.agent(this.initiatingParty.agent),
8181
+ ...(this.initiatingParty.agent && {
8182
+ DbtrAgt: this.agent(this.initiatingParty.agent),
8183
+ }),
8181
8184
  ChrgBr: 'SLEV',
8182
8185
  // payments[]
8183
8186
  CdtTrfTxInf: this.paymentInstructions.map(p => this.creditTransfer(p)),
@@ -9372,7 +9375,9 @@ class SEPADirectDebitPaymentInitiation extends PaymentInitiation {
9372
9375
  }),
9373
9376
  },
9374
9377
  },
9375
- DbtrAgt: this.agent(instruction.debtor.agent),
9378
+ ...(instruction.debtor.agent && {
9379
+ DbtrAgt: this.agent(instruction.debtor.agent),
9380
+ }),
9376
9381
  Dbtr: this.party(instruction.debtor),
9377
9382
  DbtrAcct: this.account(instruction.debtor.account),
9378
9383
  ...(instruction.remittanceInformation && {
@@ -9421,7 +9426,9 @@ class SEPADirectDebitPaymentInitiation extends PaymentInitiation {
9421
9426
  .split('T')[0],
9422
9427
  Cdtr: this.party(group.creditor),
9423
9428
  CdtrAcct: this.account(group.creditor.account),
9424
- CdtrAgt: this.agent(group.creditor.agent),
9429
+ ...(group.creditor.agent && {
9430
+ CdtrAgt: this.agent(group.creditor.agent),
9431
+ }),
9425
9432
  ChrgBr: 'SLEV',
9426
9433
  CdtrSchmeId: {
9427
9434
  Id: {
@@ -10668,6 +10675,161 @@ class CashManagementReturnTransaction {
10668
10675
  }
10669
10676
  registerISO20022Implementation(CashManagementReturnTransaction);
10670
10677
 
10678
+ /**
10679
+ * Represents a Cash Management Account Report (CAMT.052.x).
10680
+ * This class encapsulates the data and functionality related to processing
10681
+ * and accessing information from a CAMT.052 XML file.
10682
+ */
10683
+ class CashManagementAccountReport {
10684
+ _messageId;
10685
+ _creationDate;
10686
+ _recipient;
10687
+ _statements;
10688
+ constructor(config) {
10689
+ this._messageId = config.messageId;
10690
+ this._creationDate = config.creationDate;
10691
+ this._recipient = config.recipient;
10692
+ this._statements = config.statements;
10693
+ }
10694
+ static supportedMessages() {
10695
+ return [ISO20022Messages.CAMT_052];
10696
+ }
10697
+ get data() {
10698
+ return {
10699
+ messageId: this._messageId,
10700
+ creationDate: this._creationDate,
10701
+ recipient: this._recipient,
10702
+ statements: this._statements,
10703
+ };
10704
+ }
10705
+ static fromDocumentObject(obj) {
10706
+ const bankToCustomerAcctRpt = obj.Document.BkToCstmrAcctRpt;
10707
+ const rawCreationDate = bankToCustomerAcctRpt.GrpHdr.CreDtTm;
10708
+ const creationDate = new Date(rawCreationDate);
10709
+ let statements = [];
10710
+ if (Array.isArray(bankToCustomerAcctRpt.Rpt)) {
10711
+ statements = bankToCustomerAcctRpt.Rpt.map((stmt) => parseStatement(stmt));
10712
+ }
10713
+ else {
10714
+ statements = [parseStatement(bankToCustomerAcctRpt.Rpt)];
10715
+ }
10716
+ const rawRecipient = bankToCustomerAcctRpt.GrpHdr.MsgRcpt;
10717
+ return new CashManagementAccountReport({
10718
+ messageId: bankToCustomerAcctRpt.GrpHdr.MsgId.toString(),
10719
+ creationDate,
10720
+ recipient: rawRecipient ? parseRecipient(rawRecipient) : undefined,
10721
+ statements: statements,
10722
+ });
10723
+ }
10724
+ /**
10725
+ * Creates a CashManagementAccountReport instance from a raw XML string.
10726
+ *
10727
+ * @param {string} rawXml - The raw XML string containing the CAMT.052 data.
10728
+ * @returns {CashManagementAccountReport} A new instance of CashManagementAccountReport.
10729
+ * @throws {Error} If the XML parsing fails or required data is missing.
10730
+ */
10731
+ static fromXML(rawXml) {
10732
+ const parser = XML.getParser();
10733
+ const xml = parser.parse(rawXml);
10734
+ if (!xml.Document) {
10735
+ throw new InvalidXmlError('Invalid XML format');
10736
+ }
10737
+ const namespace = (xml.Document['@_xmlns'] ||
10738
+ xml.Document['@_Xmlns']);
10739
+ if (!namespace.startsWith('urn:iso:std:iso:20022:tech:xsd:camt.052.001.')) {
10740
+ throw new InvalidXmlNamespaceError('Invalid CAMT.052 namespace');
10741
+ }
10742
+ return CashManagementAccountReport.fromDocumentObject(xml);
10743
+ }
10744
+ /**
10745
+ *
10746
+ * @param json - JSON string representing a CashManagementAccountReport
10747
+ * @returns {CashManagementAccountReport} A new instance of CashManagementAccountReport
10748
+ * @throws {Error} If the JSON parsing fails or required data is missing.
10749
+ */
10750
+ static fromJSON(json) {
10751
+ const obj = JSON.parse(json);
10752
+ if (!obj.Document) {
10753
+ throw new InvalidXmlError('Invalid JSON format');
10754
+ }
10755
+ return CashManagementAccountReport.fromDocumentObject(obj);
10756
+ }
10757
+ toJSON() {
10758
+ const Document = {
10759
+ BkToCstmrAcctRpt: {
10760
+ GrpHdr: {
10761
+ MsgId: this._messageId,
10762
+ CreDtTm: this._creationDate.toISOString(),
10763
+ MsgRcpt: this._recipient
10764
+ ? exportRecipient(this._recipient)
10765
+ : undefined,
10766
+ },
10767
+ Rpt: this._statements.map(stmt => exportStatement(stmt)),
10768
+ },
10769
+ };
10770
+ return { Document };
10771
+ }
10772
+ serialize() {
10773
+ const builder = XML.getBuilder();
10774
+ const obj = this.toJSON();
10775
+ obj.Document['@_xmlns'] = 'urn:iso:std:iso:20022:tech:xsd:camt.052.001.02';
10776
+ obj.Document['@_xmlns:xsi'] = 'http://www.w3.org/2001/XMLSchema-instance';
10777
+ return builder.build(obj);
10778
+ }
10779
+ /**
10780
+ * Retrieves all balances from all statements in the report.
10781
+ * @returns {Balance[]} An array of all balances across all statements.
10782
+ */
10783
+ get balances() {
10784
+ return this._statements.flatMap(statement => statement.balances);
10785
+ }
10786
+ /**
10787
+ * Retrieves all transactions from all statements in the report.
10788
+ * @returns {Transaction[]} An array of all transactions across all statements.
10789
+ */
10790
+ get transactions() {
10791
+ return this._statements
10792
+ .flatMap(statement => statement.entries)
10793
+ .flatMap(entry => entry.transactions);
10794
+ }
10795
+ /**
10796
+ * Retrieves all entries from all statements in the report.
10797
+ * @returns {Entry[]} An array of all entries across all statements.
10798
+ */
10799
+ get entries() {
10800
+ return this._statements.flatMap(statement => statement.entries);
10801
+ }
10802
+ /**
10803
+ * Gets the unique identifier for the message.
10804
+ * @returns {string} The message ID.
10805
+ */
10806
+ get messageId() {
10807
+ return this._messageId;
10808
+ }
10809
+ /**
10810
+ * Gets the party receiving the report.
10811
+ * @returns {Party | undefined} The recipient party information, or undefined if no recipient is set.
10812
+ */
10813
+ get recipient() {
10814
+ return this._recipient;
10815
+ }
10816
+ /**
10817
+ * Gets the date and time when the report was created.
10818
+ * @returns {Date} The creation date of the report.
10819
+ */
10820
+ get creationDate() {
10821
+ return this._creationDate;
10822
+ }
10823
+ /**
10824
+ * Gets all statements included in the report.
10825
+ * @returns {Statement[]} An array of all statements in the report.
10826
+ */
10827
+ get statements() {
10828
+ return this._statements;
10829
+ }
10830
+ }
10831
+ registerISO20022Implementation(CashManagementAccountReport);
10832
+
10671
10833
  // Types related to CAMT 053
10672
10834
  /**
10673
10835
  * Balance types as defined in ISO 20022.
@@ -11383,6 +11545,7 @@ exports.ACHLocalInstrumentCode = ACHLocalInstrumentCode;
11383
11545
  exports.ACHLocalInstrumentCodeDescriptionMap = ACHLocalInstrumentCodeDescriptionMap;
11384
11546
  exports.BalanceTypeCode = BalanceTypeCode;
11385
11547
  exports.BalanceTypeCodeDescriptionMap = BalanceTypeCodeDescriptionMap;
11548
+ exports.CashManagementAccountReport = CashManagementAccountReport;
11386
11549
  exports.CashManagementEndOfDayReport = CashManagementEndOfDayReport;
11387
11550
  exports.ISO20022 = ISO20022;
11388
11551
  exports.InvalidXmlError = InvalidXmlError;
package/dist/index.mjs CHANGED
@@ -2395,6 +2395,7 @@ const ISO20022Messages = {
2395
2395
  CAMT_004: 'CAMT.004',
2396
2396
  CAMT_005: 'CAMT.005',
2397
2397
  CAMT_006: 'CAMT.006',
2398
+ CAMT_052: 'CAMT.052',
2398
2399
  CAMT_053: 'CAMT.053',
2399
2400
  PAIN_001: 'PAIN.001',
2400
2401
  PAIN_002: 'PAIN.002',
@@ -8175,7 +8176,9 @@ class SEPACreditPaymentInitiation extends PaymentInitiation {
8175
8176
  ReqdExctnDt: this.creationDate.toISOString().split('T').at(0),
8176
8177
  Dbtr: this.party(this.initiatingParty),
8177
8178
  DbtrAcct: this.account(this.initiatingParty.account),
8178
- DbtrAgt: this.agent(this.initiatingParty.agent),
8179
+ ...(this.initiatingParty.agent && {
8180
+ DbtrAgt: this.agent(this.initiatingParty.agent),
8181
+ }),
8179
8182
  ChrgBr: 'SLEV',
8180
8183
  // payments[]
8181
8184
  CdtTrfTxInf: this.paymentInstructions.map(p => this.creditTransfer(p)),
@@ -9370,7 +9373,9 @@ class SEPADirectDebitPaymentInitiation extends PaymentInitiation {
9370
9373
  }),
9371
9374
  },
9372
9375
  },
9373
- DbtrAgt: this.agent(instruction.debtor.agent),
9376
+ ...(instruction.debtor.agent && {
9377
+ DbtrAgt: this.agent(instruction.debtor.agent),
9378
+ }),
9374
9379
  Dbtr: this.party(instruction.debtor),
9375
9380
  DbtrAcct: this.account(instruction.debtor.account),
9376
9381
  ...(instruction.remittanceInformation && {
@@ -9419,7 +9424,9 @@ class SEPADirectDebitPaymentInitiation extends PaymentInitiation {
9419
9424
  .split('T')[0],
9420
9425
  Cdtr: this.party(group.creditor),
9421
9426
  CdtrAcct: this.account(group.creditor.account),
9422
- CdtrAgt: this.agent(group.creditor.agent),
9427
+ ...(group.creditor.agent && {
9428
+ CdtrAgt: this.agent(group.creditor.agent),
9429
+ }),
9423
9430
  ChrgBr: 'SLEV',
9424
9431
  CdtrSchmeId: {
9425
9432
  Id: {
@@ -10666,6 +10673,161 @@ class CashManagementReturnTransaction {
10666
10673
  }
10667
10674
  registerISO20022Implementation(CashManagementReturnTransaction);
10668
10675
 
10676
+ /**
10677
+ * Represents a Cash Management Account Report (CAMT.052.x).
10678
+ * This class encapsulates the data and functionality related to processing
10679
+ * and accessing information from a CAMT.052 XML file.
10680
+ */
10681
+ class CashManagementAccountReport {
10682
+ _messageId;
10683
+ _creationDate;
10684
+ _recipient;
10685
+ _statements;
10686
+ constructor(config) {
10687
+ this._messageId = config.messageId;
10688
+ this._creationDate = config.creationDate;
10689
+ this._recipient = config.recipient;
10690
+ this._statements = config.statements;
10691
+ }
10692
+ static supportedMessages() {
10693
+ return [ISO20022Messages.CAMT_052];
10694
+ }
10695
+ get data() {
10696
+ return {
10697
+ messageId: this._messageId,
10698
+ creationDate: this._creationDate,
10699
+ recipient: this._recipient,
10700
+ statements: this._statements,
10701
+ };
10702
+ }
10703
+ static fromDocumentObject(obj) {
10704
+ const bankToCustomerAcctRpt = obj.Document.BkToCstmrAcctRpt;
10705
+ const rawCreationDate = bankToCustomerAcctRpt.GrpHdr.CreDtTm;
10706
+ const creationDate = new Date(rawCreationDate);
10707
+ let statements = [];
10708
+ if (Array.isArray(bankToCustomerAcctRpt.Rpt)) {
10709
+ statements = bankToCustomerAcctRpt.Rpt.map((stmt) => parseStatement(stmt));
10710
+ }
10711
+ else {
10712
+ statements = [parseStatement(bankToCustomerAcctRpt.Rpt)];
10713
+ }
10714
+ const rawRecipient = bankToCustomerAcctRpt.GrpHdr.MsgRcpt;
10715
+ return new CashManagementAccountReport({
10716
+ messageId: bankToCustomerAcctRpt.GrpHdr.MsgId.toString(),
10717
+ creationDate,
10718
+ recipient: rawRecipient ? parseRecipient(rawRecipient) : undefined,
10719
+ statements: statements,
10720
+ });
10721
+ }
10722
+ /**
10723
+ * Creates a CashManagementAccountReport instance from a raw XML string.
10724
+ *
10725
+ * @param {string} rawXml - The raw XML string containing the CAMT.052 data.
10726
+ * @returns {CashManagementAccountReport} A new instance of CashManagementAccountReport.
10727
+ * @throws {Error} If the XML parsing fails or required data is missing.
10728
+ */
10729
+ static fromXML(rawXml) {
10730
+ const parser = XML.getParser();
10731
+ const xml = parser.parse(rawXml);
10732
+ if (!xml.Document) {
10733
+ throw new InvalidXmlError('Invalid XML format');
10734
+ }
10735
+ const namespace = (xml.Document['@_xmlns'] ||
10736
+ xml.Document['@_Xmlns']);
10737
+ if (!namespace.startsWith('urn:iso:std:iso:20022:tech:xsd:camt.052.001.')) {
10738
+ throw new InvalidXmlNamespaceError('Invalid CAMT.052 namespace');
10739
+ }
10740
+ return CashManagementAccountReport.fromDocumentObject(xml);
10741
+ }
10742
+ /**
10743
+ *
10744
+ * @param json - JSON string representing a CashManagementAccountReport
10745
+ * @returns {CashManagementAccountReport} A new instance of CashManagementAccountReport
10746
+ * @throws {Error} If the JSON parsing fails or required data is missing.
10747
+ */
10748
+ static fromJSON(json) {
10749
+ const obj = JSON.parse(json);
10750
+ if (!obj.Document) {
10751
+ throw new InvalidXmlError('Invalid JSON format');
10752
+ }
10753
+ return CashManagementAccountReport.fromDocumentObject(obj);
10754
+ }
10755
+ toJSON() {
10756
+ const Document = {
10757
+ BkToCstmrAcctRpt: {
10758
+ GrpHdr: {
10759
+ MsgId: this._messageId,
10760
+ CreDtTm: this._creationDate.toISOString(),
10761
+ MsgRcpt: this._recipient
10762
+ ? exportRecipient(this._recipient)
10763
+ : undefined,
10764
+ },
10765
+ Rpt: this._statements.map(stmt => exportStatement(stmt)),
10766
+ },
10767
+ };
10768
+ return { Document };
10769
+ }
10770
+ serialize() {
10771
+ const builder = XML.getBuilder();
10772
+ const obj = this.toJSON();
10773
+ obj.Document['@_xmlns'] = 'urn:iso:std:iso:20022:tech:xsd:camt.052.001.02';
10774
+ obj.Document['@_xmlns:xsi'] = 'http://www.w3.org/2001/XMLSchema-instance';
10775
+ return builder.build(obj);
10776
+ }
10777
+ /**
10778
+ * Retrieves all balances from all statements in the report.
10779
+ * @returns {Balance[]} An array of all balances across all statements.
10780
+ */
10781
+ get balances() {
10782
+ return this._statements.flatMap(statement => statement.balances);
10783
+ }
10784
+ /**
10785
+ * Retrieves all transactions from all statements in the report.
10786
+ * @returns {Transaction[]} An array of all transactions across all statements.
10787
+ */
10788
+ get transactions() {
10789
+ return this._statements
10790
+ .flatMap(statement => statement.entries)
10791
+ .flatMap(entry => entry.transactions);
10792
+ }
10793
+ /**
10794
+ * Retrieves all entries from all statements in the report.
10795
+ * @returns {Entry[]} An array of all entries across all statements.
10796
+ */
10797
+ get entries() {
10798
+ return this._statements.flatMap(statement => statement.entries);
10799
+ }
10800
+ /**
10801
+ * Gets the unique identifier for the message.
10802
+ * @returns {string} The message ID.
10803
+ */
10804
+ get messageId() {
10805
+ return this._messageId;
10806
+ }
10807
+ /**
10808
+ * Gets the party receiving the report.
10809
+ * @returns {Party | undefined} The recipient party information, or undefined if no recipient is set.
10810
+ */
10811
+ get recipient() {
10812
+ return this._recipient;
10813
+ }
10814
+ /**
10815
+ * Gets the date and time when the report was created.
10816
+ * @returns {Date} The creation date of the report.
10817
+ */
10818
+ get creationDate() {
10819
+ return this._creationDate;
10820
+ }
10821
+ /**
10822
+ * Gets all statements included in the report.
10823
+ * @returns {Statement[]} An array of all statements in the report.
10824
+ */
10825
+ get statements() {
10826
+ return this._statements;
10827
+ }
10828
+ }
10829
+ registerISO20022Implementation(CashManagementAccountReport);
10830
+
10669
10831
  // Types related to CAMT 053
10670
10832
  /**
10671
10833
  * Balance types as defined in ISO 20022.
@@ -11376,4 +11538,4 @@ class CashManagementEndOfDayReport {
11376
11538
  }
11377
11539
  registerISO20022Implementation(CashManagementEndOfDayReport);
11378
11540
 
11379
- export { ACHCreditPaymentInitiation, ACHLocalInstrumentCode, ACHLocalInstrumentCodeDescriptionMap, BalanceTypeCode, BalanceTypeCodeDescriptionMap, CashManagementEndOfDayReport, ISO20022, InvalidXmlError, InvalidXmlNamespaceError, Iso20022JsError, PaymentStatusCode, PaymentStatusReport, RTPCreditPaymentInitiation, SEPACreditPaymentInitiation, SEPADirectDebitPaymentInitiation, SEPAMultiCreditPaymentInitiation, SWIFTCreditPaymentInitiation };
11541
+ export { ACHCreditPaymentInitiation, ACHLocalInstrumentCode, ACHLocalInstrumentCodeDescriptionMap, BalanceTypeCode, BalanceTypeCodeDescriptionMap, CashManagementAccountReport, CashManagementEndOfDayReport, ISO20022, InvalidXmlError, InvalidXmlNamespaceError, Iso20022JsError, PaymentStatusCode, PaymentStatusReport, RTPCreditPaymentInitiation, SEPACreditPaymentInitiation, SEPADirectDebitPaymentInitiation, SEPAMultiCreditPaymentInitiation, SWIFTCreditPaymentInitiation };
@@ -0,0 +1,90 @@
1
+ import { Balance, Entry, Statement, Transaction } from '../types';
2
+ import { Party, StructuredAddress } from '../../lib/types';
3
+ import { GenericISO20022Message, ISO20022MessageTypeName } from '../../lib/interfaces';
4
+ /**
5
+ * Configuration interface for creating a CashManagementAccountReport instance.
6
+ */
7
+ interface CashManagementAccountReportConfig {
8
+ /** Unique identifier for the message */
9
+ messageId: string;
10
+ /** Date and time when the report was created */
11
+ creationDate: Date;
12
+ /** Recipient (party without bank and institution) receiving the report */
13
+ recipient?: {
14
+ id?: string;
15
+ name?: string;
16
+ address?: StructuredAddress;
17
+ };
18
+ /** Array of bank account reports included in the report */
19
+ statements: Statement[];
20
+ }
21
+ /**
22
+ * Represents a Cash Management Account Report (CAMT.052.x).
23
+ * This class encapsulates the data and functionality related to processing
24
+ * and accessing information from a CAMT.052 XML file.
25
+ */
26
+ export declare class CashManagementAccountReport implements GenericISO20022Message {
27
+ private _messageId;
28
+ private _creationDate;
29
+ private _recipient?;
30
+ private _statements;
31
+ constructor(config: CashManagementAccountReportConfig);
32
+ static supportedMessages(): ISO20022MessageTypeName[];
33
+ get data(): CashManagementAccountReportConfig;
34
+ static fromDocumentObject(obj: {
35
+ Document: any;
36
+ }): CashManagementAccountReport;
37
+ /**
38
+ * Creates a CashManagementAccountReport instance from a raw XML string.
39
+ *
40
+ * @param {string} rawXml - The raw XML string containing the CAMT.052 data.
41
+ * @returns {CashManagementAccountReport} A new instance of CashManagementAccountReport.
42
+ * @throws {Error} If the XML parsing fails or required data is missing.
43
+ */
44
+ static fromXML(rawXml: string): CashManagementAccountReport;
45
+ /**
46
+ *
47
+ * @param json - JSON string representing a CashManagementAccountReport
48
+ * @returns {CashManagementAccountReport} A new instance of CashManagementAccountReport
49
+ * @throws {Error} If the JSON parsing fails or required data is missing.
50
+ */
51
+ static fromJSON(json: string): CashManagementAccountReport;
52
+ toJSON(): any;
53
+ serialize(): string;
54
+ /**
55
+ * Retrieves all balances from all statements in the report.
56
+ * @returns {Balance[]} An array of all balances across all statements.
57
+ */
58
+ get balances(): Balance[];
59
+ /**
60
+ * Retrieves all transactions from all statements in the report.
61
+ * @returns {Transaction[]} An array of all transactions across all statements.
62
+ */
63
+ get transactions(): Transaction[];
64
+ /**
65
+ * Retrieves all entries from all statements in the report.
66
+ * @returns {Entry[]} An array of all entries across all statements.
67
+ */
68
+ get entries(): Entry[];
69
+ /**
70
+ * Gets the unique identifier for the message.
71
+ * @returns {string} The message ID.
72
+ */
73
+ get messageId(): string;
74
+ /**
75
+ * Gets the party receiving the report.
76
+ * @returns {Party | undefined} The recipient party information, or undefined if no recipient is set.
77
+ */
78
+ get recipient(): Party | undefined;
79
+ /**
80
+ * Gets the date and time when the report was created.
81
+ * @returns {Date} The creation date of the report.
82
+ */
83
+ get creationDate(): Date;
84
+ /**
85
+ * Gets all statements included in the report.
86
+ * @returns {Statement[]} An array of all statements in the report.
87
+ */
88
+ get statements(): Statement[];
89
+ }
90
+ export {};
@@ -2,4 +2,5 @@ export * from './003/cash-management-get-account';
2
2
  export * from './004/cash-management-return-account';
3
3
  export * from './005/cash-management-get-transaction';
4
4
  export * from './006/cash-management-return-transaction';
5
+ export * from './052/cash-management-account-report';
5
6
  export * from './types';
@@ -59,6 +59,7 @@ export { PaymentStatusCode } from './pain/002/types';
59
59
  export { PaymentStatusReport } from './pain/002/payment-status-report';
60
60
  export type { SEPADirectDebitPaymentInitiationConfig, SEPADirectDebitPaymentInstructionGroup, } from './pain/008/sepa-direct-debit-payment-initiation';
61
61
  export { SEPADirectDebitPaymentInitiation } from './pain/008/sepa-direct-debit-payment-initiation';
62
+ export { CashManagementAccountReport } from './camt/052/cash-management-account-report';
62
63
  export type { Statement, Balance, Entry, Transaction, BalanceType, } from './camt/types';
63
64
  export { BalanceTypeCode, BalanceTypeCodeDescriptionMap } from './camt/types';
64
65
  export { CashManagementEndOfDayReport } from './camt/053/cash-management-end-of-day-report';
@@ -120,6 +120,34 @@ export declare class SEPADirectDebitPaymentInitiation extends PaymentInitiation
120
120
  RmtInf?: {
121
121
  Ustrd: string;
122
122
  } | undefined;
123
+ Dbtr: any;
124
+ DbtrAcct: {
125
+ Id: {
126
+ IBAN: string;
127
+ };
128
+ } | {
129
+ Id: {
130
+ Othr: {
131
+ Id: string;
132
+ };
133
+ };
134
+ };
135
+ DbtrAgt?: {
136
+ FinInstnId: {
137
+ BIC: string;
138
+ ClrSysMmbId?: undefined;
139
+ };
140
+ } | {
141
+ FinInstnId: {
142
+ ClrSysMmbId: {
143
+ ClrSysId: {
144
+ Cd: string;
145
+ };
146
+ MmbId: string;
147
+ };
148
+ BIC?: undefined;
149
+ };
150
+ } | undefined;
123
151
  PmtId: {
124
152
  EndToEndId: string;
125
153
  };
@@ -150,34 +178,6 @@ export declare class SEPADirectDebitPaymentInitiation extends PaymentInitiation
150
178
  AmdmntInd: boolean;
151
179
  };
152
180
  };
153
- DbtrAgt: {
154
- FinInstnId: {
155
- BIC: string;
156
- ClrSysMmbId?: undefined;
157
- };
158
- } | {
159
- FinInstnId: {
160
- ClrSysMmbId: {
161
- ClrSysId: {
162
- Cd: string;
163
- };
164
- MmbId: string;
165
- };
166
- BIC?: undefined;
167
- };
168
- };
169
- Dbtr: any;
170
- DbtrAcct: {
171
- Id: {
172
- IBAN: string;
173
- };
174
- } | {
175
- Id: {
176
- Othr: {
177
- Id: string;
178
- };
179
- };
180
- };
181
181
  };
182
182
  /**
183
183
  * Serializes the SEPA direct debit initiation to an XML string.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucianpacurar/iso20022.js",
3
- "version": "0.2.14",
3
+ "version": "0.2.16",
4
4
  "readme": "README.md",
5
5
  "description": "Library to create payment messages.",
6
6
  "main": "dist/index.js",