Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ playground
newQueryBuilder.ts
query-builder.ts
dist

# pre-commit scans
talisman_output.log
snyk_output.log
69 changes: 69 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env sh
# Pre-commit hook to run Snyk and Talisman scans, completing both before deciding to commit

# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}

# Check if Snyk is installed
if ! command_exists snyk; then
echo "Error: Snyk is not installed. Please install it and try again."
exit 1
fi

# Check if Talisman is installed
if ! command_exists talisman; then
echo "Error: Talisman is not installed. Please install it and try again."
exit 1
fi

# Allow bypassing the hook with an environment variable
if [ "$SKIP_HOOK" = "1" ]; then
echo "Skipping Snyk and Talisman scans (SKIP_HOOK=1)."
exit 0
fi

# Initialize variables to track scan results
snyk_failed=false
talisman_failed=false

# Run Snyk vulnerability scan
echo "Running Snyk vulnerability scan..."
snyk test --all-projects > snyk_output.log 2>&1
snyk_exit_code=$?

if [ $snyk_exit_code -eq 0 ]; then
echo "Snyk scan passed: No vulnerabilities found."
elif [ $snyk_exit_code -eq 1 ]; then
echo "Snyk found vulnerabilities. See snyk_output.log for details."
snyk_failed=true
else
echo "Snyk scan failed with error (exit code $snyk_exit_code). See snyk_output.log for details."
snyk_failed=true
fi

# Run Talisman secret scan (continues even if Snyk failed)
echo "Running Talisman secret scan..."
talisman --githook pre-commit > talisman_output.log 2>&1
talisman_exit_code=$?

if [ $talisman_exit_code -eq 0 ]; then
echo "Talisman scan passed: No secrets found."
else
echo "Talisman scan failed (exit code $talisman_exit_code). See talisman_output.log for details."
talisman_failed=true
fi

# Evaluate results after both scans
if [ "$snyk_failed" = true ] || [ "$talisman_failed" = true ]; then
echo "Commit aborted due to issues found in one or both scans."
[ "$snyk_failed" = true ] && echo "- Snyk issues: Check snyk_output.log"
[ "$talisman_failed" = true ] && echo "- Talisman issues: Check talisman_output.log"
exit 1
fi

# If both scans pass, allow the commit
echo "All scans passed. Proceeding with commit.cd ."
rm -f snyk_output.log talisman_output.log
exit 0
7 changes: 5 additions & 2 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ fileignoreconfig:
ignore_detectors:
- filecontent
- filename: package-lock.json
checksum: a618ae6c113021eef425f224f1dfd7066b15af1a45249ea063a193517ce5a92f
version: ""
checksum: 37742c5c56859fdfed906c14e97881c4a10e0a52464fda489e4eb8154298fde4
- filename: .husky/pre-commit
checksum: 5baabd7d2c391648163f9371f0e5e9484f8fb90fa2284cfc378732ec3192c193
version: ""
base64_entropy: false
39 changes: 28 additions & 11 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "Contentstack Ecosystem <ecosystem@contentstack.com>",
"name": "@contentstack/datasync-mongodb-sdk",
"version": "1.0.11",
"version": "1.0.12",
"description": "Mongodb query wrapper around contents synced via @contentstack/content-store-mongodb",
"main": "dist/index.js",
"scripts": {
Expand All @@ -11,6 +11,7 @@
"watch-ts": "npm run clean && tsc -w",
"compile": "tsc",
"prepare": "npm run compile",
"pre-commit": "husky install && husky && chmod +x .husky/pre-commit",
"start": "dist/index.js",
"tslint": "npx tslint -c tslint.json 'src/**/*.ts' --fix",
"test": "jest"
Expand All @@ -19,14 +20,15 @@
"dependencies": {
"lodash": "^4.17.21",
"mongodb": "^6.12.0",
"sift": "^17.1.3"
"sift": "^17.1.3"
},
"devDependencies": {
"@types/jest": "29.5.14",
"@types/lodash": "4.17.14",
"@types/node": "10.17.60",
"@types/rimraf": "4.0.5",
"debug": "^4.4.0",
"husky": "^9.1.7",
"jest": "^29.7.0",
"jsdoc": "^4.0.4",
"node-notifier": "^10.0.1",
Expand Down
62 changes: 62 additions & 0 deletions src/messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* Centralized error messages and warnings for the DataSync MongoDB SDK
* This file contains all user-facing messages for consistency and maintainability
*/

export const ErrorMessages = {
// Configuration errors
INVALID_MONGODB_URI: (uri: any) => `MongoDB connection URL: ${uri} must be of type string`,
INVALID_DBNAME: 'Content store dbName should be of type string and not empty',

// Sorting errors
INVALID_ASCENDING_PARAMS: 'Invalid parameters for .ascending(). Expected a valid string field name',
INVALID_DESCENDING_PARAMS: 'Invalid parameters for .descending(). Expected a valid string field name',

// Language errors
INVALID_LANGUAGE_PARAMS: 'Invalid parameters for .language(). Expected a valid language code string',

// Logical operator errors
INVALID_AND_PARAMS: 'Invalid parameters for .and(). Expected an array of query objects',
INVALID_OR_PARAMS: 'Invalid parameters for .or(). Expected an array of query objects',

// Comparison operator errors
INVALID_LESSTHAN_PARAMS: 'Invalid key or value parameters for .lessThan(). Expected a string key and a value',
INVALID_LESSTHAN_OR_EQUAL_PARAMS: 'Invalid key or value parameters for .lessThanOrEqualTo(). Expected a string key and a value',
INVALID_GREATERTHAN_PARAMS: 'Invalid key or value parameters for .greaterThan(). Expected a string key and a value',
INVALID_GREATERTHAN_OR_EQUAL_PARAMS: 'Invalid key or value parameters for .greaterThanOrEqualTo(). Expected a string key and a value',
INVALID_NOTEQUAL_PARAMS: 'Invalid key or value parameters for .notEqualTo(). Expected a string key and a value',
INVALID_CONTAINED_IN_PARAMS: 'Invalid key or value parameters for .containedIn(). Expected a string key and an array value',
INVALID_NOT_CONTAINED_IN_PARAMS: 'Invalid key or value parameters for .notContainedIn(). Expected a string key and an array value',
INVALID_EXISTS_PARAMS: 'Invalid key parameter for .exists(). Expected a valid string field name',
INVALID_NOT_EXISTS_PARAMS: 'Invalid key parameter for .notExists(). Expected a valid string field name',

// Content type errors
MISSING_CONTENT_TYPE_UID: 'Content type UID is required. Please provide a valid content type UID',
MISSING_CONTENT_TYPE_FOR_ENTRY: 'Please call .contentType() before .entry()',
MISSING_CONTENT_TYPE_FOR_ENTRIES: 'Please call .contentType() before .entries()',

// Pagination errors
INVALID_LIMIT_VALUE: 'Invalid value for .limit(). Expected a positive numeric value',
INVALID_SKIP_VALUE: 'Invalid value for .skip(). Expected a non-negative numeric value',

// Projection errors
INVALID_ONLY_PARAMS: 'Invalid field values for .only(). Expected a non-empty array of field names',
INVALID_EXCEPT_PARAMS: 'Invalid field values for .except(). Expected a non-empty array of field names',

// Query errors
INVALID_REGEX_PARAMS: 'Invalid field or pattern parameters for .regex(). Expected string values for both field and pattern',
INVALID_TAGS_PARAMS: 'Invalid field values for .tags(). Expected an array of tag values',
INVALID_WHERE_PARAMS: 'Invalid expression for .where(). Expected a valid expression or function',
INVALID_QUERY_REFERENCES_PARAMS: 'Invalid query object for .queryReferences(). Expected a valid query object',
INVALID_INCLUDE_PARAMS: 'Invalid reference field path for .include(). Expected a valid string or array of strings',

// Query validation errors
INVALID_QUERY: 'Invalid query provided. Please ensure your query is properly formatted',
INVALID_QUERIES: 'Invalid queries provided. Please ensure all queries are properly formatted',
} as const

export const WarningMessages = {
// Performance warnings
SLOW_INCLUDE_REFERENCES: '.includeReferences(...) is a relatively slow query. Consider limiting the depth or using .include() for specific references',
} as const

Loading
Loading