@mojaloop/central-ledger 19.14.0 → 20.1.0
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/.grype.yaml +3 -0
- package/.license-scanner.json +16 -0
- package/.ncurc.yaml +19 -13
- package/.nvmrc +1 -1
- package/.nycrc.yml +14 -2
- package/CHANGELOG.md +51 -0
- package/Dockerfile +13 -10
- package/README.md +39 -89
- package/audit-ci.jsonc +1 -1
- package/config/default.json +60 -3
- package/config/deprecated.default-settlement.json +160 -0
- package/docker/ml-api-adapter/default.json +28 -0
- package/docker-compose.yml +6 -0
- package/nodemon.json +6 -0
- package/package.json +128 -64
- package/{sbom-v19.13.2.csv → sbom-v20.0.0.csv} +886 -736
- package/scripts/_wait4_all.js +5 -5
- package/scripts/transferSettlementTemp/interchangeFeeCalculation.js +51 -0
- package/src/api/index.ts +30 -0
- package/src/api/interface/swagger.json +2249 -2054
- package/src/api/participants/routes.js +1 -1
- package/src/api/root/handler.int.ts +55 -0
- package/src/api/routes.js +7 -6
- package/src/api/server.ts +27 -0
- package/src/api/server.unit.ts +16 -0
- package/src/api/settlementModels/routes.js +4 -4
- package/src/domain/participant/index.d.ts +47 -0
- package/src/domain/participant/index.int.ts +724 -0
- package/src/domain/participant/index.js +4 -5
- package/src/domain/position/fx-prepare.js +1 -1
- package/src/domain/position/fx-timeout-reserved.js +6 -0
- package/src/domain/position/prepare.js +1 -1
- package/src/handlers/admin/handler.js +1 -1
- package/src/handlers/index.js +30 -0
- package/src/handlers/positions/handler.js +0 -2
- package/src/handlers/positions/handlerBatch.js +5 -5
- package/src/handlers/register.js +44 -29
- package/src/handlers/timeouts/handler.js +1 -4
- package/src/handlers/transfers/fx-abort.int.ts +209 -0
- package/src/handlers/transfers/fx-handlers.int.ts +275 -0
- package/src/handlers/transfers/fx-timeout.int.ts +284 -0
- package/src/handlers/transfers/handler.js +1 -3
- package/src/handlers/transfers/handlers.int.ts +538 -0
- package/src/handlers/transfers/prepare.int.ts +1283 -0
- package/src/handlers/transfers/prepare.js +2 -2
- package/src/knexfile.js +19 -0
- package/src/lib/cache.js +1 -1
- package/src/lib/config/index.ts +60 -0
- package/src/lib/config/resolver.ts +231 -0
- package/src/lib/config/resolver.unit.ts +72 -0
- package/src/lib/config/types.ts +372 -0
- package/src/lib/config/util.ts +523 -0
- package/src/lib/config/util.unit.ts +825 -0
- package/src/lib/migrator.js +3 -3
- package/src/lib/proxyCache.js +3 -3
- package/{migrations → src/migrations}/100100_event.js +1 -1
- package/{migrations → src/migrations}/110100_contactType.js +1 -1
- package/{migrations → src/migrations}/110200_currency.js +1 -1
- package/{migrations → src/migrations}/110201_currency-scale.js +1 -1
- package/{migrations → src/migrations}/110300_endpointType.js +1 -1
- package/{migrations → src/migrations}/110400_ledgerEntryType.js +1 -1
- package/{migrations → src/migrations}/110450_ledgerAccountType.js +1 -1
- package/{migrations → src/migrations}/110500_participantLimitType.js +1 -1
- package/{migrations → src/migrations}/110600_transferParticipantRoleType.js +1 -1
- package/{migrations → src/migrations}/110700_transferState.js +1 -1
- package/{migrations → src/migrations}/110900_settlementState.js +1 -1
- package/{migrations → src/migrations}/112000_bulkTransferState.js +1 -1
- package/{migrations → src/migrations}/112100_bulkProcessingState.js +1 -1
- package/{migrations → src/migrations}/200100_participant.js +1 -1
- package/{migrations → src/migrations}/200200_participantContact.js +1 -1
- package/{migrations → src/migrations}/200300_participantEndpoint.js +1 -1
- package/{migrations → src/migrations}/200400_participantParty.js +1 -1
- package/{migrations → src/migrations}/200600_token.js +1 -1
- package/{migrations → src/migrations}/200601_token-indexes.js +1 -1
- package/{migrations → src/migrations}/300100_transferDuplicateCheck.js +2 -2
- package/{migrations → src/migrations}/300150_bulkTransferDuplicateCheck.js +2 -2
- package/{migrations → src/migrations}/300200_transfer.js +2 -2
- package/{migrations → src/migrations}/300202_transfer-decimal184.js +1 -1
- package/{migrations → src/migrations}/300250_bulkTransfer.js +2 -3
- package/{migrations → src/migrations}/300275_bulkTransferAssociation.js +2 -3
- package/{migrations → src/migrations}/300300_ilpPacket.js +1 -1
- package/{migrations → src/migrations}/300400_transferStateChange.js +1 -1
- package/{migrations → src/migrations}/300450_bulkTransferStateChange.js +1 -1
- package/{migrations → src/migrations}/300500_segment.js +1 -1
- package/{migrations → src/migrations}/310100_participantCurrency.js +1 -1
- package/{migrations → src/migrations}/310200_transferParticipant.js +1 -1
- package/{migrations → src/migrations}/310202_transferParticipant-decimal184.js +1 -1
- package/{migrations → src/migrations}/310204_transferParticipant-participantId.js +2 -2
- package/{migrations → src/migrations}/310300_participantPosition.js +1 -1
- package/{migrations → src/migrations}/310302_participantPosition-decimal184.js +1 -1
- package/{migrations → src/migrations}/310400_participantPositionChange.js +1 -1
- package/{migrations → src/migrations}/310402_participantPositionChange-decimal184.js +1 -1
- package/{migrations → src/migrations}/310403_participantPositionChange-participantCurrencyId.js +2 -2
- package/{migrations → src/migrations}/310404_participantPositionChange-change.js +2 -2
- package/{migrations → src/migrations}/310500_participantLimit.js +1 -1
- package/{migrations → src/migrations}/310502_participantLimit-decimal184.js +1 -1
- package/{migrations → src/migrations}/400100_settlementWindow.js +1 -1
- package/{migrations → src/migrations}/400200_settlement.js +1 -1
- package/{migrations → src/migrations}/400300_settlementSettlementWindow.js +1 -1
- package/{migrations → src/migrations}/400301_settlementSettlementWindow-indexes.js +0 -1
- package/{migrations → src/migrations}/400400_settlementWindowStateChange.js +1 -1
- package/{migrations → src/migrations}/400500_settlementTransferParticipant.js +1 -1
- package/{migrations → src/migrations}/400502_settlementTransferParticipant-decimal184.js +1 -1
- package/{migrations → src/migrations}/400600_settlementParticipantCurrency.js +1 -1
- package/{migrations → src/migrations}/400602_settlementParticipantCurrency-decimal184.js +1 -1
- package/{migrations → src/migrations}/400700_settlementParticipantCurrencyStateChange.js +1 -1
- package/{migrations → src/migrations}/400800_settlementStateChange.js +1 -1
- package/{migrations → src/migrations}/400900_settlementWindowContent.js +1 -1
- package/{migrations → src/migrations}/401000_settlementWindowContentStateChange.js +1 -1
- package/{migrations → src/migrations}/401001_settlementWindowContentStateChange-indexes.js +6 -6
- package/{migrations → src/migrations}/401200_settlementContentAggregation.js +1 -1
- package/{migrations → src/migrations}/401300_settlementModel.js +1 -1
- package/{migrations → src/migrations}/410100_transferFulfilmentDuplicateCheck.js +1 -1
- package/{migrations → src/migrations}/410102_transferFulfilmentDuplicateCheck-dropForeignTransferId.js +1 -1
- package/{migrations → src/migrations}/410103_transferFulfilmentDuplicateCheck-hashNullable.js +1 -1
- package/{migrations → src/migrations}/410200_transferFulfilment.js +1 -1
- package/{migrations → src/migrations}/410202_transferFulfilment-ilpFulfilment.js +1 -1
- package/{migrations → src/migrations}/410203_transferFulfilment-foreignTransferFulfilmentId.js +1 -1
- package/{migrations → src/migrations}/410240_bulkTransferFulfilmentDuplicateCheck.js +1 -1
- package/{migrations → src/migrations}/410250_bulkTransferFulfilment.js +1 -1
- package/{migrations → src/migrations}/410300_transferExtension.js +1 -1
- package/{migrations → src/migrations}/410302_transferExtension-transferErrorId.js +1 -1
- package/{migrations → src/migrations}/410350_bulkTransferExtension.js +1 -1
- package/{migrations → src/migrations}/410400_transferTimeout.js +1 -1
- package/{migrations → src/migrations}/410450_transferErrorDuplicateCheck.js +1 -1
- package/{migrations → src/migrations}/410500_transferError.js +1 -1
- package/{migrations → src/migrations}/410502_transferError-foreignTransferErrorDuplicateCheckId.js +1 -1
- package/{migrations → src/migrations}/410550_bulkTransferError.js +1 -1
- package/{migrations → src/migrations}/410600_expiringTransfer.js +1 -1
- package/{migrations → src/migrations}/500401_quote-hotfix-2719.js +8 -8
- package/{migrations → src/migrations}/500501_feature-fixSubIdRef.js +12 -12
- package/{migrations → src/migrations}/500601_party-2480.js +3 -3
- package/{migrations → src/migrations}/501001_quoteExtension-quote-service-174.js +1 -2
- package/{migrations → src/migrations}/501002_quoteExtension-2522.js +3 -3
- package/{migrations → src/migrations}/600010_fxTransferType.js +1 -1
- package/{migrations → src/migrations}/600012_fxParticipantCurrencyType.js +1 -1
- package/{migrations → src/migrations}/600100_fxTransferDuplicateCheck.js +2 -2
- package/{migrations → src/migrations}/600110_fxTransferErrorDuplicateCheck.js.js +1 -1
- package/{migrations → src/migrations}/600200_fxTransfer.js +2 -2
- package/{migrations → src/migrations}/600400_fxTransferStateChange.js +1 -1
- package/{migrations → src/migrations}/600501_fxWatchList.js +2 -2
- package/{migrations → src/migrations}/600600_fxTransferFulfilmentDuplicateCheck.js +1 -1
- package/{migrations → src/migrations}/600700_fxTransferFulfilment.js +1 -1
- package/{migrations → src/migrations}/600800_fxTransferExtension.js +1 -1
- package/{migrations → src/migrations}/601400_fxTransferTimeout.js +1 -1
- package/{migrations → src/migrations}/601500_fxTransferError.js +1 -1
- package/{migrations → src/migrations}/610200_fxTransferParticipant.js +1 -1
- package/{migrations → src/migrations}/610202_fxTransferParticipant-participantId.js +2 -2
- package/{migrations → src/migrations}/610403_participantPositionChange-fxTransfer.js +1 -1
- package/{migrations → src/migrations}/800100_quotePartyView.js +1 -1
- package/{migrations → src/migrations}/800101_feature-fixSubIdRef.js +1 -1
- package/{migrations → src/migrations}/800200_quoteView.js +1 -1
- package/{migrations → src/migrations}/800300_quoteResponseView.js +1 -1
- package/{migrations → src/migrations}/900100_foreign-keys.js +18 -18
- package/{migrations → src/migrations}/900101_foreign-keys.js +6 -6
- package/{migrations → src/migrations}/910100_feature904DDL.js +7 -7
- package/{migrations → src/migrations}/910101_feature904DataMigration.js +1 -1
- package/{migrations → src/migrations}/910102_feature949DataMigration.js +1 -1
- package/{migrations → src/migrations}/910103_feature1093SettlementByCurrency.js +3 -3
- package/{migrations → src/migrations}/940101_quotePartyIdInfoExtension-2522.js +25 -25
- package/{migrations → src/migrations}/950101_transferParticipantStateChange.js +2 -2
- package/{migrations → src/migrations}/950102_settlementModel-adjustPosition.js +2 -2
- package/{migrations → src/migrations}/950103_dropTransferParticipantStateChange.js +3 -3
- package/{migrations → src/migrations}/950104_settlementModel-settlementAccountTypeId.js +3 -3
- package/src/migrations/950107_settlementWindowContent_foreign_settlementModel.js +63 -0
- package/{migrations → src/migrations}/950108_participantProxy.js +1 -2
- package/{migrations → src/migrations}/950120_fxQuoteConversionTerms_sourceAmount_nullable.js +1 -1
- package/{migrations → src/migrations}/960100_create_externalParticipant.js +2 -2
- package/{migrations → src/migrations}/960110_alter_transferParticipant__addFiled_externalParticipantId.js +2 -2
- package/{migrations → src/migrations}/961001_transferForwarded.js +1 -1
- package/{migrations → src/migrations}/961002_fxTransferForwarded.js +1 -1
- package/src/models/participant/externalParticipant.int.ts +85 -0
- package/src/models/participant/facade.js +4 -2
- package/src/models/participant/participantCurrencyCached.js +1 -1
- package/src/models/position/facade.js +8 -2
- package/src/models/transfer/facade.int.ts +139 -0
- package/src/models/transfer/facade.js +8 -3
- package/src/models/transfer/transferDuplicateCheck.js +2 -2
- package/src/models/transfer/transferError.int.ts +112 -0
- package/src/models/transfer/transferExtension.int.ts +137 -0
- package/src/models/transfer/transferStateChange.int.ts +117 -0
- package/{seeds → src/seeds}/participant.js +1 -1
- package/{seeds → src/seeds}/settlementInterchange.js +1 -0
- package/src/settlement/api/handlerRoutes.js +71 -0
- package/src/settlement/api/handlers/health.js +10 -0
- package/src/settlement/api/handlers/index.js +57 -0
- package/src/settlement/api/handlers/settlementWindows/{id}.js +103 -0
- package/src/settlement/api/handlers/settlementWindows.js +77 -0
- package/src/settlement/api/handlers/settlements/{id}.js +133 -0
- package/src/settlement/api/handlers/settlements/{sid}/participants/{pid}/accounts/{aid}.js +127 -0
- package/src/settlement/api/handlers/settlements/{sid}/participants/{pid}.js +127 -0
- package/src/settlement/api/handlers/settlements.js +114 -0
- package/src/settlement/api/openapiRouting.js +87 -0
- package/src/settlement/api/routes.js +176 -0
- package/src/settlement/domain/rules/index.js +46 -0
- package/src/settlement/domain/settlement/index.js +405 -0
- package/src/settlement/domain/settlementWindow/index.js +117 -0
- package/src/settlement/domain/transactions/index.js +83 -0
- package/src/settlement/domain/transferSettlement/index.js +57 -0
- package/src/settlement/handlers/deferredSettlement/handler.js +180 -0
- package/src/settlement/handlers/grossSettlement/handler.js +180 -0
- package/src/settlement/handlers/index.js +101 -0
- package/src/settlement/handlers/register.js +92 -0
- package/src/settlement/handlers/rules/handler.js +164 -0
- package/src/settlement/interface/swagger-handler.json +34 -0
- package/src/settlement/interface/swagger.json +1560 -0
- package/src/settlement/lib/db.js +32 -0
- package/src/settlement/lib/kafka/index.js +41 -0
- package/src/settlement/lib/kafka/producer.js +142 -0
- package/src/settlement/lib/scriptEngine.js +99 -0
- package/src/settlement/lib/scriptsLoader.js +175 -0
- package/src/settlement/lib/utility.js +243 -0
- package/src/settlement/models/ilpPackets/ilpPacket.js +42 -0
- package/src/settlement/models/lib/enums.js +192 -0
- package/src/settlement/models/misc/migrationLock.js +53 -0
- package/src/settlement/models/settlement/facade.js +1652 -0
- package/src/settlement/models/settlement/index.js +55 -0
- package/src/settlement/models/settlement/participantCurrency.js +48 -0
- package/src/settlement/models/settlement/settlement.js +49 -0
- package/src/settlement/models/settlement/settlementModel.js +44 -0
- package/src/settlement/models/settlement/settlementParticipantCurrency.js +61 -0
- package/src/settlement/models/settlement/settlementStateChange.js +44 -0
- package/src/settlement/models/settlement/settlementTransferParticipant.js +46 -0
- package/src/settlement/models/settlementWindow/facade.js +345 -0
- package/src/settlement/models/settlementWindow/index.js +47 -0
- package/src/settlement/models/settlementWindow/settlementWindowStateChange.js +55 -0
- package/src/settlement/models/settlementWindowContent/facade.js +79 -0
- package/src/settlement/models/settlementWindowContent/index.js +40 -0
- package/src/settlement/models/settlementWindowContent/settlementWindowContentStateChange.js +53 -0
- package/src/settlement/models/transferSettlement/facade.js +363 -0
- package/src/settlement/models/transferSettlement/index.js +42 -0
- package/src/settlement/shared/logger/index.js +7 -0
- package/src/settlement/shared/plugins.js +88 -0
- package/src/settlement/shared/setup.js +224 -0
- package/src/settlement/utils/truthyProperty.js +37 -0
- package/src/shared/legacyUtilShim.js +20 -0
- package/src/shared/plugins.js +3 -3
- package/src/shared/results.ts +22 -0
- package/src/shared/results.unit.ts +38 -0
- package/src/shared/setup.js +14 -1
- package/src/testing/api-helpers.ts +1222 -0
- package/src/testing/exec-async.ts +67 -0
- package/src/testing/harness.snapshot.sql +3895 -0
- package/src/testing/harness.test.ts +15 -0
- package/src/testing/harness.ts +1160 -0
- package/src/testing/kafka.ts +221 -0
- package/src/testing/prng.ts +82 -0
- package/src/testing/rdkafka.test.ts +263 -0
- package/src/testing/run.ts +559 -0
- package/src/testing/snapshot.test.ts +92 -0
- package/src/testing/snapshot.ts +549 -0
- package/src/testing/tap-stream.ts +164 -0
- package/src/testing/types.ts +95 -0
- package/src/testing/util.ts +333 -0
- package/src/types/central-services-error-handling.d.ts +72 -0
- package/src/types/central-services-stream.d.ts +148 -0
- package/test-integration.Dockerfile +0 -2
- package/test.Dockerfile +0 -2
- package/tsconfig.json +40 -0
- package/config/knexfile.js +0 -19
- package/migrations/950107_settlementWindowContent_foreign_settlementModel.js +0 -63
- package/src/api/index.js +0 -16
- package/src/lib/config.js +0 -81
- /package/{migrations → src/migrations}/110101_contactType-indexes.js +0 -0
- /package/{migrations → src/migrations}/110301_endpointType-indexes.js +0 -0
- /package/{migrations → src/migrations}/110401_ledgerEntryType-indexes.js +0 -0
- /package/{migrations → src/migrations}/110451_ledgerAccountType-indexes.js +0 -0
- /package/{migrations → src/migrations}/110501_participantLimitType-indexes.js +0 -0
- /package/{migrations → src/migrations}/110601_transferParticipantRoleType-indexes.js +0 -0
- /package/{migrations → src/migrations}/110800_settlementWindowState.js +0 -0
- /package/{migrations → src/migrations}/111000_amountType.js +0 -0
- /package/{migrations → src/migrations}/111001_amountType-indexes.js +0 -0
- /package/{migrations → src/migrations}/111100_balanceOfPayments.js +0 -0
- /package/{migrations → src/migrations}/111101_balanceOfPayments-indexes.js +0 -0
- /package/{migrations → src/migrations}/111200_partyIdentifierType.js +0 -0
- /package/{migrations → src/migrations}/111201_partyIdentifierType-indexes.js +0 -0
- /package/{migrations → src/migrations}/111300_partyType.js +0 -0
- /package/{migrations → src/migrations}/111301_partyType-indexes.js +0 -0
- /package/{migrations → src/migrations}/111400_quoteDuplicateCheck.js +0 -0
- /package/{migrations → src/migrations}/111500_transactionInitiator.js +0 -0
- /package/{migrations → src/migrations}/111501_transactionInitiator-indexes.js +0 -0
- /package/{migrations → src/migrations}/111600_transactionInitiatorType.js +0 -0
- /package/{migrations → src/migrations}/111601_transactionInitiatorType-indexes.js +0 -0
- /package/{migrations → src/migrations}/111700_settlementDelay.js +0 -0
- /package/{migrations → src/migrations}/111701_settlementDelay-indexes.js +0 -0
- /package/{migrations → src/migrations}/111800_settlementInterchange.js +0 -0
- /package/{migrations → src/migrations}/111801_settlementInterchange-indexes.js +0 -0
- /package/{migrations → src/migrations}/111900_settlementGranularity.js +0 -0
- /package/{migrations → src/migrations}/111901_settlementGranularity-indexes.js +0 -0
- /package/{migrations → src/migrations}/112101_bulkProcessingState-indexes.js +0 -0
- /package/{migrations → src/migrations}/200101_participant-indexes.js +0 -0
- /package/{migrations → src/migrations}/200201_participantContact-indexes.js +0 -0
- /package/{migrations → src/migrations}/200301_participantEndpoint-indexes.js +0 -0
- /package/{migrations → src/migrations}/200401_participantParty-indexes.js +0 -0
- /package/{migrations → src/migrations}/300201_transfer-indexes.js +0 -0
- /package/{migrations → src/migrations}/300251_bulkTransfer-indexes.js +0 -0
- /package/{migrations → src/migrations}/300276_bulkTransferAssociation-indexes.js +0 -0
- /package/{migrations → src/migrations}/300401_transferStateChange-indexes.js +0 -0
- /package/{migrations → src/migrations}/300451_bulkTransferStateChange-indexes.js +0 -0
- /package/{migrations → src/migrations}/300501_segment-indexes.js +0 -0
- /package/{migrations → src/migrations}/310101_participantCurrency-indexes.js +0 -0
- /package/{migrations → src/migrations}/310201_transferParticipant-indexes.js +0 -0
- /package/{migrations → src/migrations}/310203_transferParticipant-indexes.js +0 -0
- /package/{migrations → src/migrations}/310301_participantPosition-indexes.js +0 -0
- /package/{migrations → src/migrations}/310401_participantPositionChange-indexes.js +0 -0
- /package/{migrations → src/migrations}/310405_participantPositionChange-positionChange.js +0 -0
- /package/{migrations → src/migrations}/310406_participantPositionChange-positionChange-revert.js +0 -0
- /package/{migrations → src/migrations}/310501_participantLimit-indexes.js +0 -0
- /package/{migrations → src/migrations}/310503_participantLimit-indexes-composite.js +0 -0
- /package/{migrations → src/migrations}/400401_settlmentWindowStateChange-indexes.js +0 -0
- /package/{migrations → src/migrations}/400501_settlementTransferParticipant-indexes.js +0 -0
- /package/{migrations → src/migrations}/400601_settlementParticipantCurrency-indexes.js +0 -0
- /package/{migrations → src/migrations}/400701_settlementParticipantCurrencyStateChange-indexes.js +0 -0
- /package/{migrations → src/migrations}/400801_settlementStateChange-indexes.js +0 -0
- /package/{migrations → src/migrations}/401002_settlementWindowContent-indexes.js +0 -0
- /package/{migrations → src/migrations}/401201_settlementContentAggregation-indexes.js +0 -0
- /package/{migrations → src/migrations}/401301_settlementModel-indexes.js +0 -0
- /package/{migrations → src/migrations}/410101_transferFulfilmentDuplicateCheck-indexes.js +0 -0
- /package/{migrations → src/migrations}/410201_transferFulfilment-indexes.js +0 -0
- /package/{migrations → src/migrations}/410301_transferExtension-indexes.js +0 -0
- /package/{migrations → src/migrations}/410351_bulkTransferExtension-indexes.js +0 -0
- /package/{migrations → src/migrations}/410401_transferTimeout-indexes.js +0 -0
- /package/{migrations → src/migrations}/410501_transferError-indexes.js +0 -0
- /package/{migrations → src/migrations}/410551_bulkTransferError-indexes.js +0 -0
- /package/{migrations → src/migrations}/410601_expiringTransfer-indexes.js +0 -0
- /package/{migrations → src/migrations}/500100_transactionReference.js +0 -0
- /package/{migrations → src/migrations}/500101_transactionReference-indexes.js +0 -0
- /package/{migrations → src/migrations}/500200_transactionScenario.js +0 -0
- /package/{migrations → src/migrations}/500201_transactionScenario-indexes.js +0 -0
- /package/{migrations → src/migrations}/500300_transactionSubScenario.js +0 -0
- /package/{migrations → src/migrations}/500400_quote.js +0 -0
- /package/{migrations → src/migrations}/500500_quoteParty.js +0 -0
- /package/{migrations → src/migrations}/500600_party.js +0 -0
- /package/{migrations → src/migrations}/500700_quoteResponse.js +0 -0
- /package/{migrations → src/migrations}/500800_quoteResponseIlpPacket.js +0 -0
- /package/{migrations → src/migrations}/500900_geoCode.js +0 -0
- /package/{migrations → src/migrations}/501000_quoteExtension.js +0 -0
- /package/{migrations → src/migrations}/501100_quoteResponseDuplicateCheck.js +0 -0
- /package/{migrations → src/migrations}/501200_quoteError.js +0 -0
- /package/{migrations → src/migrations}/501300_transferRules.js +0 -0
- /package/{migrations → src/migrations}/600011_fxTransferType-indexes.js +0 -0
- /package/{migrations → src/migrations}/600013_fxParticipantCurrencyType-indexes.js +0 -0
- /package/{migrations → src/migrations}/600201_fxTransfer-indexes.js +0 -0
- /package/{migrations → src/migrations}/600401_fxTransferStateChange-indexes.js +0 -0
- /package/{migrations → src/migrations}/600502_fxWatchList-indexes.js +0 -0
- /package/{migrations → src/migrations}/600601_fxTransferFulfilmentDuplicateCheck-indexes.js +0 -0
- /package/{migrations → src/migrations}/600701_fxTransferFulfilment-indexes.js +0 -0
- /package/{migrations → src/migrations}/601401_fxTransferTimeout-indexes.js +0 -0
- /package/{migrations → src/migrations}/601501_fxTransferError-indexes.js +0 -0
- /package/{migrations → src/migrations}/610201_fxTransferParticipant-indexes.js +0 -0
- /package/{migrations → src/migrations}/910102_hotfix954.js +0 -0
- /package/{migrations → src/migrations}/940100_quotePartyIdInfoExtension.js +0 -0
- /package/{migrations → src/migrations}/950100_settlementContentAggregation-decimal184.js +0 -0
- /package/{migrations → src/migrations}/950106_unique_settlement_model_ledger_account_currency.js +0 -0
- /package/{migrations → src/migrations}/950109_fxQuote.js +0 -0
- /package/{migrations → src/migrations}/950110_fxQuoteResponse.js +0 -0
- /package/{migrations → src/migrations}/950111_fxQuoteError.js +0 -0
- /package/{migrations → src/migrations}/950113_fxQuoteDuplicateCheck.js +0 -0
- /package/{migrations → src/migrations}/950114_fxQuoteResponseDuplicateCheck.js +0 -0
- /package/{migrations → src/migrations}/950115_fxQuoteConversionTerms.js +0 -0
- /package/{migrations → src/migrations}/950116_fxQuoteConversionTermsExtension.js +0 -0
- /package/{migrations → src/migrations}/950117_fxQuoteResponseConversionTerms.js +0 -0
- /package/{migrations → src/migrations}/950118_fxQuoteResponseConversionTermsExtension.js +0 -0
- /package/{migrations → src/migrations}/950119_fxCharge.js +0 -0
- /package/{migrations → src/migrations}/960111_alter_fxTransferParticipant__addFiled_externalParticipantId.js +0 -0
- /package/{migrations → src/migrations}/960112_fxTransfer-indexes2.js +0 -0
- /package/{migrations → src/migrations}/960113_fxTransferExtension-indexes.js +0 -0
- /package/{migrations → src/migrations}/960114_fxTransferTimeout-indexes2.js +0 -0
- /package/{migrations → src/migrations}/961000_participantEndpoint_unique.js +0 -0
- /package/{migrations → src/migrations}/migration.template +0 -0
- /package/{seeds → src/seeds}/amountType.js +0 -0
- /package/{seeds → src/seeds}/balanceOfPayments.js +0 -0
- /package/{seeds → src/seeds}/bulkProcessingState.js +0 -0
- /package/{seeds → src/seeds}/bulkTransferState.js +0 -0
- /package/{seeds → src/seeds}/currency.js +0 -0
- /package/{seeds → src/seeds}/endpointType.js +0 -0
- /package/{seeds → src/seeds}/fxParticipantCurrencyType.js +0 -0
- /package/{seeds → src/seeds}/fxTransferType.js +0 -0
- /package/{seeds → src/seeds}/ledgerAccountType.js +0 -0
- /package/{seeds → src/seeds}/ledgerEntryType.js +0 -0
- /package/{seeds → src/seeds}/participantLimitType.js +0 -0
- /package/{seeds → src/seeds}/partyIdentifierType.js +0 -0
- /package/{seeds → src/seeds}/partyType.js +0 -0
- /package/{seeds → src/seeds}/settlementDelay.js +0 -0
- /package/{seeds → src/seeds}/settlementGranularity.js +0 -0
- /package/{seeds → src/seeds}/settlementState.js +0 -0
- /package/{seeds → src/seeds}/settlementWindow1State.js +0 -0
- /package/{seeds → src/seeds}/settlementWindow2Open.js +0 -0
- /package/{seeds → src/seeds}/transactionInitiator.js +0 -0
- /package/{seeds → src/seeds}/transactionInitiatorType.js +0 -0
- /package/{seeds → src/seeds}/transactionScenario.js +0 -0
- /package/{seeds → src/seeds}/transferParticipantRoleType.js +0 -0
- /package/{seeds → src/seeds}/transferState.js +0 -0
- /package/{seeds → src/seeds}/z1000_settlementModel-deprecated.js- +0 -0
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
/*****
|
|
2
|
+
License
|
|
3
|
+
--------------
|
|
4
|
+
Copyright © 2020-2025 Mojaloop Foundation
|
|
5
|
+
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
10
|
+
|
|
11
|
+
Contributors
|
|
12
|
+
--------------
|
|
13
|
+
This is the official list of the Mojaloop project contributors for this file.
|
|
14
|
+
Names of the original copyright holders (individuals or organizations)
|
|
15
|
+
should be listed with a '*' in the first column. People who have
|
|
16
|
+
contributed from an organization can be listed under the organization
|
|
17
|
+
that actually holds the copyright for their contributions (see the
|
|
18
|
+
Mojaloop Foundation for an example). Those individuals should have
|
|
19
|
+
their names indented and be marked with a '-'. Email address can be added
|
|
20
|
+
optionally within square brackets <email>.
|
|
21
|
+
|
|
22
|
+
* Mojaloop Foundation
|
|
23
|
+
- Name Surname <name.surname@mojaloop.io>
|
|
24
|
+
|
|
25
|
+
* ModusBox
|
|
26
|
+
- Deon Botha <deon.botha@modusbox.com>
|
|
27
|
+
- Georgi Georgiev <georgi.georgiev@modusbox.com>
|
|
28
|
+
- Valentin Genev <valentin.genev@modusbox.com>
|
|
29
|
+
--------------
|
|
30
|
+
******/
|
|
31
|
+
'use strict'
|
|
32
|
+
|
|
33
|
+
const Db = require('../../lib/db')
|
|
34
|
+
const ErrorHandler = require('@mojaloop/central-services-error-handling')
|
|
35
|
+
const Enum = require('@mojaloop/central-services-shared').Enum
|
|
36
|
+
const { logger } = require('../../shared/logger')
|
|
37
|
+
const SettlementModelModel = require('../settlement/settlementModel')
|
|
38
|
+
|
|
39
|
+
const Facade = {
|
|
40
|
+
getById: async function ({ settlementWindowId }) {
|
|
41
|
+
return Db.from('settlementWindow').query(builder => {
|
|
42
|
+
return builder
|
|
43
|
+
.leftJoin('settlementWindowStateChange AS swsc', 'swsc.settlementWindowStateChangeId', 'settlementWindow.currentStateChangeId')
|
|
44
|
+
.select(
|
|
45
|
+
'settlementWindow.settlementWindowId',
|
|
46
|
+
'swsc.settlementWindowStateId as state',
|
|
47
|
+
'swsc.reason as reason',
|
|
48
|
+
'settlementWindow.createdDate as createdDate',
|
|
49
|
+
'swsc.createdDate as changedDate'
|
|
50
|
+
)
|
|
51
|
+
.first()
|
|
52
|
+
.where('settlementWindow.settlementWindowId', settlementWindowId)
|
|
53
|
+
})
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
getTransfersCount: async function ({ settlementWindowId }) {
|
|
57
|
+
return Db.from('transferFulfilment').query(builder => {
|
|
58
|
+
return builder
|
|
59
|
+
.count('* as cnt')
|
|
60
|
+
.first()
|
|
61
|
+
.where('transferFulfilment.settlementWindowId', settlementWindowId)
|
|
62
|
+
})
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
getByListOfIds: async function (listOfIds, settlementModel, winStateEnum) {
|
|
66
|
+
const knex = await Db.getKnex()
|
|
67
|
+
return Db.from('settlementWindow').query(builder => {
|
|
68
|
+
const b = builder
|
|
69
|
+
.join('settlementWindowStateChange AS swsc', 'swsc.settlementWindowStateChangeId', 'settlementWindow.currentStateChangeId')
|
|
70
|
+
.join('settlementWindowContent AS swc', 'swc.settlementWindowId', 'settlementWindow.settlementWindowId')
|
|
71
|
+
.join('settlementWindowContentStateChange AS swcsc', 'swcsc.settlementWindowContentStateChangeId', 'swc.currentStateChangeId')
|
|
72
|
+
.whereRaw(`settlementWindow.settlementWindowId IN (${listOfIds})`)
|
|
73
|
+
.where('swc.ledgerAccountTypeId', settlementModel.ledgerAccountTypeId)
|
|
74
|
+
.where('swc.currencyId', knex.raw('COALESCE(?, swc.currencyId)', settlementModel.currencyId))
|
|
75
|
+
.whereIn('swsc.settlementWindowStateId', [winStateEnum.CLOSED, winStateEnum.ABORTED, winStateEnum.PENDING_SETTLEMENT])
|
|
76
|
+
.whereIn('swcsc.settlementWindowStateId', [winStateEnum.CLOSED, winStateEnum.ABORTED])
|
|
77
|
+
.distinct(
|
|
78
|
+
'settlementWindow.settlementWindowId',
|
|
79
|
+
'swsc.settlementWindowStateId as state'
|
|
80
|
+
)
|
|
81
|
+
return b
|
|
82
|
+
})
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
getByParams: async function ({ query }) {
|
|
86
|
+
const { participantId, state, fromDateTime, toDateTime, currency } = query
|
|
87
|
+
return Db.from('settlementWindow').query(builder => {
|
|
88
|
+
if (!participantId) {
|
|
89
|
+
const b = builder
|
|
90
|
+
.leftJoin('settlementWindowStateChange AS swsc', 'swsc.settlementWindowStateChangeId', 'settlementWindow.currentStateChangeId')
|
|
91
|
+
.leftJoin('transferFulfilment AS tf', 'tf.settlementWindowId', 'settlementWindow.settlementWindowId')
|
|
92
|
+
.leftJoin('transferParticipant AS tp', 'tp.transferId', 'tf.transferId')
|
|
93
|
+
.leftJoin('participantCurrency AS pc', 'pc.participantCurrencyId', 'tp.participantCurrencyId')
|
|
94
|
+
.select(
|
|
95
|
+
'settlementWindow.settlementWindowId',
|
|
96
|
+
'swsc.settlementWindowStateId as state',
|
|
97
|
+
'swsc.reason as reason',
|
|
98
|
+
'settlementWindow.createdDate as createdDate',
|
|
99
|
+
'swsc.createdDate as changedDate'
|
|
100
|
+
)
|
|
101
|
+
.orderBy('changedDate', 'desc').distinct()
|
|
102
|
+
if (state) { b.where('swsc.settlementWindowStateId', state) }
|
|
103
|
+
if (fromDateTime) { b.where('settlementWindow.createdDate', '>=', fromDateTime) }
|
|
104
|
+
if (toDateTime) { b.where('settlementWindow.createdDate', '<=', toDateTime) }
|
|
105
|
+
if (currency) { b.where('pc.currencyId', currency) }
|
|
106
|
+
return b
|
|
107
|
+
} else {
|
|
108
|
+
const b = builder
|
|
109
|
+
.leftJoin('settlementWindowStateChange AS swsc', 'swsc.settlementWindowStateChangeId', 'settlementWindow.currentStateChangeId')
|
|
110
|
+
.leftJoin('transferFulfilment AS tf', 'tf.settlementWindowId', 'settlementWindow.settlementWindowId')
|
|
111
|
+
.leftJoin('transferParticipant AS tp', 'tp.transferId', 'tf.transferId')
|
|
112
|
+
.leftJoin('participantCurrency AS pc', 'pc.participantCurrencyId', 'tp.participantCurrencyId')
|
|
113
|
+
.select(
|
|
114
|
+
'settlementWindow.settlementWindowId',
|
|
115
|
+
'swsc.settlementWindowStateId as state',
|
|
116
|
+
'swsc.reason as reason',
|
|
117
|
+
'settlementWindow.createdDate as createdDate',
|
|
118
|
+
'swsc.createdDate as changedDate'
|
|
119
|
+
)
|
|
120
|
+
.orderBy('changedDate', 'desc').distinct()
|
|
121
|
+
.where('pc.participantId', participantId)
|
|
122
|
+
if (state) { b.where('swsc.settlementWindowStateId', state) }
|
|
123
|
+
if (fromDateTime) { b.where('settlementWindow.createdDate', '>=', fromDateTime) }
|
|
124
|
+
if (toDateTime) { b.where('settlementWindow.createdDate', '<=', toDateTime) }
|
|
125
|
+
if (currency) { b.where('pc.currencyId', currency) }
|
|
126
|
+
return b
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
process: async function ({ settlementWindowId, reason }, enums = {}) {
|
|
132
|
+
const knex = await Db.getKnex()
|
|
133
|
+
const settlementWindowCurrentState = await Facade.getById({ settlementWindowId })
|
|
134
|
+
const transfersCount = (await Facade.getTransfersCount({ settlementWindowId })).cnt
|
|
135
|
+
if (!settlementWindowCurrentState) {
|
|
136
|
+
throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.VALIDATION_ERROR, `Window ${settlementWindowId} does not exist`)
|
|
137
|
+
} if (settlementWindowCurrentState && settlementWindowCurrentState.state !== enums.OPEN) {
|
|
138
|
+
throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.VALIDATION_ERROR, `Window ${settlementWindowId} is not open`)
|
|
139
|
+
} if (transfersCount === 0) {
|
|
140
|
+
throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.VALIDATION_ERROR, `Window ${settlementWindowId} is empty`)
|
|
141
|
+
} else {
|
|
142
|
+
return knex.transaction(async (trx) => {
|
|
143
|
+
try {
|
|
144
|
+
const transactionTimestamp = new Date()
|
|
145
|
+
const settlementWindowStateChangeId = await knex('settlementWindowStateChange').transacting(trx)
|
|
146
|
+
.insert({
|
|
147
|
+
settlementWindowStateId: enums.PROCESSING,
|
|
148
|
+
reason,
|
|
149
|
+
settlementWindowId,
|
|
150
|
+
createdDate: transactionTimestamp
|
|
151
|
+
})
|
|
152
|
+
await knex('settlementWindow').transacting(trx)
|
|
153
|
+
.where({ settlementWindowId })
|
|
154
|
+
.update({ currentStateChangeId: settlementWindowStateChangeId })
|
|
155
|
+
const newSettlementWindowId = await knex('settlementWindow').transacting(trx)
|
|
156
|
+
.insert({ reason, createdDate: transactionTimestamp })
|
|
157
|
+
const newSettlementWindowStateChangeId = await knex('settlementWindowStateChange').transacting(trx)
|
|
158
|
+
.insert({
|
|
159
|
+
settlementWindowId: newSettlementWindowId[0],
|
|
160
|
+
settlementWindowStateId: enums.OPEN,
|
|
161
|
+
reason,
|
|
162
|
+
createdDate: transactionTimestamp
|
|
163
|
+
})
|
|
164
|
+
await knex('settlementWindow').transacting(trx)
|
|
165
|
+
.where({ settlementWindowId: newSettlementWindowId[0] })
|
|
166
|
+
.update({ currentStateChangeId: newSettlementWindowStateChangeId })
|
|
167
|
+
return newSettlementWindowId[0]
|
|
168
|
+
} catch (err) {
|
|
169
|
+
logger.error(err)
|
|
170
|
+
throw ErrorHandler.Factory.reformatFSPIOPError(err)
|
|
171
|
+
}
|
|
172
|
+
})
|
|
173
|
+
.catch((err) => {
|
|
174
|
+
logger.error(err)
|
|
175
|
+
throw ErrorHandler.Factory.reformatFSPIOPError(err)
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
close: async function (settlementWindowId, reason) {
|
|
181
|
+
const knex = await Db.getKnex()
|
|
182
|
+
const settlementWindowCurrentState = await Facade.getById({ settlementWindowId })
|
|
183
|
+
if (!settlementWindowCurrentState) {
|
|
184
|
+
throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.VALIDATION_ERROR, `Window ${settlementWindowId} does not exist`)
|
|
185
|
+
} if (settlementWindowCurrentState && settlementWindowCurrentState.state !== Enum.Settlements.SettlementWindowState.PROCESSING) {
|
|
186
|
+
throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.VALIDATION_ERROR, `Window ${settlementWindowId} is not in processing state`)
|
|
187
|
+
} else {
|
|
188
|
+
return knex.transaction(async (trx) => {
|
|
189
|
+
try {
|
|
190
|
+
const transactionTimestamp = new Date()
|
|
191
|
+
// Insert settlementWindowContent
|
|
192
|
+
const allSettlementModels = await SettlementModelModel.getAll()
|
|
193
|
+
const smMap = {}
|
|
194
|
+
|
|
195
|
+
for (const sm of allSettlementModels) {
|
|
196
|
+
smMap[sm.settlementModelId] = sm
|
|
197
|
+
}
|
|
198
|
+
const settlementModelCurrenciesList = allSettlementModels.filter(record => record.currencyId !== null).map(record => record.currencyId)
|
|
199
|
+
const swcList = await knex
|
|
200
|
+
.from(/* istanbul ignore next */ function () {
|
|
201
|
+
this.select('tf.settlementWindowId', 'ppc.participantCurrencyId')
|
|
202
|
+
.from('transferFulfilment AS tf')
|
|
203
|
+
.join('transferStateChange AS tsc', 'tsc.transferId', 'tf.transferId')
|
|
204
|
+
.join('participantPositionChange AS ppc', 'ppc.transferStateChangeId', 'tsc.transferStateChangeId')
|
|
205
|
+
.where('tf.settlementWindowId', settlementWindowId)
|
|
206
|
+
.unionAll(/* istanbul ignore next */ function () {
|
|
207
|
+
this.select('ftf.settlementWindowId', 'ppc.participantCurrencyId')
|
|
208
|
+
.from('fxTransferFulfilment AS ftf')
|
|
209
|
+
.join('fxTransferStateChange AS ftsc', 'ftsc.commitRequestId', 'ftf.commitRequestId')
|
|
210
|
+
.join('participantPositionChange AS ppc', 'ppc.fxTransferStateChangeId', 'ftsc.fxTransferStateChangeId')
|
|
211
|
+
.where('ftf.settlementWindowId', settlementWindowId)
|
|
212
|
+
}).as('unioned')
|
|
213
|
+
}).as('swc')
|
|
214
|
+
.join('participantCurrency AS pc', 'pc.participantCurrencyId', 'unioned.participantCurrencyId')
|
|
215
|
+
.join('settlementModel AS m', 'm.ledgerAccountTypeId', 'pc.ledgerAccountTypeId')
|
|
216
|
+
.where('m.settlementGranularityId', Enum.Settlements.SettlementGranularity.NET)
|
|
217
|
+
.distinct('unioned.settlementWindowId', 'pc.ledgerAccountTypeId', 'pc.currencyId', 'm.settlementModelId')
|
|
218
|
+
.transacting(trx)
|
|
219
|
+
const promiseArray = []
|
|
220
|
+
swcList.forEach(swc => {
|
|
221
|
+
const currentModel = smMap[swc.settlementModelId]
|
|
222
|
+
if (currentModel.settlementModelId === swc.settlementModelId) {
|
|
223
|
+
if ((currentModel.currencyId === swc.currencyId) ||
|
|
224
|
+
(!settlementModelCurrenciesList.includes(swc.currencyId) && currentModel.currencyId === null)) { // is default settlement model
|
|
225
|
+
swc.createdDate = transactionTimestamp
|
|
226
|
+
promiseArray.push(knex('settlementWindowContent').insert(swc).transacting(trx))
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
await Promise.all(promiseArray)
|
|
232
|
+
// Insert settlementContentAggregation
|
|
233
|
+
let builder = knex
|
|
234
|
+
.from(knex.raw('settlementContentAggregation (settlementWindowContentId, participantCurrencyId, transferParticipantRoleTypeId, ledgerEntryTypeId, currentStateId, createdDate, amount)'))
|
|
235
|
+
.insert(/* istanbul ignore next */ function () {
|
|
236
|
+
this.from(function () {
|
|
237
|
+
this.select('ppc.participantCurrencyId', 'ppc.change', 'tf.settlementWindowId')
|
|
238
|
+
.from('transferFulfilment AS tf')
|
|
239
|
+
.join('transferStateChange AS tsc', 'tsc.transferId', 'tf.transferId')
|
|
240
|
+
.join('participantPositionChange AS ppc', 'ppc.transferStateChangeId', 'tsc.transferStateChangeId')
|
|
241
|
+
.where('tf.settlementWindowId', settlementWindowId)
|
|
242
|
+
.unionAll(/* istanbul ignore next */ function () {
|
|
243
|
+
this.select('ppc.participantCurrencyId', 'ppc.change', 'fxtf.settlementWindowId')
|
|
244
|
+
.from('fxTransferFulfilment AS fxtf')
|
|
245
|
+
.join('fxTransferStateChange AS fxtsc', 'fxtsc.commitRequestId', 'fxtf.commitRequestId')
|
|
246
|
+
.join('participantPositionChange AS ppc', 'ppc.fxTransferStateChangeId', 'fxtsc.fxTransferStateChangeId')
|
|
247
|
+
.where('fxtf.settlementWindowId', settlementWindowId)
|
|
248
|
+
}).as('unioned')
|
|
249
|
+
})
|
|
250
|
+
.join('participantCurrency AS pc', 'pc.participantCurrencyId', 'unioned.participantCurrencyId')
|
|
251
|
+
.join('participant AS p', 'p.participantId', 'pc.participantId')
|
|
252
|
+
.join('settlementWindowContent AS swc', function () {
|
|
253
|
+
this.on('swc.settlementWindowId', 'unioned.settlementWindowId')
|
|
254
|
+
.on('swc.ledgerAccountTypeId', 'pc.ledgerAccountTypeId')
|
|
255
|
+
.on('swc.currencyId', 'pc.currencyId')
|
|
256
|
+
})
|
|
257
|
+
.join('settlementModel AS m', 'm.settlementModelId', 'swc.settlementModelId')
|
|
258
|
+
.andWhere('m.settlementGranularityId', Enum.Settlements.SettlementGranularity.NET)
|
|
259
|
+
.groupBy('swc.settlementWindowContentId', 'pc.participantCurrencyId', 'transferParticipantRoleTypeId', 'ledgerEntryTypeId')
|
|
260
|
+
.select('swc.settlementWindowContentId', 'pc.participantCurrencyId',
|
|
261
|
+
knex.raw('CASE WHEN unioned.change > 0 THEN ? ELSE ?? END AS transferParticipantRoleTypeId', [Enum.Accounts.TransferParticipantRoleType.PAYER_DFSP, Enum.Accounts.TransferParticipantRoleType.PAYEE_DFSP]),
|
|
262
|
+
knex.raw('? AS ??', [Enum.Accounts.LedgerEntryType.PRINCIPLE_VALUE, 'ledgerEntryTypeId']),
|
|
263
|
+
knex.raw('? AS ??', [Enum.Settlements.SettlementWindowState.CLOSED, 'settlementWindowStateId']),
|
|
264
|
+
knex.raw('? AS ??', [transactionTimestamp, 'createdDate']))
|
|
265
|
+
.sum('unioned.change AS amount')
|
|
266
|
+
})
|
|
267
|
+
.transacting(trx)
|
|
268
|
+
await builder
|
|
269
|
+
|
|
270
|
+
// Insert settlementWindowContentStateChange
|
|
271
|
+
builder = knex
|
|
272
|
+
.from(knex.raw('settlementWindowContentStateChange (settlementWindowContentId, settlementWindowStateId, reason, createdDate)'))
|
|
273
|
+
.insert(/* istanbul ignore next */ function () {
|
|
274
|
+
this.from('settlementWindowContent AS swc')
|
|
275
|
+
.where('swc.settlementWindowId', settlementWindowId)
|
|
276
|
+
.select('swc.settlementWindowContentId',
|
|
277
|
+
knex.raw('? AS ??', [Enum.Settlements.SettlementWindowState.CLOSED, 'settlementWindowStateId']),
|
|
278
|
+
knex.raw('? AS ??', [reason, 'reason']),
|
|
279
|
+
knex.raw('? AS ??', [transactionTimestamp, 'createdDate']))
|
|
280
|
+
})
|
|
281
|
+
.transacting(trx)
|
|
282
|
+
await builder
|
|
283
|
+
|
|
284
|
+
// Update settlementWindowContent pointers to current states, inserted by previous command
|
|
285
|
+
const settlementWindowContentStateChangeList = await knex('settlementWindowContentStateChange AS swcsc')
|
|
286
|
+
.join('settlementWindowContent AS swc', 'swc.settlementWindowContentId', 'swcsc.settlementWindowContentId')
|
|
287
|
+
.select('swc.settlementWindowContentId', 'swcsc.settlementWindowContentStateChangeId')
|
|
288
|
+
.where('swc.settlementWindowId', settlementWindowId)
|
|
289
|
+
.transacting(trx)
|
|
290
|
+
const updatePromises = []
|
|
291
|
+
for (const i in settlementWindowContentStateChangeList) {
|
|
292
|
+
const updatedColumns = { currentStateChangeId: settlementWindowContentStateChangeList[i].settlementWindowContentStateChangeId }
|
|
293
|
+
updatePromises.push(
|
|
294
|
+
knex('settlementWindowContent')
|
|
295
|
+
.where('settlementWindowContentId', settlementWindowContentStateChangeList[i].settlementWindowContentId)
|
|
296
|
+
.update(updatedColumns)
|
|
297
|
+
.transacting(trx)
|
|
298
|
+
)
|
|
299
|
+
}
|
|
300
|
+
await Promise.all(updatePromises)
|
|
301
|
+
|
|
302
|
+
const settlementWindowStateChangeId = await knex('settlementWindowStateChange')
|
|
303
|
+
.insert({
|
|
304
|
+
settlementWindowStateId: Enum.Settlements.SettlementWindowState.CLOSED,
|
|
305
|
+
reason,
|
|
306
|
+
settlementWindowId,
|
|
307
|
+
createdDate: transactionTimestamp
|
|
308
|
+
})
|
|
309
|
+
.transacting(trx)
|
|
310
|
+
await knex('settlementWindow')
|
|
311
|
+
.where({ settlementWindowId })
|
|
312
|
+
.update({ currentStateChangeId: settlementWindowStateChangeId })
|
|
313
|
+
.transacting(trx)
|
|
314
|
+
|
|
315
|
+
return true
|
|
316
|
+
} catch (err) {
|
|
317
|
+
logger.error(err)
|
|
318
|
+
throw ErrorHandler.Factory.reformatFSPIOPError(err)
|
|
319
|
+
}
|
|
320
|
+
})
|
|
321
|
+
.catch((err) => {
|
|
322
|
+
logger.error(err)
|
|
323
|
+
throw ErrorHandler.Factory.reformatFSPIOPError(err)
|
|
324
|
+
})
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
|
|
328
|
+
getBySettlementId: async function ({ settlementId }) {
|
|
329
|
+
return Db.from('settlementSettlementWindow').query(builder => {
|
|
330
|
+
return builder
|
|
331
|
+
.join('settlementWindow AS sw', 'sw.settlementWindowId', 'settlementSettlementWindow.settlementWindowId')
|
|
332
|
+
.join('settlementWindowStateChange AS swsc', 'swsc.settlementWindowStateChangeId', 'sw.currentStateChangeId')
|
|
333
|
+
.select(
|
|
334
|
+
'sw.settlementWindowId AS id',
|
|
335
|
+
'swsc.settlementWindowStateId as state',
|
|
336
|
+
'swsc.reason as reason',
|
|
337
|
+
'sw.createdDate as createdDate',
|
|
338
|
+
'swsc.createdDate as changedDate'
|
|
339
|
+
)
|
|
340
|
+
.where('settlementSettlementWindow.settlementId', settlementId)
|
|
341
|
+
})
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
module.exports = Facade
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*****
|
|
2
|
+
License
|
|
3
|
+
--------------
|
|
4
|
+
Copyright © 2020-2025 Mojaloop Foundation
|
|
5
|
+
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
10
|
+
|
|
11
|
+
Contributors
|
|
12
|
+
--------------
|
|
13
|
+
This is the official list of the Mojaloop project contributors for this file.
|
|
14
|
+
Names of the original copyright holders (individuals or organizations)
|
|
15
|
+
should be listed with a '*' in the first column. People who have
|
|
16
|
+
contributed from an organization can be listed under the organization
|
|
17
|
+
that actually holds the copyright for their contributions (see the
|
|
18
|
+
Mojaloop Foundation for an example). Those individuals should have
|
|
19
|
+
their names indented and be marked with a '-'. Email address can be added
|
|
20
|
+
optionally within square brackets <email>.
|
|
21
|
+
|
|
22
|
+
* Mojaloop Foundation
|
|
23
|
+
- Name Surname <name.surname@mojaloop.io>
|
|
24
|
+
|
|
25
|
+
* ModuxBox
|
|
26
|
+
- Deon Botha <deon.botha@modusbox.com>
|
|
27
|
+
- Georgi Georgiev <georgi.georgiev@modusbox.com>
|
|
28
|
+
- Miguel de Barros <miguel.debarros@modusbox.com>
|
|
29
|
+
- Rajiv Mothilal <rajiv.mothilal@modusbox.com>
|
|
30
|
+
- Valentin Genev <valentin.genev@modusbox.com>
|
|
31
|
+
--------------
|
|
32
|
+
******/
|
|
33
|
+
'use strict'
|
|
34
|
+
|
|
35
|
+
const Facade = require('./facade')
|
|
36
|
+
const settlementWindowStateChange = require('./settlementWindowStateChange')
|
|
37
|
+
|
|
38
|
+
module.exports = {
|
|
39
|
+
getById: Facade.getById,
|
|
40
|
+
getByParams: Facade.getByParams,
|
|
41
|
+
process: Facade.process,
|
|
42
|
+
close: Facade.close,
|
|
43
|
+
getByListOfIds: Facade.getByListOfIds,
|
|
44
|
+
getBySettlementId: Facade.getBySettlementId,
|
|
45
|
+
getUnprocessedTransferParticipantEntryCount: Facade.getUnprocessedTransferParticipantEntryCount,
|
|
46
|
+
createSettlementWindowState: settlementWindowStateChange.create
|
|
47
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*****
|
|
2
|
+
License
|
|
3
|
+
--------------
|
|
4
|
+
Copyright © 2020-2025 Mojaloop Foundation
|
|
5
|
+
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
10
|
+
|
|
11
|
+
Contributors
|
|
12
|
+
--------------
|
|
13
|
+
This is the official list of the Mojaloop project contributors for this file.
|
|
14
|
+
Names of the original copyright holders (individuals or organizations)
|
|
15
|
+
should be listed with a '*' in the first column. People who have
|
|
16
|
+
contributed from an organization can be listed under the organization
|
|
17
|
+
that actually holds the copyright for their contributions (see the
|
|
18
|
+
Mojaloop Foundation for an example). Those individuals should have
|
|
19
|
+
their names indented and be marked with a '-'. Email address can be added
|
|
20
|
+
optionally within square brackets <email>.
|
|
21
|
+
|
|
22
|
+
* Mojaloop Foundation
|
|
23
|
+
- Name Surname <name.surname@mojaloop.io>
|
|
24
|
+
|
|
25
|
+
* ModusBox
|
|
26
|
+
- Deon Botha <deon.botha@modusbox.com>
|
|
27
|
+
- Georgi Georgiev <georgi.georgiev@modusbox.com>
|
|
28
|
+
- Valentin Genev <valentin.genev@modusbox.com>
|
|
29
|
+
--------------
|
|
30
|
+
******/
|
|
31
|
+
'use strict'
|
|
32
|
+
|
|
33
|
+
const Db = require('../../lib/db')
|
|
34
|
+
|
|
35
|
+
const create = async ({ settlementWindowId, state, reason }, enums = {}) => {
|
|
36
|
+
return Db.from('settlementWindowStateChange').insert({
|
|
37
|
+
settlementWindowId,
|
|
38
|
+
settlementWindowStateId: enums[state.toUpperCase()],
|
|
39
|
+
reason
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const getBySettlementWindowId = async (id) => {
|
|
44
|
+
const knex = await Db.getKnex()
|
|
45
|
+
return knex('settlementWindowStateChange')
|
|
46
|
+
.where('settlementWindowId', id)
|
|
47
|
+
.orderBy('settlementWindowStateChangeId', 'desc')
|
|
48
|
+
.select('*')
|
|
49
|
+
.first()
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = {
|
|
53
|
+
create,
|
|
54
|
+
getBySettlementWindowId
|
|
55
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/*****
|
|
2
|
+
License
|
|
3
|
+
--------------
|
|
4
|
+
Copyright © 2020-2025 Mojaloop Foundation
|
|
5
|
+
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
10
|
+
|
|
11
|
+
Contributors
|
|
12
|
+
--------------
|
|
13
|
+
This is the official list of the Mojaloop project contributors for this file.
|
|
14
|
+
Names of the original copyright holders (individuals or organizations)
|
|
15
|
+
should be listed with a '*' in the first column. People who have
|
|
16
|
+
contributed from an organization can be listed under the organization
|
|
17
|
+
that actually holds the copyright for their contributions (see the
|
|
18
|
+
Mojaloop Foundation for an example). Those individuals should have
|
|
19
|
+
their names indented and be marked with a '-'. Email address can be added
|
|
20
|
+
optionally within square brackets <email>.
|
|
21
|
+
|
|
22
|
+
* Mojaloop Foundation
|
|
23
|
+
- Name Surname <name.surname@mojaloop.io>
|
|
24
|
+
|
|
25
|
+
* ModusBox
|
|
26
|
+
- Georgi Georgiev <georgi.georgiev@modusbox.com>
|
|
27
|
+
--------------
|
|
28
|
+
******/
|
|
29
|
+
'use strict'
|
|
30
|
+
|
|
31
|
+
const Db = require('../../lib/db')
|
|
32
|
+
|
|
33
|
+
const Facade = {
|
|
34
|
+
getApplicableByWindowIdList: async function (idList, settlementModel, winStateEnum) {
|
|
35
|
+
const knex = await Db.getKnex()
|
|
36
|
+
return Db.from('settlementWindow').query(builder => {
|
|
37
|
+
const b = builder
|
|
38
|
+
.join('settlementWindowStateChange AS swsc', 'swsc.settlementWindowStateChangeId', 'settlementWindow.currentStateChangeId')
|
|
39
|
+
.join('settlementWindowContent AS swc', 'swc.settlementWindowId', 'settlementWindow.settlementWindowId')
|
|
40
|
+
.join('settlementWindowContentStateChange AS swcsc', 'swcsc.settlementWindowContentStateChangeId', 'swc.currentStateChangeId')
|
|
41
|
+
.whereRaw(`settlementWindow.settlementWindowId IN (${idList})`)
|
|
42
|
+
.where('swc.ledgerAccountTypeId', settlementModel.ledgerAccountTypeId)
|
|
43
|
+
.where('swc.currencyId', knex.raw('COALESCE(?, swc.currencyId)', settlementModel.currencyId))
|
|
44
|
+
.whereIn('swsc.settlementWindowStateId', [winStateEnum.CLOSED, winStateEnum.ABORTED, winStateEnum.PENDING_SETTLEMENT])
|
|
45
|
+
.whereIn('swcsc.settlementWindowStateId', [winStateEnum.CLOSED, winStateEnum.ABORTED])
|
|
46
|
+
.distinct('swc.settlementWindowContentId')
|
|
47
|
+
return b
|
|
48
|
+
})
|
|
49
|
+
},
|
|
50
|
+
getBySettlementId: async (id) => {
|
|
51
|
+
const knex = await Db.getKnex()
|
|
52
|
+
return knex('settlementWindowContent AS swc')
|
|
53
|
+
.join('settlementWindowContentStateChange AS swcsc', 'swcsc.settlementWindowContentStateChangeId', 'swc.currentStateChangeId')
|
|
54
|
+
.join('ledgerAccountType AS lat', 'lat.ledgerAccountTypeId', 'swc.ledgerAccountTypeId')
|
|
55
|
+
.where('swc.settlementId', id)
|
|
56
|
+
.select('swc.settlementWindowContentId AS id', 'swc.settlementWindowId', 'swcsc.settlementWindowStateId AS state',
|
|
57
|
+
'lat.name AS ledgerAccountType', 'swc.currencyId', 'swc.createdDate', 'swcsc.createdDate AS changedDate')
|
|
58
|
+
},
|
|
59
|
+
getBySettlementWindowId: async (id) => {
|
|
60
|
+
const knex = await Db.getKnex()
|
|
61
|
+
return knex('settlementWindowContent AS swc')
|
|
62
|
+
.join('settlementWindowContentStateChange AS swcsc', 'swcsc.settlementWindowContentStateChangeId', 'swc.currentStateChangeId')
|
|
63
|
+
.join('ledgerAccountType AS lat', 'lat.ledgerAccountTypeId', 'swc.ledgerAccountTypeId')
|
|
64
|
+
.where('swc.settlementWindowId', id)
|
|
65
|
+
.select('swc.settlementWindowContentId AS id', 'swcsc.settlementWindowStateId AS state',
|
|
66
|
+
'lat.name AS ledgerAccountType', 'swc.currencyId', 'swc.createdDate', 'swcsc.createdDate AS changedDate', 'swc.settlementId')
|
|
67
|
+
},
|
|
68
|
+
getBySettlementAndWindowId: async (settlementId, settlementWindowId) => {
|
|
69
|
+
const knex = await Db.getKnex()
|
|
70
|
+
return knex('settlementWindowContent AS swc')
|
|
71
|
+
.join('settlementWindowContentStateChange AS swcsc', 'swcsc.settlementWindowContentStateChangeId', 'swc.currentStateChangeId')
|
|
72
|
+
.join('ledgerAccountType AS lat', 'lat.ledgerAccountTypeId', 'swc.ledgerAccountTypeId')
|
|
73
|
+
.where({ 'swc.settlementId': settlementId, 'swc.settlementWindowId': settlementWindowId })
|
|
74
|
+
.select('swc.settlementWindowContentId AS id', 'swc.settlementWindowId', 'swcsc.settlementWindowStateId AS state',
|
|
75
|
+
'lat.name AS ledgerAccountType', 'swc.currencyId', 'swc.createdDate', 'swcsc.createdDate AS changedDate')
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
module.exports = Facade
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*****
|
|
2
|
+
License
|
|
3
|
+
--------------
|
|
4
|
+
Copyright © 2020-2025 Mojaloop Foundation
|
|
5
|
+
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
10
|
+
|
|
11
|
+
Contributors
|
|
12
|
+
--------------
|
|
13
|
+
This is the official list of the Mojaloop project contributors for this file.
|
|
14
|
+
Names of the original copyright holders (individuals or organizations)
|
|
15
|
+
should be listed with a '*' in the first column. People who have
|
|
16
|
+
contributed from an organization can be listed under the organization
|
|
17
|
+
that actually holds the copyright for their contributions (see the
|
|
18
|
+
Mojaloop Foundation for an example). Those individuals should have
|
|
19
|
+
their names indented and be marked with a '-'. Email address can be added
|
|
20
|
+
optionally within square brackets <email>.
|
|
21
|
+
|
|
22
|
+
* Mojaloop Foundation
|
|
23
|
+
- Name Surname <name.surname@mojaloop.io>
|
|
24
|
+
|
|
25
|
+
* ModuxBox
|
|
26
|
+
- Georgi Georgiev <georgi.georgiev@modusbox.com>
|
|
27
|
+
--------------
|
|
28
|
+
******/
|
|
29
|
+
'use strict'
|
|
30
|
+
|
|
31
|
+
const Facade = require('./facade')
|
|
32
|
+
const SettlementWindowContentStateChangeModel = require('./settlementWindowContentStateChange')
|
|
33
|
+
|
|
34
|
+
module.exports = {
|
|
35
|
+
createSettlementWindowContentState: SettlementWindowContentStateChangeModel.create,
|
|
36
|
+
getApplicableByWindowIdList: Facade.getApplicableByWindowIdList,
|
|
37
|
+
getBySettlementId: Facade.getBySettlementId,
|
|
38
|
+
getBySettlementWindowId: Facade.getBySettlementWindowId,
|
|
39
|
+
getBySettlementAndWindowId: Facade.getBySettlementAndWindowId
|
|
40
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*****
|
|
2
|
+
License
|
|
3
|
+
--------------
|
|
4
|
+
Copyright © 2020-2025 Mojaloop Foundation
|
|
5
|
+
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
10
|
+
|
|
11
|
+
Contributors
|
|
12
|
+
--------------
|
|
13
|
+
This is the official list of the Mojaloop project contributors for this file.
|
|
14
|
+
Names of the original copyright holders (individuals or organizations)
|
|
15
|
+
should be listed with a '*' in the first column. People who have
|
|
16
|
+
contributed from an organization can be listed under the organization
|
|
17
|
+
that actually holds the copyright for their contributions (see the
|
|
18
|
+
Mojaloop Foundation for an example). Those individuals should have
|
|
19
|
+
their names indented and be marked with a '-'. Email address can be added
|
|
20
|
+
optionally within square brackets <email>.
|
|
21
|
+
|
|
22
|
+
* Mojaloop Foundation
|
|
23
|
+
- Name Surname <name.surname@mojaloop.io>
|
|
24
|
+
|
|
25
|
+
* ModusBox
|
|
26
|
+
- Georgi Georgiev <georgi.georgiev@modusbox.com>
|
|
27
|
+
--------------
|
|
28
|
+
******/
|
|
29
|
+
'use strict'
|
|
30
|
+
|
|
31
|
+
const Db = require('../../lib/db')
|
|
32
|
+
|
|
33
|
+
const create = async ({ settlementWindowContentId, state, reason }, enums = {}) => {
|
|
34
|
+
return Db.from('settlementWindowContentStateChange').insert({
|
|
35
|
+
settlementWindowContentId,
|
|
36
|
+
settlementWindowStateId: enums[state.toUpperCase()],
|
|
37
|
+
reason
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const getBySettlementWindowContentId = async (id) => {
|
|
42
|
+
const knex = await Db.getKnex()
|
|
43
|
+
return knex('settlementWindowContentStateChange')
|
|
44
|
+
.where('settlementWindowContentId', id)
|
|
45
|
+
.orderBy('settlementWindowContentStateChangeId', 'desc')
|
|
46
|
+
.select('*')
|
|
47
|
+
.first()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
module.exports = {
|
|
51
|
+
create,
|
|
52
|
+
getBySettlementWindowContentId
|
|
53
|
+
}
|