-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3034fe7
commit 1357c38
Showing
4 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
config_url= https://raw.githubusercontent.com/ONDC-Official/protocol-server-config/metro/build/build.json | ||
PORT = 80 | ||
BUSINESS_SERVER_IS_SYNC = false | ||
IS_VERIFY_AUTH = false | ||
SERVER_TYPE = BAP | ||
SUBSCRIBER_URL = https://2f59-59-145-217-117.ngrok-free.app | ||
BACKEND_SERVER_URL= http://localhost:8000 | ||
GATEWAY_URL = "http://localhost:5500/ondc/" | ||
PRIVATE_KEY=Un205TSOdDXTq8E+N/sJOLJ8xalnzZ1EUP1Wcv23sKx70fOfFd4Q2bzfpzPQ+6XZhZv65SH7Pr6YMk8SuFHpxQ== | ||
SUBSCRIBER_ID=mobility-staging.ondc.org | ||
SUBSCRIBER_UNIQUE_KEY=UK-MOBILITY | ||
PROTOCOL_SERVER = https://2f59-59-145-217-117.ngrok-free.app | ||
is_loadConfigFromGit = true | ||
|
||
DATABASE_CONNECTION_STRING = mongodb://localhost:27017/protocolServerBAP | ||
USE_DB = false | ||
VERSION = 1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
config_url= https://raw.githubusercontent.com/ONDC-Official/protocol-server-config/metro-dev/build/build.json | ||
PORT = 5500 | ||
IS_VERIFY_AUTH = false | ||
SERVER_TYPE = BPP | ||
SUBSCRIBER_URL = http://localhost:3000 | ||
BACKEND_SERVER_URL= http://localhost:5502 | ||
PRIVATE_KEY=Un205TSOdDXTq8E+N/sJOLJ8xalnzZ1EUP1Wcv23sKx70fOfFd4Q2bzfpzPQ+6XZhZv65SH7Pr6YMk8SuFHpxQ== | ||
SUBSCRIBER_ID=mobility-staging.ondc.org | ||
SUBSCRIBER_UNIQUE_KEY=UK-MOBILITY | ||
PROTOCOL_SERVER = http://localhost:3000 | ||
localConfig= false | ||
flow = metro-flow-1 | ||
|
||
DATABASE_CONNECTION_STRING = mongodb://localhost:27017/protocolServerBPP | ||
USE_DB = false | ||
VERSION = 1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
// const Ajv = require("ajv"); | ||
// const addFormats = require("ajv-formats"); | ||
// const ajvErrors = require("ajv-errors"); | ||
|
||
// const logger = require("../utils/logger").init(); | ||
// const { formatted_error } = require("../utils/utils"); | ||
|
||
// const ajv = new Ajv({ | ||
// allErrors: true, | ||
// strict: "log", | ||
// }); | ||
|
||
// // Add formats and custom error messages to Ajv | ||
// addFormats(ajv); | ||
// ajvErrors(ajv); | ||
|
||
// // Define the schema for transaction ID validation | ||
// const transactionIdSchema = { | ||
// type: "object", | ||
// properties: { | ||
// context: { | ||
// type: "object", | ||
// properties: { | ||
// transaction_id: { type: "string", minLength: 1, errorMessage: "Transaction ID is required and must be a non-empty string." } | ||
// }, | ||
// required: ["transaction_id"], | ||
// additionalProperties: true, | ||
// } | ||
// }, | ||
// required: ["context"], | ||
// additionalProperties: true, | ||
// errorMessage: { | ||
// required: { | ||
// "context.transaction_id": "Transaction ID is required." | ||
// } | ||
// } | ||
// }; | ||
|
||
// /** | ||
// * Middleware to validate transaction ID. | ||
// * @param {Object} req - Express request object. | ||
// * @param {Object} res - Express response object. | ||
// * @param {Function} next - Express next middleware function. | ||
// */ | ||
// const validateTransactionId = (req, res, next) => { | ||
// const payload = req.body; | ||
// const validate = ajv.compile(transactionIdSchema); | ||
|
||
// const valid = validate(payload); | ||
// if (!valid) { | ||
// const errorList = validate.errors; | ||
// const formattedErrors = formatted_error(errorList); | ||
// logger.error(`Transaction ID validation failed: ${JSON.stringify(formattedErrors)}`); | ||
|
||
// return res.status(400).json({ status: false, errors: formattedErrors }); | ||
// } | ||
|
||
// logger.info(`Transaction ID validation succeeded for Transaction ID: ${payload.context.transaction_id}`); | ||
// next(); | ||
// }; | ||
|
||
// module.exports = validateTransactionId; | ||
|
||
|
||
const Ajv = require("ajv"); | ||
const addFormats = require("ajv-formats"); | ||
const ajvErrors = require("ajv-errors"); | ||
|
||
const logger = require("../utils/logger").init(); | ||
const { formatted_error } = require("../utils/utils"); | ||
|
||
const ajv = new Ajv({ | ||
allErrors: true, | ||
strict: "log", | ||
}); | ||
|
||
// Add formats and custom error messages to Ajv | ||
addFormats(ajv); | ||
ajvErrors(ajv); | ||
|
||
// Define the schema for multiple transaction IDs validation | ||
const transactionIdsSchema = { | ||
type: "object", | ||
properties: { | ||
context: { | ||
type: "object", | ||
properties: { | ||
transaction_id: { type: "string", minLength: 1, errorMessage: "Transaction ID is required and must be a non-empty string." }, | ||
secondary_transaction_id: { type: "string", minLength: 1, errorMessage: "Secondary Transaction ID must be a non-empty string." } | ||
}, | ||
required: ["transaction_id"], | ||
additionalProperties: true, | ||
}, | ||
anotherContext: { | ||
type: "object", | ||
properties: { | ||
another_transaction_id: { type: "string", minLength: 1, errorMessage: "Another Transaction ID must be a non-empty string." } | ||
}, | ||
additionalProperties: true, | ||
} | ||
}, | ||
additionalProperties: true, | ||
errorMessage: { | ||
required: { | ||
"context.transaction_id": "Transaction ID is required." | ||
} | ||
} | ||
}; | ||
|
||
/** | ||
* Middleware to validate multiple transaction IDs. | ||
* @param {Object} req - Express request object. | ||
* @param {Object} res - Express response object. | ||
* @param {Function} next - Express next middleware function. | ||
*/ | ||
const validateTransactionIds = (req, res, next) => { | ||
const payload = req.body; | ||
const validate = ajv.compile(transactionIdsSchema); | ||
|
||
const valid = validate(payload); | ||
if (!valid) { | ||
const errorList = validate.errors; | ||
const formattedErrors = formatted_error(errorList); | ||
logger.error(`Transaction IDs validation failed: ${JSON.stringify(formattedErrors)}`); | ||
|
||
return res.status(400).json({ status: false, errors: formattedErrors }); | ||
} | ||
|
||
logger.info(`Transaction IDs validation succeeded for Transaction ID: ${payload.context.transaction_id}`); | ||
if (payload.context.secondary_transaction_id) { | ||
logger.info(`Secondary Transaction ID: ${payload.context.secondary_transaction_id}`); | ||
} | ||
if (payload.anotherContext && payload.anotherContext.another_transaction_id) { | ||
logger.info(`Another Transaction ID: ${payload.anotherContext.another_transaction_id}`); | ||
} | ||
next(); | ||
}; | ||
|
||
module.exports = validateTransactionIds; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters