@ind-rcg/backend 246.1008.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/LICENSE.md +37 -0
  2. package/README.md +7 -0
  3. package/bin/libsqliteExtension.dll +0 -0
  4. package/bin/libsqliteExtension.dylib +0 -0
  5. package/binding.gyp +21 -0
  6. package/configuration.template.json +24 -0
  7. package/log4js.json +11 -0
  8. package/nativeSrc/PriceEngineWrap.cc +157 -0
  9. package/nativeSrc/PriceEngineWrap.h +24 -0
  10. package/nativeSrc/common/DBAccess/SimpleDBConnection.cpp +800 -0
  11. package/nativeSrc/common/DBAccess/SimpleDBConnection.h +54 -0
  12. package/nativeSrc/common/Libs/cJSON/CHANGELOG.md +428 -0
  13. package/nativeSrc/common/Libs/cJSON/LICENSE +20 -0
  14. package/nativeSrc/common/Libs/cJSON/README.md +571 -0
  15. package/nativeSrc/common/Libs/cJSON/cJSON.c +3110 -0
  16. package/nativeSrc/common/Libs/cJSON/cJSON.h +293 -0
  17. package/nativeSrc/common/Libs/sqlcipher/sqlite3.c +241624 -0
  18. package/nativeSrc/common/Libs/sqlcipher/sqlite3.h +12836 -0
  19. package/nativeSrc/common/Libs/sqlcipher/sqlite3ext.h +701 -0
  20. package/nativeSrc/common/LogAdapter/LogAdapter.cpp +25 -0
  21. package/nativeSrc/common/LogAdapter/LogAdapter.h +20 -0
  22. package/nativeSrc/common/PriceEngine/PriceEngine.cpp +251 -0
  23. package/nativeSrc/common/PriceEngine/PriceEngine.h +67 -0
  24. package/nativeSrc/common/Utils/StringFormat.cpp +905 -0
  25. package/nativeSrc/common/Utils/StringFormat.h +116 -0
  26. package/nativeSrc/common/Utils/miniz/timer.cpp +165 -0
  27. package/nativeSrc/common/Utils/miniz/timer.h +40 -0
  28. package/nativeSrc/common/stdngm.h +92 -0
  29. package/nativeSrc/nativeWrapper.cc +15 -0
  30. package/package.json +70 -0
  31. package/src/argsParser.js +73 -0
  32. package/src/bootstrap.js +156 -0
  33. package/src/fsHelper.js +36 -0
  34. package/src/globalConfig.js +23 -0
  35. package/src/local.js +546 -0
  36. package/src/server.js +64 -0
  37. package/src/sfAttachmentsHandler.js +283 -0
  38. package/src/utils.js +91 -0
  39. package/src/zipHandler.js +153 -0
@@ -0,0 +1,156 @@
1
+ /*
2
+ * FILE_HEADER
3
+ */
4
+
5
+ "use strict";
6
+
7
+ const express = require('express');
8
+ const bodyParser = require('body-parser');
9
+ const local = require('./local');
10
+
11
+ const log = require('log4js').getLogger("bootstrap");
12
+ const pako = require('pako');
13
+ const _ = require('lodash');
14
+ const fs = require("fs");
15
+ const path = require("path");
16
+ const GlobalConfig = require('./globalConfig');
17
+ let fetch = null;
18
+ let salesforceInstanceURL;
19
+ //let salesforceAccessToken;
20
+
21
+ async function loadESModule() {
22
+ // eslint-disable-next-line no-shadow
23
+ fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
24
+ return fetch;
25
+ }
26
+
27
+ module.exports.setup = (webServerConfig) => {
28
+
29
+ // initialize local.js with web server config
30
+ return local.initialize(webServerConfig)
31
+ .then(() => {
32
+
33
+ // setup express app
34
+ let app = express();
35
+
36
+ app.use(bodyParser.json({ limit: '50mb' }));
37
+ app.use(bodyParser.raw({ type: 'application/octet-stream', limit: '50mb' }));
38
+
39
+ app.get('/', function (req, res) {
40
+ res.send('Backend server, version 1.0');
41
+ });
42
+
43
+ // add static endpoint to include the framework
44
+ // this makes usage of CORS plugins obsolete
45
+ // since backend and framework both run under the same port and adr.
46
+ webServerConfig.mountpoints.forEach(function (mountpoint) {
47
+ app.use(mountpoint.path, express.static(mountpoint.location));
48
+ });
49
+
50
+ loadESModule().then(() => {
51
+ app.post(['/Request', '/dba/Request'], function (req, res) {
52
+ local.performCall(req, res);
53
+ });
54
+
55
+ app.use(/\/ibe\/iws\/emu\/sfproxy.*/, function (req, res) {
56
+ let url = req.originalUrl.replace("/ibe/iws/emu/sfproxy", salesforceInstanceURL);
57
+ log.debug("PROXY - ", req.originalUrl, url, req.method);
58
+ req.headers.authorization = req.headers["x-authorization"];
59
+ delete req.headers["x-authorization"];
60
+ delete req.headers.host;
61
+ delete req.headers.origin;
62
+ delete req.headers.referer;
63
+
64
+ let options = { method: req.method, headers: req.headers };
65
+ if (req.method !== 'GET') {
66
+ let reqJson = JSON.stringify(req.body);
67
+ let encoded = pako.gzip(reqJson);
68
+ options['body'] = encoded;
69
+ }
70
+ if (req.originalUrl.includes('ContentVersion')) {
71
+ // TO DO: Review request modifications to accept all possible actions, like Picture taking feature
72
+ log.warn("The request is proxied for local HESA execution. Always include your localhost URL as CORS allowed origin in your org to prevent errors. " +
73
+ "Without CORS allowed URL, the picture taking feature won't work and synchronization fails.");
74
+ }
75
+ fetch(url, options)
76
+ .then((resp) => {
77
+ if (['application/octetstream','image/png', 'text/html; charset=UTF-8'].includes(resp.headers.get('content-type'))) {
78
+ resp.body.pipe(res);
79
+ return;
80
+ }
81
+ resp.json().then((jsonRes) => {
82
+ res.send(jsonRes);
83
+ }).catch((error) => {
84
+ log.error(`ERROR while reading json from ${url}`, error);
85
+ });
86
+ }).catch((error) => {
87
+ log.error(`ERROR while accessing ${url}`, error);
88
+ });
89
+ });
90
+ }, (error) => {
91
+ log.error("ERROR while loading node-fetch module", error);
92
+ });
93
+
94
+ app.post('/ibe/iws/emu/sfproxydata', (request, response) => {
95
+ let body = request.body;
96
+ salesforceInstanceURL = body.salesforceInstanceURL;
97
+ //salesforceAccessToken = body.salesforceAccesstoken;
98
+ response.writeHead(200, { 'Content-Type': 'application/json' });
99
+ response.end(JSON.stringify({success: true}));
100
+ });
101
+
102
+ const validateReferemceImageConfig = () => {
103
+ let validationResult = true;
104
+ if (_.isNil(webServerConfig.referenceImage)) {
105
+ log.error("ERROR: Looks like you haven’t specified an image file in referenceImage. Specify a PNG or JPEG file and try again.");
106
+ validationResult = false;
107
+ } else if (_.isNil(webServerConfig.referenceImagePath)) {
108
+ log.error("ERROR: Looks like you haven't specified a file path in referenceImagePath. Specify a file path and try again.");
109
+ validationResult = false;
110
+ } else {
111
+ const finalPath = path.isAbsolute(webServerConfig.referenceImagePath)?
112
+ path.join(webServerConfig.referenceImagePath, webServerConfig.referenceImage)
113
+ : path.resolve(webServerConfig.referenceImagePath, webServerConfig.referenceImage);
114
+ if (!fs.existsSync(finalPath)) {
115
+ log.error("ERROR: We couldn't find the file. Verify the file name or make sure that the file exists at the specified location.");
116
+ validationResult = false;
117
+ }
118
+ }
119
+ return validationResult;
120
+ };
121
+
122
+ // Check reference image config during setup
123
+ validateReferemceImageConfig();
124
+
125
+ const hesaFolderPath = `${GlobalConfig.AttachmentsFolder}/${GlobalConfig.hesaFolder}`;
126
+ if (fs.existsSync(hesaFolderPath)) {
127
+ fs.rmdirSync(hesaFolderPath, { recursive: true, force: true });
128
+ }
129
+ fs.mkdirSync(hesaFolderPath, { recursive: true, force: true });
130
+
131
+ app.get("/emu/picture", (req, res) => {
132
+ let temporalFileName = 'ReferenceImage.jpg';
133
+ if (validateReferemceImageConfig()) {
134
+ temporalFileName = `${new Date().getTime()}.${path.extname(webServerConfig.referenceImage)}`;
135
+ const sourcePath = path.isAbsolute(webServerConfig.referenceImagePath)?
136
+ path.join(webServerConfig.referenceImagePath, webServerConfig.referenceImage)
137
+ : path.resolve(webServerConfig.referenceImagePath, webServerConfig.referenceImage);
138
+ fs.copyFileSync(
139
+ sourcePath,
140
+ `${hesaFolderPath}/${temporalFileName}`
141
+ );
142
+ }
143
+ res.send(`{"success":true,"message":null,"results":"{\\"width\\":225,\\"height\\":225,\\"path\\":\\"hesa/${temporalFileName}\\"}"}`);
144
+ });
145
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
146
+ return Promise.resolve(app);
147
+ })
148
+ .catch(() => {
149
+ return Promise.reject(null);
150
+ });
151
+ };
152
+
153
+
154
+ module.exports.closeConnection = () => {
155
+ local.closeDBConnection();
156
+ };
@@ -0,0 +1,36 @@
1
+ /*
2
+ * FILE_HEADER
3
+ */
4
+
5
+ "use strict";
6
+
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+ const log = require('log4js').getLogger("fsHelper");
10
+
11
+ module.exports.readJsonFile = (filePath) => {
12
+
13
+ // Sanitizer method for JSON.parse action in readJSONFile
14
+ const sanitizer = (key, value) => {
15
+ const evilPattern = /[;`|&${}]/;
16
+ if (typeof value === 'string' && value.search(evilPattern) >= 0) {
17
+ log.error('Alert!!! - Command Injection suspected');
18
+ return null;
19
+ } else {
20
+ return value;
21
+ }
22
+ };
23
+
24
+ if (filePath) {
25
+ let resolvedPath = path.resolve(filePath);
26
+ if (fs.existsSync(resolvedPath)) {
27
+ let raw = fs.readFileSync(resolvedPath);
28
+ if (raw) {
29
+ // Use sanitizer method to prevent XSS injection in configurable attributes
30
+ return JSON.parse(raw, sanitizer);
31
+ }
32
+ }
33
+ }
34
+
35
+ return null;
36
+ };
@@ -0,0 +1,23 @@
1
+ /*
2
+ * FILE_HEADER
3
+ */
4
+
5
+ "use strict";
6
+
7
+ const GlobalConfig = new function(){
8
+ this.AttachmentsFolder = "Attachments";
9
+ this.SFFilesBlobFolder = "SFFilesBlob";
10
+ this.ThumbnailsFolder = "Thumbnails";
11
+ this.ThemeImagesFolder = "ThemeImages";
12
+ this.hesaFolder = "hesa";
13
+ this.BlobFolder = "Blob";
14
+
15
+ this.MAX_PARAM_STRING_LENGTH = 100;
16
+ this.MAX_FILE_PATH_LENGTH = 500;
17
+ this.MAX_FILE_SIZE = 50; // in MB
18
+
19
+ this.validThemeFolders = ['Application', 'Framework'];
20
+ this.validFileTypesForThemes = ['svg', 'png', 'gif'];
21
+ }();
22
+
23
+ module.exports = GlobalConfig;