Skip to content

Commit

Permalink
chore: add config option for mismatch id's (#291)
Browse files Browse the repository at this point in the history
* chore: add config option for mismatch ids

* chore: resolve audit

* chore: rename
  • Loading branch information
kleyow authored Feb 15, 2022
1 parent c2247e4 commit 8e9717a
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 58 deletions.
134 changes: 96 additions & 38 deletions src/audit-resolve.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,80 +140,138 @@
"expiresAt": 1637308004771
},
"1004946|@mojaloop/event-sdk>@grpc/proto-loader>yargs>string-width>strip-ansi>ansi-regex": {
"decision": "postpone",
"madeAt": 1637774978679
"decision": "ignore",
"madeAt": 1644879175753,
"expiresAt": 1647471172307
},
"1004946|@mojaloop/central-services-shared>widdershins>oas-resolver>yargs>string-width>strip-ansi>ansi-regex": {
"decision": "postpone",
"madeAt": 1637774978679
"decision": "ignore",
"madeAt": 1644879175753,
"expiresAt": 1647471172307
},
"1004946|@mojaloop/central-services-shared>widdershins>oas-resolver>yargs>cliui>string-width>strip-ansi>ansi-regex": {
"decision": "postpone",
"madeAt": 1637774978679
"decision": "ignore",
"madeAt": 1644879175753,
"expiresAt": 1647471172307
},
"1004946|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-resolver>yargs>cliui>string-width>strip-ansi>ansi-regex": {
"decision": "postpone",
"madeAt": 1637774978679
"decision": "ignore",
"madeAt": 1644879175753,
"expiresAt": 1647471172307
},
"1004946|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-validator>oas-resolver>yargs>cliui>string-width>strip-ansi>ansi-regex": {
"decision": "postpone",
"madeAt": 1637774978679
"decision": "ignore",
"madeAt": 1644879175754,
"expiresAt": 1647471172307
},
"1004946|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-validator>oas-resolver>yargs>cliui>wrap-ansi>string-width>strip-ansi>ansi-regex": {
"decision": "postpone",
"madeAt": 1637774978679
"decision": "ignore",
"madeAt": 1644879175754,
"expiresAt": 1647471172307
},
"1004946|@mojaloop/event-sdk>@grpc/proto-loader>yargs>cliui>wrap-ansi>strip-ansi>ansi-regex": {
"decision": "postpone",
"madeAt": 1637774978679
"decision": "ignore",
"madeAt": 1644879175754,
"expiresAt": 1647471172307
},
"1004946|@mojaloop/central-services-shared>widdershins>oas-resolver>yargs>cliui>wrap-ansi>strip-ansi>ansi-regex": {
"decision": "postpone",
"madeAt": 1637774978679
"decision": "ignore",
"madeAt": 1644879175754,
"expiresAt": 1647471172307
},
"1004946|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-resolver>yargs>cliui>wrap-ansi>strip-ansi>ansi-regex": {
"decision": "postpone",
"madeAt": 1637774978679
"decision": "ignore",
"madeAt": 1644879175754,
"expiresAt": 1647471172307
},
"1004946|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-validator>oas-resolver>yargs>cliui>wrap-ansi>strip-ansi>ansi-regex": {
"decision": "postpone",
"madeAt": 1637774978679
"decision": "ignore",
"madeAt": 1644879175754,
"expiresAt": 1647471172307
},
"1004946|@mojaloop/event-sdk>@grpc/proto-loader>yargs>cliui>strip-ansi>ansi-regex": {
"decision": "postpone",
"madeAt": 1637774978679
"decision": "ignore",
"madeAt": 1644879175754,
"expiresAt": 1647471172307
},
"1004854|@mojaloop/central-services-shared>widdershins>openapi-sampler>json-pointer": {
"decision": "postpone",
"madeAt": 1637774979253
"decision": "ignore",
"madeAt": 1644879153322,
"expiresAt": 1647471110577
},
"1004869|@mojaloop/central-services-shared>widdershins>swagger2openapi>better-ajv-errors>jsonpointer": {
"decision": "postpone",
"madeAt": 1637774979672
"decision": "ignore",
"madeAt": 1644879154472,
"expiresAt": 1647471110577
},
"1004869|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-validator>better-ajv-errors>jsonpointer": {
"decision": "postpone",
"madeAt": 1637774979672
"decision": "ignore",
"madeAt": 1644879154472,
"expiresAt": 1647471110577
},
"1004946|@mojaloop/central-services-shared>widdershins>yargs>string-width>strip-ansi>ansi-regex": {
"decision": "postpone",
"madeAt": 1637774980265
"decision": "ignore",
"madeAt": 1644879155619,
"expiresAt": 1647471110577
},
"1004946|@mojaloop/central-services-shared>widdershins>yargs>cliui>string-width>strip-ansi>ansi-regex": {
"decision": "postpone",
"madeAt": 1637774980265
"decision": "ignore",
"madeAt": 1644879155619,
"expiresAt": 1647471110577
},
"1005383|@mojaloop/central-services-shared>shins>sanitize-html": {
"decision": "postpone",
"madeAt": 1637774980738
"decision": "ignore",
"madeAt": 1644879156746,
"expiresAt": 1647471110577
},
"1005384|@mojaloop/central-services-shared>shins>sanitize-html": {
"decision": "postpone",
"madeAt": 1637774980738
"decision": "ignore",
"madeAt": 1644879156746,
"expiresAt": 1647471110577
},
"1005534|@mojaloop/central-services-shared>widdershins>yargs>yargs-parser": {
"decision": "postpone",
"madeAt": 1637774981266
"decision": "ignore",
"madeAt": 1644879157837,
"expiresAt": 1647471110577
},
"1006865|axios>follow-redirects": {
"decision": "fix",
"madeAt": 1644879138577
},
"1006865|@mojaloop/central-services-shared>axios>follow-redirects": {
"decision": "fix",
"madeAt": 1644879138577
},
"1007023|axios>follow-redirects": {
"decision": "fix",
"madeAt": 1644879138577
},
"1007023|@mojaloop/central-services-shared>axios>follow-redirects": {
"decision": "fix",
"madeAt": 1644879138577
},
"1006899|@mojaloop/central-services-shared>widdershins>node-fetch": {
"decision": "fix",
"madeAt": 1644879149946
},
"1006899|@mojaloop/event-sdk>grpc>@mapbox/node-pre-gyp>node-fetch": {
"decision": "fix",
"madeAt": 1644879149946
},
"1006846|@mojaloop/central-services-shared>shins>sanitize-html>postcss": {
"decision": "ignore",
"madeAt": 1644879158938,
"expiresAt": 1647471110577
},
"1006886|@mojaloop/central-services-shared>shins>markdown-it": {
"decision": "ignore",
"madeAt": 1644879160175,
"expiresAt": 1647471110577
},
"1007017|@mojaloop/central-services-shared>widdershins>swagger2openapi>oas-validator>ajv": {
"decision": "ignore",
"madeAt": 1644879161354,
"expiresAt": 1647471110577
}
},
"rules": {},
Expand Down
7 changes: 6 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,10 @@ module.exports = {
proxyConfig: env.get('PROXY_CONFIG_PATH').asYamlConfig(),
reserveNotification: env.get('RESERVE_NOTIFICATION').default('false').asBool(),
// resourceVersions config should be string in format: "resouceOneName=1.0,resourceTwoName=1.1"
resourceVersions: env.get('RESOURCE_VERSIONS').default('').asResourceVersions()
resourceVersions: env.get('RESOURCE_VERSIONS').default('').asResourceVersions(),

// in 3PPI DFSP's generate their own `transferId` which is associated with
// a transactionRequestId. this option decodes the ilp packet for
// the `transactionId` to retrieve the quote from cache
allowDifferentTransferTransactionId: env.get('ALLOW_DIFFERENT_TRANSFER_TRANSACTION_ID').default('false').asBool(),
};
25 changes: 16 additions & 9 deletions src/lib/model/InboundTransfersModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class InboundTransfersModel {
this._rejectTransfersOnExpiredQuotes = config.rejectTransfersOnExpiredQuotes;
this._allowTransferWithoutQuote = config.allowTransferWithoutQuote;
this._reserveNotification = config.reserveNotification;
this._allowDifferentTransferTransactionId = config.allowDifferentTransferTransactionId;

this._mojaloopRequests = new MojaloopRequests({
logger: this._logger,
Expand Down Expand Up @@ -175,7 +176,7 @@ class InboundTransfersModel {
response.expiration = new Date(expiration).toISOString();
}

// project our internal quote reponse into mojaloop quote response form
// project our internal quote response into mojaloop quote response form
const mojaloopResponse = shared.internalQuoteResponseToMojaloop(response);

// create our ILP packet and condition and tag them on to our internal quote response
Expand All @@ -193,7 +194,7 @@ class InboundTransfersModel {
fulfilment: fulfilment
});

// now store the quoteRespnse data against the quoteId in our cache to be sent as a response to GET /quotes/{ID}
// now store the quoteResponse data against the quoteId in our cache to be sent as a response to GET /quotes/{ID}
await this._cache.set(`quoteResponse_${quoteRequest.quoteId}`, mojaloopResponse);

// make a callback to the source fsp with the quote response
Expand All @@ -209,21 +210,21 @@ class InboundTransfersModel {
}

/**
* This is executed as when GET /quotes/{ID} request is made to get the response of a previous POST /quotes request.
* This is executed as when GET /quotes/{ID} request is made to get the response of a previous POST /quotes request.
* Gets the quoteResponse from the cache and makes a callback to the originator with result
*/
async getQuoteRequest(quoteId, sourceFspId) {
try {
// Get the quoteRespnse data for the quoteId from the cache to be sent as a response to GET /quotes/{ID}
const quoteResponse = await this._cache.get(`quoteResponse_${quoteId}`);

// If no quoteResponse is found in the cache, make an error callback to the source fsp
if (!quoteResponse) {
const err = new Error('Quote Id not found');
const mojaloopError = await this._handleError(err, Errors.MojaloopApiErrorCodes.QUOTE_ID_NOT_FOUND);
this._logger.push({ mojaloopError }).log(`Sending error response to ${sourceFspId}`);
return await this._mojaloopRequests.putQuotesError(quoteId,
mojaloopError, sourceFspId);
mojaloopError, sourceFspId);
}
// Make a PUT /quotes/{ID} callback to the source fsp with the quote response
return this._mojaloopRequests.putQuotes(quoteId, quoteResponse, sourceFspId);
Expand Down Expand Up @@ -270,14 +271,20 @@ class InboundTransfersModel {


/**
* Validates an incoming transfer prepare request and makes a callback to the originator with
* Validates an incoming transfer prepare request and makes a callback to the originator with
* the result
*/
async prepareTransfer(prepareRequest, sourceFspId) {
try {

// retrieve our quote data
const quote = await this._cache.get(`quote_${prepareRequest.transferId}`);
let quote;

if (this._allowDifferentTransferTransactionId) {
const transactionId = this._ilp.getTransactionObject(prepareRequest.ilpPacket).transactionId;
quote = await this._cache.get(`quote_${transactionId}`);
} else {
quote = await this._cache.get(`quote_${prepareRequest.transferId}`);
}

if(!quote) {
// Check whether to allow transfers without a previous quote.
Expand Down Expand Up @@ -703,7 +710,7 @@ class InboundTransfersModel {
}

/**
* Forwards Switch notification for fulfiled transfer to the DFSP backend, when acting as a payee
* Forwards Switch notification for fulfiled transfer to the DFSP backend, when acting as a payee
*/
async sendNotificationToPayee(body, transferId) {
try {
Expand Down
36 changes: 30 additions & 6 deletions src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8e9717a

Please sign in to comment.