@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
package/LICENSE.md ADDED
@@ -0,0 +1,37 @@
1
+ ## License
2
+
3
+ Copyright (c) 2023, Salesforce, Inc.
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without modification,
7
+ are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice, this
13
+ list of conditions and the following disclaimer in the documentation and/or
14
+ other materials provided with the distribution.
15
+
16
+ * Neither the name of Salesforce.com nor the names of its contributors may be
17
+ used to endorse or promote products derived from this software without specific
18
+ prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
24
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
27
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+
31
+ ## Security
32
+
33
+ Please report any security issue to [security@salesforce.com](mailto:security@salesforce.com)
34
+ as soon as it is discovered. This library limits its runtime dependencies in
35
+ order to reduce the total cost of ownership as much as can be, but all consumers
36
+ should remain vigilant and have their security stakeholders review all third-party
37
+ products (3PP) like this one and their dependencies.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # Backend for Industries Consumer Goods Mobile application
2
+
3
+ This backend module is required to simulate the application of Consumer Goods Mobile Application. This modules can only be used in modeler-sfdx-cli-plugin.
4
+
5
+ # License
6
+ BSD-3-Clause
7
+
Binary file
Binary file
package/binding.gyp ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "targets": [
3
+ {
4
+ "target_name": "mobileNativeCode",
5
+ "sources": [ "nativeSrc/nativeWrapper.cc", "nativeSrc/common/stdngm.h", "nativeSrc/common/Utils/StringFormat.h", "nativeSrc/common/Utils/StringFormat.cpp",
6
+ "nativeSrc/common/Utils/miniz/timer.h","nativeSrc/common/Utils/miniz/timer.cpp", "nativeSrc/common/Libs/sqlcipher/sqlite3.h",
7
+ "nativeSrc/common/Libs/sqlcipher/sqlite3.c", "nativeSrc/common/Libs/cJSON/cJSON.h", "nativeSrc/common/Libs/cJSON/cJSON.c",
8
+ "nativeSrc/common/LogAdapter/LogAdapter.h", "nativeSrc/common/LogAdapter/LogAdapter.cpp","nativeSrc/common/DBAccess/SimpleDBConnection.h",
9
+ "nativeSrc/common/DBAccess/SimpleDBConnection.cpp", "nativeSrc/common/PriceEngine/PriceEngine.h", "nativeSrc/common/PriceEngine/PriceEngine.cpp",
10
+ "nativeSrc/PriceEngineWrap.cc", "PriceEngineWrap.h" ],
11
+ "include_dirs": ["<!(node -p \"require('node-addon-api').include_dir\")"],
12
+ "defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS", "NODE_ADDON_API_ENABLE_MAYBE" ],
13
+ "conditions": [['OS=="mac"', {
14
+ "cflags+": ["-fvisibility=hidden"],
15
+ "xcode_settings": {
16
+ "GCC_SYMBOLS_PRIVATE_EXTERN": "YES",
17
+ }
18
+ }]]
19
+ }
20
+ ]
21
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "port": 3000,
3
+ "mountpoints": [
4
+ {
5
+ "path": "/www",
6
+ "location": "/[OPTIONAL_INSERT_LOCAL_PATH_TO_SENCHA_FRAMEWORK_HERE]"
7
+ },
8
+ {
9
+ "path": "/framework",
10
+ "location": "../engineComponents"
11
+ },
12
+ {
13
+ "path": "/framework/Attachments",
14
+ "location": "./Attachments"
15
+ },
16
+ {
17
+ "path": "/framework/themeImages",
18
+ "location": "./ThemeImages"
19
+ }
20
+ ],
21
+ "database": "ngm.db3",
22
+ "referenceImage": "testImage1.jpg",
23
+ "referenceImagePath": "test/testdata"
24
+ }
package/log4js.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "appenders": {
3
+ "file": { "type": "file", "filename": "log/backend.log", "maxLogSize": 10485760, "numBackups": 3 },
4
+ "console":{"type": "console"},
5
+ "errorFile": { "type": "file", "filename": "log/errors.log" },
6
+ "errors": { "type": "logLevelFilter", "level": "ERROR", "appender": "errorFile" }
7
+ },
8
+ "categories": {
9
+ "default": { "appenders": ["console","file","errors"], "level": "all" }
10
+ }
11
+ }
@@ -0,0 +1,157 @@
1
+ /*
2
+ * FILE_HEADER
3
+ */
4
+
5
+ #include "PriceEngineWrap.h"
6
+ #include "common/PriceEngine/PriceEngine.h"
7
+ #include "common/LogAdapter/LogAdapter.h"
8
+
9
+ Napi::Object PriceEngineWrap::Init(Napi::Env env, Napi::Object exports) {
10
+ Napi::Function func =
11
+ DefineClass(env,
12
+ "PriceEngineWrap",{
13
+ InstanceMethod("openDbConnection", &PriceEngineWrap::OpenDbConnection),
14
+ InstanceMethod("closeDbConnection", &PriceEngineWrap::CloseDbConnection),
15
+ InstanceMethod("conditionSearch", &PriceEngineWrap::ConditionSearch)
16
+ });
17
+
18
+ Napi::FunctionReference* constructor = new Napi::FunctionReference();
19
+ *constructor = Napi::Persistent(func);
20
+ #ifndef WIN32
21
+ env.SetInstanceData(constructor);
22
+ #endif
23
+
24
+ exports.Set("PriceEngineWrap", func);
25
+ return exports;
26
+ }
27
+
28
+ PriceEngineWrap::PriceEngineWrap(const Napi::CallbackInfo& info)
29
+ : Napi::ObjectWrap<PriceEngineWrap>(info) {
30
+
31
+ }
32
+
33
+ void PriceEngineWrap::checkIsExceptionOccurred(const Napi::Env env) {
34
+ if(env.IsExceptionPending()) {
35
+ Napi::TypeError::New(env, "Something went wrong, we couldn’t create the Napi object. Check the code and try again.").ThrowAsJavaScriptException();
36
+ }
37
+ }
38
+
39
+ Napi::Array PriceEngineWrap::getNapiArray(const Napi::Env env, const std::vector<std::string> array) {
40
+ Napi::Array napiArray = Napi::Array::New(env, array.size());
41
+ checkIsExceptionOccurred(env);
42
+
43
+ for (int i = 0; i < (int)array.size(); i++) {
44
+ napiArray[i] = Napi::String::New(env, array[i]);
45
+ checkIsExceptionOccurred(env);
46
+ }
47
+
48
+ return napiArray;
49
+ }
50
+
51
+ Napi::Value PriceEngineWrap::OpenDbConnection(const Napi::CallbackInfo& info){
52
+ Napi::Env env = info.Env();
53
+ Napi::Object responseObject = Napi::Object::New(env);
54
+ checkIsExceptionOccurred(env);
55
+
56
+ Napi::Object resultObject = Napi::Object::New(env);
57
+ checkIsExceptionOccurred(env);
58
+
59
+ int length = info.Length();
60
+ std::vector<std::string> logMessageArray;
61
+
62
+ if (length <= 0 || !info[0].IsString()) {
63
+ logMessageArray.push_back("The database path is required. Specify the path to the database using string characters.");
64
+ resultObject.Set("messages", getNapiArray(env, logMessageArray));
65
+ responseObject.Set("success", false);
66
+ responseObject.Set("results", resultObject);
67
+ return responseObject;
68
+ }
69
+
70
+ Napi::String dbPath = info[0].As<Napi::String>();
71
+ bool isDBOpened = dbConnection.openConnection(dbPath.Utf8Value().c_str());
72
+ logMessageArray = LogAdapter::getInternalLogLines();
73
+ resultObject.Set("messages", getNapiArray(env, logMessageArray));
74
+ responseObject.Set("results", resultObject);
75
+
76
+ if(!isDBOpened) {
77
+ // error occured in opening db connection
78
+ responseObject.Set("success", false);
79
+ } else {
80
+ // db connection is opened successfully
81
+ responseObject.Set("success", true);
82
+ }
83
+
84
+ return responseObject;
85
+ }
86
+
87
+ Napi::Value PriceEngineWrap::CloseDbConnection(const Napi::CallbackInfo& info){
88
+ Napi::Env env = info.Env();
89
+ bool isClosed = dbConnection.close();
90
+ const std::vector<std::string>logMessageArray = LogAdapter::getInternalLogLines();
91
+
92
+ Napi::Object responseObject = Napi::Object::New(env);
93
+ checkIsExceptionOccurred(env);
94
+
95
+ Napi::Object resultObject = Napi::Object::New(env);
96
+ checkIsExceptionOccurred(env);
97
+
98
+ resultObject.Set("messages", getNapiArray(env, logMessageArray));
99
+ responseObject.Set("results", resultObject);
100
+
101
+ if(isClosed) {
102
+ // db connection is closed successfully
103
+ responseObject.Set("success", true);
104
+ } else {
105
+ // error occured in closing db connection
106
+ responseObject.Set("success", false);
107
+ }
108
+
109
+ return responseObject;
110
+ }
111
+
112
+ Napi::Value PriceEngineWrap::ConditionSearch(const Napi::CallbackInfo& info){
113
+ Napi::Env env = info.Env();
114
+ Napi::Object responseObject = Napi::Object::New(env);
115
+ checkIsExceptionOccurred(env);
116
+
117
+ Napi::Object resultObject = Napi::Object::New(env);
118
+ checkIsExceptionOccurred(env);
119
+
120
+ responseObject.Set("success", false);
121
+ int length = info.Length();
122
+ std::vector<std::string> logMessageArray;
123
+
124
+ if (length <= 0 || !info[0].IsString()) {
125
+ logMessageArray.push_back("A string specifying the search criteria is required. Provide a search string containing a stringified JSON object");
126
+ resultObject.Set("messages", getNapiArray(env, logMessageArray));
127
+ responseObject.Set("results", resultObject);
128
+ return responseObject;
129
+ }
130
+
131
+ if(!dbConnection.isValid()) {
132
+ logMessageArray.push_back("Open a database connection first, then pass the request.");
133
+ resultObject.Set("messages", getNapiArray(env, logMessageArray));
134
+ responseObject.Set("results", resultObject);
135
+ return responseObject;
136
+ }
137
+
138
+ Napi::String jsonString = info[0].As<Napi::String>();
139
+ PriceEngine pe;
140
+ pe.SetDBConnection(&dbConnection);
141
+
142
+ char* ret = pe.conditionSearch((char *)jsonString.Utf8Value().c_str());
143
+
144
+ logMessageArray = LogAdapter::getInternalLogLines();
145
+
146
+ resultObject.Set("messages", getNapiArray(env, logMessageArray));
147
+
148
+ if (ret) {
149
+ // success case
150
+ responseObject.Set("success", true);
151
+ resultObject.Set("conditions", ret);
152
+ free(ret);
153
+ }
154
+
155
+ responseObject.Set("results", resultObject);
156
+ return responseObject;
157
+ }
@@ -0,0 +1,24 @@
1
+ /*
2
+ * FILE_HEADER
3
+ */
4
+
5
+ #ifndef RCG_PriceEngine_Wrap_h
6
+ #define RCG_PriceEngine_Wrap_h
7
+ #include <napi.h>
8
+ #include "common/DBAccess/SimpleDBConnection.h"
9
+
10
+ class PriceEngineWrap : public Napi::ObjectWrap<PriceEngineWrap> {
11
+ public:
12
+ static Napi::Object Init(Napi::Env env, Napi::Object exports);
13
+ PriceEngineWrap(const Napi::CallbackInfo& info);
14
+
15
+ private:
16
+ Napi::Value Hello(const Napi::CallbackInfo& info);
17
+ Napi::Value OpenDbConnection(const Napi::CallbackInfo& info);
18
+ Napi::Value CloseDbConnection(const Napi::CallbackInfo& info);
19
+ Napi::Value ConditionSearch(const Napi::CallbackInfo& info);
20
+ Napi::Array getNapiArray(const Napi::Env env, const std::vector<std::string> array);
21
+ void checkIsExceptionOccurred(const Napi::Env env);
22
+ SimpleDBConnection dbConnection;
23
+ };
24
+ #endif