Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/options-type-validations #561

Draft
wants to merge 55 commits into
base: feature/websockets
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
f4cf05e
Merge pull request #553 from highcharts/master
cvasseng Aug 2, 2024
999c504
Merge pull request #555 from highcharts/master
cvasseng Aug 5, 2024
88cb2ac
Add necessary msg and public directory to distribution.
jszuminski Aug 5, 2024
0497b27
Merge pull request #557 from highcharts/bugfix/distribution-files
PaulDalek Aug 5, 2024
fc10da5
Small corrections.
PaulDalek Aug 5, 2024
93d225f
Merge pull request #558 from highcharts/master
cvasseng Aug 5, 2024
6f1be5c
Build the dist files after merge.
actions-user Aug 5, 2024
e740944
Merge pull request #559 from highcharts/fix/changelog-4.0.2
cvasseng Aug 5, 2024
23ce55a
Merge pull request #560 from highcharts/master
cvasseng Aug 5, 2024
6f8ed0c
Expanded and added new type validators for envs and options along wit…
PaulDalek Aug 5, 2024
f83659b
Overall enhancements of validators and tests both for options from co…
PaulDalek Aug 13, 2024
a936674
Versions update.
PaulDalek Aug 13, 2024
dcc4876
Corrections in validators and tests.
PaulDalek Aug 21, 2024
dcb7bc9
Further validators and tests optimizations.
PaulDalek Aug 23, 2024
bfacbcd
Renamed envs.js to validate.js plus some corrections.
PaulDalek Aug 26, 2024
050b308
Implemented validation into the code along with many fixes and optimi…
PaulDalek Aug 29, 2024
b6316b8
Added #562, cache path option now supports absolute paths.
jszuminski Sep 2, 2024
fdae737
Touch #562: update changelog, docs, add code note.
jszuminski Sep 2, 2024
fbcffab
Tests: minor cleanup.
jszuminski Sep 2, 2024
d2c619d
Big number of fixes, corrections and enhancements.
PaulDalek Sep 17, 2024
184ac54
ExportError: add statusCode to constructor, improve basic status codes.
jszuminski Sep 18, 2024
c708bc7
Errors: Throw 400s for all client-caused errors instead of 500s.
jszuminski Sep 19, 2024
e04c30f
Fixed RasterizationTimeout from 500 to 408.
jszuminski Sep 19, 2024
853b311
Error status: rasterization timeout switched from 500 to 408.
jszuminski Sep 26, 2024
3194faa
Merge pull request #577 from highcharts/fix/error-handling-status
cvasseng Sep 26, 2024
36b5769
Added note on public export server
cvasseng Sep 26, 2024
a281b4c
Merge pull request #581 from highcharts/master
cvasseng Sep 26, 2024
28b8f88
Build the dist files after merge.
actions-user Sep 26, 2024
f6cef24
Further options and validators corrections and enhancements.
PaulDalek Oct 1, 2024
fc75980
Add fair usage policy to the public/index.html
jszuminski Oct 7, 2024
4739643
Added missing envs, validation middleware, validation enhancements, o…
PaulDalek Oct 9, 2024
d095dc0
First portion of fixes and optimizations.
PaulDalek Oct 16, 2024
5a2f159
Further fixes and optimizations.
PaulDalek Oct 17, 2024
0a25484
Logs readability and other smaller corrections.
PaulDalek Oct 18, 2024
d6b65c6
Improvements in the resource creation.
PaulDalek Oct 21, 2024
dbc8ee7
Removed the dist folder.
PaulDalek Oct 21, 2024
e8232fb
Merge branch 'master' into public/add-fair-usage-policy-link
jszuminski Oct 22, 2024
74fb4cf
Add note about the license to the fair usage policy note.
jszuminski Oct 22, 2024
cd3fdce
Add integrity and crossorigin properties to script for improved secur…
jszuminski Oct 22, 2024
0c34ece
Merge pull request #583 from highcharts/public/add-fair-usage-policy-…
jszuminski Oct 22, 2024
7270403
Merge pull request #576 from highcharts/feat/562-support-for-absolute…
PaulDalek Oct 23, 2024
4688a0a
Merge pull request #586 from highcharts/fix/memory-leak
PaulDalek Oct 23, 2024
bdbd56c
Merge remote-tracking branch 'origin/master' into fix/options-type-va…
PaulDalek Oct 23, 2024
f566663
fix: add additional error check in exportAsString for chartJSON
jszuminski Oct 28, 2024
35fbb37
chore: minor cleanup
jszuminski Oct 29, 2024
371d057
fix: export error raw input set to 400
jszuminski Oct 29, 2024
55c59e5
update changelog for v4.0.3
jszuminski Oct 29, 2024
110c3e6
chore: version bump to v4.0.3
jszuminski Oct 29, 2024
0e3da2b
Added some missing codes.
PaulDalek Oct 29, 2024
7ff083a
Merge pull request #588 from highcharts/bugfix/improper-status-code
PaulDalek Oct 29, 2024
964c7cb
Merge pull request #589 from highcharts/docs/update-changelog
PaulDalek Oct 29, 2024
9f9761c
fix: set allowed origin methods to POST, GET, OPTIONS
jszuminski Oct 30, 2024
d61b462
Merge pull request #590 from highcharts/fix/server-allowed-methods
PaulDalek Oct 30, 2024
7a22f18
Packages update.
PaulDalek Nov 4, 2024
33626cb
Master changes.
PaulDalek Nov 4, 2024
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
26 changes: 25 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1,24 +1,46 @@
# PUPPETEER CONFIG
PUPPETEER_ARGS =

# HIGHCHARTS CONFIG
HIGHCHARTS_VERSION = latest
HIGHCHARTS_CDN_URL = https://code.highcharts.com/
HIGHCHARTS_FORCE_FETCH = false
HIGHCHARTS_CACHE_PATH = .cache
HIGHCHARTS_ADMIN_TOKEN =
HIGHCHARTS_CORE_SCRIPTS =
HIGHCHARTS_MODULE_SCRIPTS =
HIGHCHARTS_INDICATOR_SCRIPTS =
HIGHCHARTS_ADMIN_TOKEN =
HIGHCHARTS_CUSTOM_SCRIPTS =

# EXPORT CONFIG
EXPORT_INFILE =
EXPORT_INSTR =
EXPORT_OPTIONS =
EXPORT_SVG =
EXPORT_TYPE = png
EXPORT_CONSTR = chart
EXPORT_OUTFILE =
EXPORT_B64 = false
EXPORT_NO_DOWNLOAD = false
EXPORT_HEIGHT =
EXPORT_WIDTH =
EXPORT_SCALE =
EXPORT_DEFAULT_HEIGHT = 400
EXPORT_DEFAULT_WIDTH = 600
EXPORT_DEFAULT_SCALE = 1
EXPORT_GLOBAL_OPTIONS =
EXPORT_THEME_OPTIONS =
EXPORT_BATCH =
EXPORT_RASTERIZATION_TIMEOUT = 1500

# CUSTOM LOGIC CONFIG
CUSTOM_LOGIC_ALLOW_CODE_EXECUTION = false
CUSTOM_LOGIC_ALLOW_FILE_RESOURCES = false
CUSTOM_LOGIC_CUSTOM_CODE =
CUSTOM_LOGIC_CALLBACK =
CUSTOM_LOGIC_RESOURCES =
CUSTOM_LOGIC_LOAD_CONFIG =
CUSTOM_LOGIC_CREATE_CONFIG =

# SERVER CONFIG
SERVER_ENABLE = false
Expand Down Expand Up @@ -57,6 +79,7 @@ POOL_IDLE_TIMEOUT = 30000
POOL_CREATE_RETRY_INTERVAL = 200
POOL_REAPER_INTERVAL = 1000
POOL_BENCHMARKING = false
POOL_RESOURCES_INTERVAL = 30000

# LOGGING CONFIG
LOGGING_LEVEL = 4
Expand All @@ -75,6 +98,7 @@ OTHER_LISTEN_TO_PROCESS_EXITS = true
OTHER_NO_LOGO = false
OTHER_HARD_RESET_PAGE = false
OTHER_BROWSER_SHELL_MODE = true
OTHER_CONNECTION_OVER_PIPE = false

# DEBUG CONFIG
DEBUG_ENABLE = false
Expand Down
3 changes: 2 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = {
],
rules: {
'no-unused-vars': 'off',
'import/no-cycle': 'error'
'import/no-cycle': 'error',
'import/no-named-as-default': 'off'
}
};
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
samples/cli/infile_not_json.json
samples/cli/infileNotJson.json
node_modules/
dist/
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# 4.0.3

_New Features:_

- Added support for absolute paths in the `HIGHCHARTS_CACHE_PATH` option [(#562)](https://github.com/highcharts/node-export-server/issues/562)

_Fixes_:

- Improved status codes (user errors instead of 500) [(#577)](https://github.com/highcharts/node-export-server/pull/577)

- Improved memory management/usage [(#586)](https://github.com/highcharts/node-export-server/pull/586)

_Other:_

- Add fair usage policy note on the page [(#583)](https://github.com/highcharts/node-export-server/pull/583)

# 4.0.2

_Hotfix_:

- Fixed missing 'msg' and 'public' bundle in 4.0.1 on NPM.

_Fixes:_

- Made chart userOptions available within `customCode` as variable `options` [(#551)](https://github.com/highcharts/node-export-server/issues/551).
Expand Down
196 changes: 120 additions & 76 deletions README.md

Large diffs are not rendered by default.

69 changes: 32 additions & 37 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ See LICENSE file in root for details.

*******************************************************************************/

import main from '../lib/index.js';
import { singleExport, batchExport } from '../lib/chart.js';
import { setOptions } from '../lib/config.js';
import { initExport } from '../lib/index.js';
import { log, logWithStack } from '../lib/logger.js';
import { manualConfig } from '../lib/prompts.js';
import { shutdownCleanUp } from '../lib/resourceRelease.js';
import { printLogo, printVersion } from '../lib/utils.js';
import { printUsage } from '../lib/schemas/config.js';
import { startServer } from '../lib/server/server.js';

import ExportError from '../lib/errors/ExportError.js';

Expand All @@ -24,29 +32,27 @@ import ExportError from '../lib/errors/ExportError.js';
* @throws {Error} Throws an Error if an unexpected error occurs during
* execution.
*/
const start = async () => {
async function start() {
try {
// Get the CLI arguments
const args = process.argv;

// Display version information if requested
if (
['-v', '--v', '-version', '--version'].includes(args[args.length - 1])
) {
if (['-v', '--v'].includes(args[args.length - 1])) {
// Print logo with the version information
return main.printVersion();
return printVersion();
}

// Display help information if requested
if (['-h', '--h', '-help', '--help'].includes(args[args.length - 1])) {
if (['-h', '--h'].includes(args[args.length - 1])) {
// Print logo with the version information
return main.printUsage();
return printUsage();
}

// Print logo with a version and usage information if no arguments supplied
if (args.length <= 2) {
main.printUsage();
return main.log(
printUsage();
return log(
2,
'[cli] The number of provided arguments is too small. Please refer to the help section above.'
);
Expand All @@ -57,69 +63,58 @@ const start = async () => {
// 2. Options from a custom JSON file (loaded by the --loadConfig argument)
// 3. Options from the environment variables (the .env file)
// 4. Options from the CLI
const options = main.setOptions(null, args);
const options = setOptions(null, args, true);

// If all options correctly parsed
if (options) {
// Print initial logo or text
main.printLogo(options.other.noLogo);
printLogo(options.other.noLogo);

// In this case we want to prepare config manually
if (options.customLogic.createConfig) {
return main.manualConfig(options.customLogic.createConfig);
return manualConfig(options.customLogic.createConfig);
}

// Start server
if (options.server.enable) {
// Init the export mechanism for the server configuration
await main.initExport(options);
await initExport(options);

// Run the server
await main.startServer(options.server);
await startServer(options.server);
} else {
// Perform batch exports
if (options.export.batch) {
// If not set explicitly, use default option for batch exports
if (!args.includes('--minWorkers', '--maxWorkers')) {
options.pool = {
...options.pool,
minWorkers: 2,
maxWorkers: 25
};
}

// Init a pool for the batch exports
await main.initExport(options);
await initExport(options);

// Start batch exports
await main.batchExport(options);
await batchExport(options);
} else {
// No need for multiple workers in case of a single CLI export
options.pool = {
...options.pool,
minWorkers: 1,
maxWorkers: 1
};
options.pool.minWorkers = 1;
options.pool.maxWorkers = 1;

// Init a pool for one export
await main.initExport(options);
await initExport(options);

// Start a single export
await main.singleExport(options);
await singleExport(options);
}
}
} else {
throw new ExportError(
'[cli] No valid options provided. Please check your input and try again.'
'[cli] No valid options provided. Please check your input and try again.',
400
);
}
} catch (error) {
// Log the error with stack
main.logWithStack(1, error);
logWithStack(1, error);

// Gracefully shut down the process
await main.shutdownCleanUp(1);
await shutdownCleanUp(1);
}
};
}

start();
5 changes: 4 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
export default {
/** @type {import('jest').Config} */
const config = {
testEnvironment: 'jest-environment-node',
testMatch: ['**/tests/unit/**/*.test.js'],
transform: {
// '^.+\\.test.js?$': 'babel-jest'
}
};

export default config;
Loading
Loading