Skip to content

Commit

Permalink
Merge pull request #268 from contentstack/development
Browse files Browse the repository at this point in the history
DX | 27-01-2025 | Release
  • Loading branch information
cs-raj authored Jan 21, 2025
2 parents 9341dc8 + be96351 commit 6c0266c
Show file tree
Hide file tree
Showing 14 changed files with 1,592 additions and 1,566 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
The MIT License (MIT)


Copyright (c) 2016-2024 Contentstack
Copyright (c) 2016-2025 Contentstack

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2,913 changes: 1,422 additions & 1,491 deletions package-lock.json

Large diffs are not rendered by default.

39 changes: 19 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "contentstack",
"version": "3.23.0",
"version": "3.24.0",
"description": "Contentstack Javascript SDK",
"homepage": "https://www.contentstack.com/",
"author": {
Expand Down Expand Up @@ -65,46 +65,45 @@
"tmp": "tmp/contentstack-3.15.0.tgz_1477830884275_0.9869455888401717"
},
"devDependencies": {
"@babel/core": "^7.25.9",
"@babel/preset-env": "^7.25.9",
"@babel/runtime": "^7.25.9",
"@slack/bolt": "^3.22.0",
"@babel/core": "^7.26.0",
"@babel/preset-env": "^7.26.0",
"@babel/runtime": "^7.26.0",
"@slack/bolt": "^4.2.0",
"@types/jest": "^26.0.24",
"babel-loader": "^9.2.1",
"clean-webpack-plugin": "^4.0.0",
"compression-webpack-plugin": "^10.0.0",
"dotenv": "^16.4.5",
"compression-webpack-plugin": "^11.1.0",
"dotenv": "^16.4.7",
"es3ify-loader": "0.2.0",
"fetch-mock-jest": "^1.5.1",
"http-proxy-agent": "^3.0.0",
"http-proxy-agent": "^7.0.2",
"jest": "^29.7.0",
"jest-html-reporters": "^2.1.7",
"jest-html-reporters": "^3.1.7",
"jsdoc": "^4.0.4",
"jshint": "^2.13.6",
"minami": "^1.2.3",
"node-request-interceptor": "^0.6.3",
"nodemailer": "^6.9.15",
"nodemailer": "^6.9.16",
"string-replace-loader": "^3.1.0",
"tap-html": "^1.1.0",
"tap-json": "1.0.0",
"tape": "4.17.0",
"terser-webpack-plugin": "^5.3.10",
"terser-webpack-plugin": "^5.3.11",
"ts-jest": "^29.2.5",
"typescript": "^4.9.5",
"uglify-js": "2.8.29",
"webpack": "^5.95.0",
"webpack-cli": "^4.10.0",
"webpack-md5-hash": "0.0.5",
"webpack-merge": "4.1.5",
"uglify-js": "3.19.3",
"webpack": "^5.97.1",
"webpack-cli": "^6.0.1",
"webpack-md5-hash": "0.0.6",
"webpack-merge": "6.0.1",
"webpack-node-externals": "^3.0.0"
},
"dependencies": {
"@contentstack/utils": "^1.3.12",
"@contentstack/utils": "^1.3.15",
"cheerio": "^1.0.0",
"es6-promise": "^4.2.8",
"fetch-mock": "^11.1.5",
"isomorphic-fetch": "^3.0.0",
"fetch-mock": "^12.2.0",
"localStorage": "1.0.4",
"qs": "^6.13.0"
"qs": "^6.14.0"
}
}
91 changes: 91 additions & 0 deletions sanity-report-dev11.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
const fs = require("fs");
const dotenv = require("dotenv");
const cheerio = require("cheerio");

dotenv.config();

const user1 = process.env.USER1;
const user2 = process.env.USER2;
const user3 = process.env.USER3;
const user4 = process.env.USER4;

const tapHtmlContent = fs.readFileSync("./tap-html.html", "utf8");
const $ = cheerio.load(tapHtmlContent);

const totalCount = $(".nav a:nth-child(2)")
.text()
.trim()
.replace("Total Count", "");
const totalPass = $(".nav a:nth-child(3)")
.text()
.trim()
.replace("Total Pass", "");
const totalFail = $(".nav a:nth-child(4)")
.text()
.trim()
.replace("Total Fail", "");

const totalTime = $(".nav a:nth-child(1)")
.text()
.trim()
.replace("Total Time", "");

const milliseconds = parseInt(totalTime.replace(/\D/g, ''), 10);
const totalSeconds = Math.floor(milliseconds / 1000);
const durationInMinutes = Math.floor(totalSeconds / 60);
const durationInSeconds = totalSeconds % 60;

const passedTests = parseInt(totalPass, 10);
const totalTests = parseInt(totalCount, 10);

const resultMessage =
passedTests === totalTests
? `:white_check_mark: Success (${passedTests} / ${totalTests} Passed)`
: `:x: Failure (${passedTests} / ${totalTests} Passed)`;

const pipelineName = process.env.GO_PIPELINE_NAME;
const pipelineCounter = process.env.GO_PIPELINE_COUNTER;
const goCdServer = process.env.GOCD_SERVER;

const reportUrl = `http://${goCdServer}/go/files/${pipelineName}/${pipelineCounter}/sanity/1/sanity/test-results/tap-html.html`;

let tagUsers = ``;
if (totalFail > 0) {
tagUsers = `<@${user1}> <@${user2}> <@${user3}> <@${user4}>`;
}

const slackMessage = {
text: `Dev11, CDA SDK Full Sanity
*Result:* ${resultMessage}. ${durationInMinutes}m ${durationInSeconds}s
*Failed Tests:* ${totalFail}
<${reportUrl}|View Report>
${tagUsers}`,
};

const slackWebhookUrl = process.env.SLACK_WEBHOOK_URL;

const sendSlackMessage = async (message) => {
const payload = {
text: message,
};

try {
const response = await fetch(slackWebhookUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
});

if (!response.ok) {
throw new Error(`Error sending message to Slack: ${response.statusText}`);
}

console.log("Message sent to Slack successfully");
} catch (error) {
console.error("Error:", error);
}
};

sendSlackMessage(slackMessage.text);
4 changes: 2 additions & 2 deletions sanity-report.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require('fs');
const Slack = require('@slack/bolt')
const { App } = require('@slack/bolt');
const dotenv = require('dotenv')
dotenv.config()

Expand Down Expand Up @@ -39,7 +39,7 @@ const slackMessage = `
• Total Duration: *${durationInMinutes}m ${durationInSeconds}s*
`

const app = new Slack.App({
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET
})
Expand Down
14 changes: 13 additions & 1 deletion src/core/contentstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,19 @@ class Contentstack {
}
}
}
x(entry[key].children);
let _entry = {...entry};
const keys = key.split(".");
for (const k of keys) {
if (_entry[k]) _entry = _entry[k];
else if (_entry.length) {
for (const block of _entry) {
if (block[k]) {
_entry = block[k];
}
}
}
}
if (_entry.children) x(_entry.children);
if (correspondingAsset) {
correspondingAsset['href'] = item.url;
}
Expand Down
3 changes: 1 addition & 2 deletions src/runtime/node/http.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import ES6Promise from 'es6-promise';
import fetch from 'node-fetch';

ES6Promise.polyfill();

export default fetch;
export default fetch; // fetch API available in Node.js 18 and later
3 changes: 1 addition & 2 deletions src/runtime/web/http.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ES6Promise from 'es6-promise';
import fetch from 'isomorphic-fetch';
ES6Promise.polyfill();

export default fetch;
export default fetch; // fetch API available in Node.js 18 and later
38 changes: 9 additions & 29 deletions test/entry/findone.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,55 +743,35 @@ test('findOne: .except() - For the reference - Array', function(assert) {
* HTTP Error Handling
* !*/

test('findOne: should handle 404 Not Found error', function(assert) {
const Query = Stack.ContentType(contentTypes.invalid_type).Query();
test('findOne: should handle 422 Unprocessable Entity error', function(assert) {
const Query = Stack.ContentType("invalid_content_type").Query();

Query
.toJSON()
.findOne()
.then(function success() {
assert.fail("Expected 404 error but got a successful response.");
assert.fail("Expected 422 error but got a successful response.");
assert.end();
}, function error(err) {
assert.equal(err.http_code, 404, 'Should return HTTP status 404.');
assert.ok(err.http_message, 'Error message should be present.');
console.error("Error:", err.http_message);
assert.equal(err.http_code, 422, 'Should return HTTP status 422.');
assert.ok(err.http_message, 'Unprocessable Entity');
assert.end();
});
});

test('findOne: should handle 401 Unauthorized error', function(assert) {
test('findOne: should handle 412 Unauthorized error', function(assert) {
Stack.headers = { authorization: 'InvalidAPIKey' }; // Simulating an invalid API key
const Query = Stack.ContentType(contentTypes.source).Query();

Query
.toJSON()
.findOne()
.then(function success() {
assert.fail("Expected 401 error but got a successful response.");
assert.fail("Expected 412 error but got a successful response.");
assert.end();
}, function error(err) {
assert.equal(err.http_code, 401, 'Should return HTTP status 401.');
assert.ok(err.http_message, 'Error message should be present.');
console.error("Error:", err.http_message);
assert.equal(err.http_code, 412, 'Should return HTTP status 412.');
assert.ok(err.http_message, 'Precondition Failed.');
assert.end();
});
});

test('findOne: should handle 500 Internal Server Error', function(assert) {
const mockStack = Contentstack.Stack({ ...init.stack, host: 'invalid.host' }); // Simulating a server error
const Query = mockStack.ContentType(contentTypes.source).Query();

Query
.toJSON()
.findOne()
.then(function success() {
assert.fail("Expected 500 error but got a successful response.");
assert.end();
}, function error(err) {
assert.equal(err.http_code, 500, 'Should return HTTP status 500.');
assert.ok(err.http_message, 'Error message should be present.');
console.error("Error:", err.http_message);
assert.end();
});
});
5 changes: 4 additions & 1 deletion webpack/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ module.exports = function(options) {
protectWebpackAssets: false,
cleanAfterEveryBuildPatterns: ['*.LICENSE.txt']
})
]
],
optimization: {
minimize: false, // Prevents code compression/minification
},
};
}
9 changes: 6 additions & 3 deletions webpack/webpack.nativescript.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';

const path = require('path');
const webpackMerge = require('webpack-merge');
const { merge } = require('webpack-merge');
var nodeExternals = require('webpack-node-externals');

const commonConfig = require('./webpack.common.js');

module.exports = function(options) {
return webpackMerge(commonConfig(), {
return merge(commonConfig(), {
output: {
libraryTarget: "commonjs2",
path: path.join(__dirname, "../dist/nativescript"),
Expand Down Expand Up @@ -50,6 +50,9 @@ module.exports = function(options) {
}
],
}]
}
},
optimization: {
minimize: false, // Prevents code compression/minification
},
});
}
7 changes: 5 additions & 2 deletions webpack/webpack.node.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';
const path = require('path');
const webpackMerge = require('webpack-merge');
const { merge } = require('webpack-merge');
var nodeExternals = require('webpack-node-externals');

const commonConfig = require('./webpack.common.js');

module.exports = function(options) {
return webpackMerge(commonConfig(), {
return merge(commonConfig(), {
output: {
libraryTarget: "commonjs2",
path: path.join(__dirname, "../dist/node"),
Expand Down Expand Up @@ -49,5 +49,8 @@ module.exports = function(options) {
}],
}]
},
optimization: {
minimize: false, // Prevents code compression/minification
},
});
}
Loading

0 comments on commit 6c0266c

Please sign in to comment.