Skip to content

Commit 3b78f42

Browse files
Merge pull request #72 from contentstack/development
DX | 10-11-2025 | Release
2 parents c7cc9da + ed6ad3a commit 3b78f42

File tree

9 files changed

+247
-46
lines changed

9 files changed

+247
-46
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ playground
1313
newQueryBuilder.ts
1414
query-builder.ts
1515
dist
16+
17+
# pre-commit scans
18+
talisman_output.log
19+
snyk_output.log

.husky/pre-commit

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env sh
2+
# Pre-commit hook to run Snyk and Talisman scans, completing both before deciding to commit
3+
4+
# Function to check if a command exists
5+
command_exists() {
6+
command -v "$1" >/dev/null 2>&1
7+
}
8+
9+
# Check if Snyk is installed
10+
if ! command_exists snyk; then
11+
echo "Error: Snyk is not installed. Please install it and try again."
12+
exit 1
13+
fi
14+
15+
# Check if Talisman is installed
16+
if ! command_exists talisman; then
17+
echo "Error: Talisman is not installed. Please install it and try again."
18+
exit 1
19+
fi
20+
21+
# Allow bypassing the hook with an environment variable
22+
if [ "$SKIP_HOOK" = "1" ]; then
23+
echo "Skipping Snyk and Talisman scans (SKIP_HOOK=1)."
24+
exit 0
25+
fi
26+
27+
# Initialize variables to track scan results
28+
snyk_failed=false
29+
talisman_failed=false
30+
31+
# Run Snyk vulnerability scan
32+
echo "Running Snyk vulnerability scan..."
33+
snyk test --all-projects > snyk_output.log 2>&1
34+
snyk_exit_code=$?
35+
36+
if [ $snyk_exit_code -eq 0 ]; then
37+
echo "Snyk scan passed: No vulnerabilities found."
38+
elif [ $snyk_exit_code -eq 1 ]; then
39+
echo "Snyk found vulnerabilities. See snyk_output.log for details."
40+
snyk_failed=true
41+
else
42+
echo "Snyk scan failed with error (exit code $snyk_exit_code). See snyk_output.log for details."
43+
snyk_failed=true
44+
fi
45+
46+
# Run Talisman secret scan (continues even if Snyk failed)
47+
echo "Running Talisman secret scan..."
48+
talisman --githook pre-commit > talisman_output.log 2>&1
49+
talisman_exit_code=$?
50+
51+
if [ $talisman_exit_code -eq 0 ]; then
52+
echo "Talisman scan passed: No secrets found."
53+
else
54+
echo "Talisman scan failed (exit code $talisman_exit_code). See talisman_output.log for details."
55+
talisman_failed=true
56+
fi
57+
58+
# Evaluate results after both scans
59+
if [ "$snyk_failed" = true ] || [ "$talisman_failed" = true ]; then
60+
echo "Commit aborted due to issues found in one or both scans."
61+
[ "$snyk_failed" = true ] && echo "- Snyk issues: Check snyk_output.log"
62+
[ "$talisman_failed" = true ] && echo "- Talisman issues: Check talisman_output.log"
63+
exit 1
64+
fi
65+
66+
# If both scans pass, allow the commit
67+
echo "All scans passed. Proceeding with commit.cd ."
68+
rm -f snyk_output.log talisman_output.log
69+
exit 0

.talismanrc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@ fileignoreconfig:
33
ignore_detectors:
44
- filecontent
55
- filename: package-lock.json
6-
checksum: a618ae6c113021eef425f224f1dfd7066b15af1a45249ea063a193517ce5a92f
7-
version: ""
6+
checksum: 37742c5c56859fdfed906c14e97881c4a10e0a52464fda489e4eb8154298fde4
7+
- filename: .husky/pre-commit
8+
checksum: 5baabd7d2c391648163f9371f0e5e9484f8fb90fa2284cfc378732ec3192c193
9+
version: ""
10+
base64_entropy: false

package-lock.json

Lines changed: 28 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"author": "Contentstack Ecosystem <[email protected]>",
33
"name": "@contentstack/datasync-mongodb-sdk",
4-
"version": "1.0.11",
4+
"version": "1.0.12",
55
"description": "Mongodb query wrapper around contents synced via @contentstack/content-store-mongodb",
66
"main": "dist/index.js",
77
"scripts": {
@@ -11,6 +11,7 @@
1111
"watch-ts": "npm run clean && tsc -w",
1212
"compile": "tsc",
1313
"prepare": "npm run compile",
14+
"pre-commit": "husky install && husky && chmod +x .husky/pre-commit",
1415
"start": "dist/index.js",
1516
"tslint": "npx tslint -c tslint.json 'src/**/*.ts' --fix",
1617
"test": "jest"
@@ -19,14 +20,15 @@
1920
"dependencies": {
2021
"lodash": "^4.17.21",
2122
"mongodb": "^6.12.0",
22-
"sift": "^17.1.3"
23+
"sift": "^17.1.3"
2324
},
2425
"devDependencies": {
2526
"@types/jest": "29.5.14",
2627
"@types/lodash": "4.17.14",
2728
"@types/node": "10.17.60",
2829
"@types/rimraf": "4.0.5",
2930
"debug": "^4.4.0",
31+
"husky": "^9.1.7",
3032
"jest": "^29.7.0",
3133
"jsdoc": "^4.0.4",
3234
"node-notifier": "^10.0.1",

src/messages.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Centralized error messages and warnings for the DataSync MongoDB SDK
3+
* This file contains all user-facing messages for consistency and maintainability
4+
*/
5+
6+
export const ErrorMessages = {
7+
// Configuration errors
8+
INVALID_MONGODB_URI: (uri: any) => `MongoDB connection URL: ${uri} must be of type string`,
9+
INVALID_DBNAME: 'Content store dbName should be of type string and not empty',
10+
11+
// Sorting errors
12+
INVALID_ASCENDING_PARAMS: 'Invalid parameters for .ascending(). Expected a valid string field name',
13+
INVALID_DESCENDING_PARAMS: 'Invalid parameters for .descending(). Expected a valid string field name',
14+
15+
// Language errors
16+
INVALID_LANGUAGE_PARAMS: 'Invalid parameters for .language(). Expected a valid language code string',
17+
18+
// Logical operator errors
19+
INVALID_AND_PARAMS: 'Invalid parameters for .and(). Expected an array of query objects',
20+
INVALID_OR_PARAMS: 'Invalid parameters for .or(). Expected an array of query objects',
21+
22+
// Comparison operator errors
23+
INVALID_LESSTHAN_PARAMS: 'Invalid key or value parameters for .lessThan(). Expected a string key and a value',
24+
INVALID_LESSTHAN_OR_EQUAL_PARAMS: 'Invalid key or value parameters for .lessThanOrEqualTo(). Expected a string key and a value',
25+
INVALID_GREATERTHAN_PARAMS: 'Invalid key or value parameters for .greaterThan(). Expected a string key and a value',
26+
INVALID_GREATERTHAN_OR_EQUAL_PARAMS: 'Invalid key or value parameters for .greaterThanOrEqualTo(). Expected a string key and a value',
27+
INVALID_NOTEQUAL_PARAMS: 'Invalid key or value parameters for .notEqualTo(). Expected a string key and a value',
28+
INVALID_CONTAINED_IN_PARAMS: 'Invalid key or value parameters for .containedIn(). Expected a string key and an array value',
29+
INVALID_NOT_CONTAINED_IN_PARAMS: 'Invalid key or value parameters for .notContainedIn(). Expected a string key and an array value',
30+
INVALID_EXISTS_PARAMS: 'Invalid key parameter for .exists(). Expected a valid string field name',
31+
INVALID_NOT_EXISTS_PARAMS: 'Invalid key parameter for .notExists(). Expected a valid string field name',
32+
33+
// Content type errors
34+
MISSING_CONTENT_TYPE_UID: 'Content type UID is required. Please provide a valid content type UID',
35+
MISSING_CONTENT_TYPE_FOR_ENTRY: 'Please call .contentType() before .entry()',
36+
MISSING_CONTENT_TYPE_FOR_ENTRIES: 'Please call .contentType() before .entries()',
37+
38+
// Pagination errors
39+
INVALID_LIMIT_VALUE: 'Invalid value for .limit(). Expected a positive numeric value',
40+
INVALID_SKIP_VALUE: 'Invalid value for .skip(). Expected a non-negative numeric value',
41+
42+
// Projection errors
43+
INVALID_ONLY_PARAMS: 'Invalid field values for .only(). Expected a non-empty array of field names',
44+
INVALID_EXCEPT_PARAMS: 'Invalid field values for .except(). Expected a non-empty array of field names',
45+
46+
// Query errors
47+
INVALID_REGEX_PARAMS: 'Invalid field or pattern parameters for .regex(). Expected string values for both field and pattern',
48+
INVALID_TAGS_PARAMS: 'Invalid field values for .tags(). Expected an array of tag values',
49+
INVALID_WHERE_PARAMS: 'Invalid expression for .where(). Expected a valid expression or function',
50+
INVALID_QUERY_REFERENCES_PARAMS: 'Invalid query object for .queryReferences(). Expected a valid query object',
51+
INVALID_INCLUDE_PARAMS: 'Invalid reference field path for .include(). Expected a valid string or array of strings',
52+
53+
// Query validation errors
54+
INVALID_QUERY: 'Invalid query provided. Please ensure your query is properly formatted',
55+
INVALID_QUERIES: 'Invalid queries provided. Please ensure all queries are properly formatted',
56+
} as const
57+
58+
export const WarningMessages = {
59+
// Performance warnings
60+
SLOW_INCLUDE_REFERENCES: '.includeReferences(...) is a relatively slow query. Consider limiting the depth or using .include() for specific references',
61+
} as const
62+

0 commit comments

Comments
 (0)