@gudhub/core 1.0.37

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 (67) hide show
  1. package/GUDHUB/Auth/Auth.js +137 -0
  2. package/GUDHUB/Auth/Auth.test.js +15 -0
  3. package/GUDHUB/Managers/ChunksManager/ChunksManager.js +80 -0
  4. package/GUDHUB/Managers/ChunksManager/ChunksManager.test.js +46 -0
  5. package/GUDHUB/Managers/DocumentManager/DocumentManager.js +48 -0
  6. package/GUDHUB/Managers/FileManager/FileManager.js +208 -0
  7. package/GUDHUB/Managers/FileManager/file_manager.test.js +17 -0
  8. package/GUDHUB/Managers/managers.js +5 -0
  9. package/GUDHUB/PipeService/PipeService.js +167 -0
  10. package/GUDHUB/PipeService/PipeService.test.js +64 -0
  11. package/GUDHUB/PipeService/utils.js +32 -0
  12. package/GUDHUB/Processors/AppProcessor/AppProcessor.js +433 -0
  13. package/GUDHUB/Processors/AppProcessor/AppProcessor.test.js +38 -0
  14. package/GUDHUB/Processors/AppProcessor/AppProcessorMocks.js +83 -0
  15. package/GUDHUB/Processors/FieldProcessor/FieldProcessor.js +139 -0
  16. package/GUDHUB/Processors/FieldProcessor/FieldProcessor.test.js +16 -0
  17. package/GUDHUB/Processors/FieldProcessor/Untitled-1.json +17 -0
  18. package/GUDHUB/Processors/FieldProcessor/field_processor.md +85 -0
  19. package/GUDHUB/Processors/ItemProcessor/ItemProcessor.js +247 -0
  20. package/GUDHUB/Processors/ItemProcessor/item_processor.md +50 -0
  21. package/GUDHUB/Processors/processors.js +5 -0
  22. package/GUDHUB/Storage/Storage.js +115 -0
  23. package/GUDHUB/Storage/Storage.test.js +112 -0
  24. package/GUDHUB/Utils/Utils.js +153 -0
  25. package/GUDHUB/Utils/compare_items_lists_worker/compare_items_lists.worker.js +50 -0
  26. package/GUDHUB/Utils/filter/filter.js +308 -0
  27. package/GUDHUB/Utils/filter/filter.test.js +94 -0
  28. package/GUDHUB/Utils/filter/filterPreparation.js +103 -0
  29. package/GUDHUB/Utils/filter/group.js +41 -0
  30. package/GUDHUB/Utils/filter/utils.js +119 -0
  31. package/GUDHUB/Utils/get_date/get_date.js +90 -0
  32. package/GUDHUB/Utils/get_date/get_date.test.js +53 -0
  33. package/GUDHUB/Utils/interpretation/interpretation.js +100 -0
  34. package/GUDHUB/Utils/json_constructor/json_constructor.js +130 -0
  35. package/GUDHUB/Utils/json_constructor/json_constructor.test.js +70 -0
  36. package/GUDHUB/Utils/json_to_items/json_to_items.js +161 -0
  37. package/GUDHUB/Utils/json_to_items/json_to_items.test.js +85 -0
  38. package/GUDHUB/Utils/merge_chunks/merge_chunks.js +30 -0
  39. package/GUDHUB/Utils/merge_compare_items/merge_compare_items.js +316 -0
  40. package/GUDHUB/Utils/merge_compare_items/merge_compare_items.test.js +632 -0
  41. package/GUDHUB/Utils/merge_objects/merge_objects.js +120 -0
  42. package/GUDHUB/Utils/merge_objects/merge_objects.test.js +137 -0
  43. package/GUDHUB/Utils/nested_list/nested_list.js +38 -0
  44. package/GUDHUB/Utils/nested_list/nested_list.test.js +70 -0
  45. package/GUDHUB/Utils/populate_items/populate_items.js +66 -0
  46. package/GUDHUB/WebSocket/WebSocket.js +136 -0
  47. package/GUDHUB/config.js +8 -0
  48. package/GUDHUB/consts.js +1 -0
  49. package/GUDHUB/gudhub-https-service.js +193 -0
  50. package/GUDHUB/gudhub.js +477 -0
  51. package/GUDHUB/gudhub.test.js +218 -0
  52. package/GUDHUB/utils.js +25 -0
  53. package/Readme.md +537 -0
  54. package/fake_server/fake_java_server.js +112 -0
  55. package/fake_server/fake_server_data/app_132.js +3037 -0
  56. package/fake_server/fake_server_data/app_16259.js +1152 -0
  57. package/fake_server/fake_server_data/app_214.js +2057 -0
  58. package/fake_server/fake_server_data/app_8263.js +4167 -0
  59. package/fake_server/fake_server_data/chunks_mocks/bcacjbgqorherqmtykrj_8263.js +44561 -0
  60. package/fake_server/fake_server_data/chunks_mocks/bcjyuoqaewybudfyhir_8263.js +44197 -0
  61. package/fake_server/fake_server_data/chunks_mocks/tpajkpolmzklodcba_8263.js +44977 -0
  62. package/fake_server/fake_server_data/fake_server_data.js +111 -0
  63. package/index.js +3 -0
  64. package/indexUMD.js +5 -0
  65. package/package.json +45 -0
  66. package/umd/library.min.js +186 -0
  67. package/umd/library.min.js.map +1 -0
@@ -0,0 +1,137 @@
1
+ export class Auth {
2
+ constructor(req, storage) {
3
+ this.req = req;
4
+ this.storage = storage;
5
+ }
6
+
7
+ login({ username, password } = {}) {
8
+ return this.req.simplePost({
9
+ url: "/auth/login",
10
+ form: {
11
+ username,
12
+ password,
13
+ },
14
+ });
15
+ }
16
+
17
+ logout(token) {
18
+ return this.req.post({
19
+ url: "/auth/logout",
20
+ form: {
21
+ token,
22
+ },
23
+ });
24
+ }
25
+
26
+ signup(user) {
27
+ return this.req.simplePost({
28
+ url: "/auth/singup",
29
+ form: { user: JSON.stringify(user) },
30
+ });
31
+ }
32
+
33
+ getUsersList(keyword) {
34
+ return this.req.get({
35
+ url: "/auth/userlist",
36
+ params: {
37
+ keyword,
38
+ },
39
+ });
40
+ }
41
+
42
+ updateUserApi(userData) {
43
+ return this.req.post({
44
+ url: "/auth/updateuser",
45
+ form: {
46
+ user: JSON.stringify(userData),
47
+ },
48
+ });
49
+ }
50
+
51
+ updateToken(auth_key) {
52
+ return this.req.simplePost({
53
+ url: "/auth/login",
54
+ form: {
55
+ auth_key,
56
+ },
57
+ });
58
+ }
59
+
60
+ avatarUploadApi(image) {
61
+ return this.req.post({
62
+ url: "/auth/avatar-upload",
63
+ form: {
64
+ image,
65
+ },
66
+ });
67
+ }
68
+
69
+ getUserByIdApi(id) {
70
+ return this.req.get({ url: "/auth/getuserbyid", params: { id } });
71
+ }
72
+
73
+ getVersion() {
74
+ return this.req.get({ url: "/version" });
75
+ }
76
+
77
+ getUserFromStorage(id) {
78
+ return this.storage.getUsersList().find((user) => user.user_id == id);
79
+ }
80
+
81
+ saveUserToStorage(saveUser) {
82
+ const usersList = this.storage.getUsersList();
83
+ const userInStorage = usersList.find(
84
+ (user) => user.user_id == saveUser.user_id
85
+ );
86
+ if (!userInStorage) {
87
+ usersList.push(saveUser);
88
+ return saveUser;
89
+ }
90
+ return userInStorage;
91
+ }
92
+
93
+ async getUserById(userId) {
94
+ let user = this.getUserFromStorage(userId);
95
+
96
+ if (!user) {
97
+ let receivedUser = await this.getUserByIdApi(userId);
98
+
99
+ if(!receivedUser) return null;
100
+
101
+ user = this.getUserFromStorage(userId);
102
+
103
+ if (!user) {
104
+ this.saveUserToStorage(receivedUser);
105
+ user = receivedUser;
106
+ }
107
+ }
108
+
109
+ return user;
110
+ }
111
+
112
+ async getToken() {
113
+ const expiryDate = new Date(this.storage.getUser().expirydate);
114
+ const currentDate = new Date();
115
+ let accesstoken = this.storage.getUser().accesstoken;
116
+
117
+ /*-- checking if token exists and if it's not expired*/
118
+ if (expiryDate < currentDate || !accesstoken) {
119
+ /*-- If token is expired we send request to server to update it*/
120
+ const user = await this.updateToken(this.storage.getUser().auth_key);
121
+ this.storage.updateUser(user);
122
+ accesstoken = user.accesstoken;
123
+ }
124
+
125
+ return accesstoken;
126
+ }
127
+
128
+ async updateUser(userData) {
129
+ const user = await this.updateUserApi(userData);
130
+ this.storage.updateUser(user);
131
+ }
132
+
133
+ async updateAvatar(imageData) {
134
+ const user = await this.avatarUploadApi(imageData);
135
+ this.storage.updateUser(user);
136
+ }
137
+ }
@@ -0,0 +1,15 @@
1
+ import should from "should";
2
+ import {GudHub} from './../gudhub.js';
3
+
4
+ describe("AUTHORIZATION", async function() {
5
+ const auth_key = 'Z/lxMHLenEaQTvPjW5U6c3jBDwWFYZrh2F9Kxa3fbt8drvabS2u2lXQ2zI+SRmic';
6
+ const gudhub = new GudHub(auth_key);
7
+
8
+ it("GET USER BY ID / It Should return user with 'Vasya Pupkin' fullname", async function () {
9
+ this.timeout(5000);
10
+ var user = await gudhub.auth.getUserById("58");
11
+
12
+ user.fullname.should.equal('Vasya Pupkin');
13
+ })
14
+
15
+ });
@@ -0,0 +1,80 @@
1
+
2
+
3
+ export class ChunksManager {
4
+ constructor(storage, pipeService, req, util) {
5
+ this.storage = storage;
6
+ this.pipeService = pipeService;
7
+ this.req = req;
8
+ this.util = util;
9
+ this.itemListeners();
10
+ }
11
+
12
+ async getChunkApi(app_id, chunk_id) {
13
+ try {
14
+ const response = await this.req.simpleGet({
15
+ url: `/api/get-items-chunk/${app_id}/${chunk_id}`,
16
+ });
17
+ return response;
18
+ } catch (err) {
19
+ console.log(err);
20
+ return null;
21
+ }
22
+ }
23
+
24
+ async getLastChunkApi(app_id) {
25
+ try {
26
+ const response = await this.req.simpleGet({
27
+ url: `/api/get-last-items-chunk/${app_id}`,
28
+ });
29
+ return response;
30
+ } catch (err) {
31
+ console.log(err);
32
+ return null;
33
+ }
34
+ }
35
+
36
+
37
+ getChunk(app_id, chunk_id) {
38
+ return this.getChunkApi(app_id, chunk_id);
39
+ }
40
+
41
+
42
+ async getChunks(app_id, chunk_ids) {
43
+ let chunks = [];
44
+ if(chunk_ids){
45
+ chunks = await Promise.all(chunk_ids.map((chunk_id) => this.getChunkApi(app_id, chunk_id)));
46
+ }
47
+ return chunks;
48
+ }
49
+
50
+
51
+ async getLastChunk(app_id) {
52
+ let chunk = await this.getLastChunkApi(app_id);
53
+ return chunk;
54
+ }
55
+
56
+
57
+ itemListeners() {
58
+ }
59
+
60
+ async getApp(app_id) {
61
+ if (!app_id) return null;
62
+ let app = this.getAppFromStorage(app_id);
63
+ if (!app) {
64
+ if (this.getAppPromises[app_id]) {
65
+ return this.getAppPromises[app_id];
66
+ }
67
+ this.getAppPromises[app_id] = this.getAppApi(app_id);
68
+ app = await this.getAppPromises[app_id];
69
+ if (app) {
70
+ this.saveAppInStorage(app);
71
+ this.ws.addSubscription(app_id);
72
+ } else {
73
+ return null;
74
+ }
75
+ }
76
+ return app;
77
+ }
78
+
79
+
80
+ }
@@ -0,0 +1,46 @@
1
+ import should from "should";
2
+ import {GudHub} from './../../gudhub.js';
3
+
4
+ describe("CHUNKS MANAGER", async function() {
5
+ const auth_key = 'Z/lxMHLenEaQTvPjW5U6c3jBDwWFYZrh2F9Kxa3fbt8drvabS2u2lXQ2zI+SRmic';
6
+ const gudhub = new GudHub(auth_key);
7
+
8
+
9
+ it("GET CHUNK : here we get first chunk from App", async function () {
10
+ this.timeout(10000);
11
+ var app = await gudhub.getApp(8263);
12
+ let firstChunk = await gudhub.chunksManager.getChunk(8263, app.chunks[0]);
13
+ firstChunk.should.have.property("chunk_number");
14
+ firstChunk.should.have.property("items_list");
15
+ firstChunk.items_list[0].fields[0].should.have.property("history");
16
+ });
17
+
18
+
19
+ it("GET LAST CHUNK : here we should get last chunk", async function () {
20
+ this.timeout(5000);
21
+ let firstChunk = await gudhub.chunksManager.getLastChunk(8263);
22
+
23
+ firstChunk.should.have.property("chunk_number");
24
+ firstChunk.should.have.property("items_list");
25
+ firstChunk.items_list[0].fields[0].should.have.property("history");
26
+ });
27
+
28
+
29
+ it("GET CHUNKS : here we getting chanks from empty array []", async function () {
30
+ let chunkedItems = await gudhub.chunksManager.getChunks(8263, []);
31
+ chunkedItems.length.should.equal(0);
32
+ });
33
+
34
+
35
+ it("GET CHUNKS : here we should receive all chunks of app", async function () {
36
+ this.timeout(1000000);
37
+ var app = await gudhub.getApp(8263);
38
+ let chunkedItems = await gudhub.chunksManager.getChunks(8263, app.chunks);
39
+
40
+ chunkedItems[0].items_list[0].should.have.property("fields");
41
+ chunkedItems[0].items_list[0].should.have.property("item_id");
42
+ chunkedItems[0].items_list[0].fields[0].should.have.property("history");
43
+ });
44
+
45
+
46
+ });
@@ -0,0 +1,48 @@
1
+ /*
2
+ Document Template request
3
+ {
4
+ app_id: 1,
5
+ item_id: 1
6
+ element_id: 1,
7
+ data: {}
8
+ }
9
+
10
+ */
11
+
12
+ export class DocumentManager {
13
+ constructor(req) {
14
+ this.req = req;
15
+ }
16
+
17
+ createDocumentApi(documentObject) {
18
+ return this.req.post({
19
+ url: "/api/new/document/insert-one",
20
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
21
+ form: { document: JSON.stringify(documentObject) },
22
+ });
23
+ }
24
+
25
+ getDocumentApi(documentAddress) {
26
+ return this.req.post({
27
+ url: "/api/new/document/find-one",
28
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
29
+ form: { document: JSON.stringify(documentAddress) },
30
+ });
31
+ }
32
+
33
+ getDocumentsApi(documentsAddresses) {
34
+ return this.req.post({
35
+ url: "/api/new/document/find",
36
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
37
+ form: { document: JSON.stringify(documentsAddresses) },
38
+ });
39
+ }
40
+
41
+ deleteDocumentApi(documentAddress) {
42
+ return this.req.post({
43
+ url: "/api/new/document/remove-one",
44
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
45
+ form: { document: JSON.stringify(documentAddress) },
46
+ });
47
+ }
48
+ }
@@ -0,0 +1,208 @@
1
+ export class FileManager {
2
+ constructor(storage, pipeService, req, appProcessor) {
3
+ this.storage = storage;
4
+ this.pipeService = pipeService;
5
+ this.req = req;
6
+ this.appProcessor = appProcessor;
7
+ }
8
+
9
+ //********************* UPLOAD FILE *********************//
10
+
11
+ async uploadFileApi(fileData, app_id, item_id) {
12
+ try {
13
+ const form = {
14
+ "file-0": fileData,
15
+ app_id,
16
+ item_id,
17
+ };
18
+ const file = await this.req.post({
19
+ url: "/file/formupload",
20
+ form,
21
+ });
22
+ return file;
23
+ } catch (err) {
24
+ console.log(err);
25
+ return null;
26
+ }
27
+ }
28
+
29
+ async uploadFileFromStringApi(
30
+ source,
31
+ file_name,
32
+ app_id,
33
+ item_id,
34
+ extension,
35
+ format,
36
+ element_id
37
+ ) {
38
+ try {
39
+ const fileObj = {
40
+ app_id,
41
+ item_id,
42
+ extension,
43
+ file_name,
44
+ format,
45
+ element_id,
46
+ source,
47
+ };
48
+
49
+ const file = await this.req.post({
50
+ url: "/file/upload",
51
+ form: { file: JSON.stringify(fileObj) },
52
+ });
53
+ return file;
54
+ } catch (err) {
55
+ console.log(err);
56
+ return null;
57
+ }
58
+ }
59
+
60
+ async updateFileFromStringApi(data, file_id, file_name, extension, format) {
61
+ try {
62
+ const fileObj = {
63
+ file_name,
64
+ extension,
65
+ file_id,
66
+ format,
67
+ source: data,
68
+ };
69
+
70
+ const file = await this.req.post({
71
+ url: "/file/update",
72
+ form: { file: JSON.stringify(fileObj) },
73
+ });
74
+ return file;
75
+ } catch (err) {
76
+ console.log(err);
77
+ return null;
78
+ }
79
+ }
80
+
81
+ async duplicateFile(files) {
82
+ return this.req.post({
83
+ url: "/api/new/file/duplicate",
84
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
85
+ form: {
86
+ files: JSON.stringify(files),
87
+ },
88
+ });
89
+ }
90
+
91
+ async deleteFileApi(id) {
92
+ try {
93
+ const file = await this.req.get({
94
+ url: `/file/delete?file_id=${id}`,
95
+ });
96
+ return file;
97
+ } catch (err) {
98
+ console.log(err);
99
+ return null;
100
+ }
101
+ }
102
+
103
+ addFileToStorage(app_id, file) {
104
+ const app = this.storage.getApp(app_id);
105
+ if (app) {
106
+ app.file_list.push(file);
107
+ this.storage.updateApp(app);
108
+ }
109
+ }
110
+
111
+ addFilesToStorage(app_id, files) {
112
+ const app = this.storage.getApp(app_id);
113
+ if (app) {
114
+ app.file_list.push(...files);
115
+ this.storage.updateApp(app);
116
+ }
117
+ }
118
+
119
+ deleteFileFromStorage(fileId, app_id) {
120
+ const app = this.storage.getApp(app_id);
121
+ if (app) {
122
+ app.file_list = app.file_list.filter((file) => file.file_id != fileId);
123
+ this.storage.updateApp(app);
124
+ this.pipeService.emit("gh_file_delete", { file_id: fileId }, file);
125
+ }
126
+ }
127
+
128
+ updateFileInStorage(fileId, app_id, newFile) {
129
+ const app = this.storage.getApp(app_id);
130
+ if (app) {
131
+ app.file_list = app.file_list.map((file) =>
132
+ file.file_id == fileId ? newFile : file
133
+ );
134
+ this.storage.updateApp(app);
135
+ this.pipeService.emit("gh_file_update", { file_id: fileId });
136
+ }
137
+ }
138
+
139
+ async getFile(app_id, file_id) {
140
+ try {
141
+ const app = await this.appProcessor.getApp(app_id);
142
+ return app.file_list.find((file) => {
143
+ return file.file_id == file_id;
144
+ });
145
+ } catch (err) {
146
+ console.log(err);
147
+ return null;
148
+ }
149
+ }
150
+
151
+ async getFiles(app_id, filesId = []) {
152
+ try {
153
+ const app = await this.appProcessor.getApp(app_id);
154
+ return app.file_list.filter((file) => {
155
+ return filesId.some(id => {
156
+ return id == file.file_id;
157
+ })});
158
+ } catch (err) {
159
+ console.log(err);
160
+ return null;
161
+ }
162
+ }
163
+
164
+ async uploadFile(fileData, app_id, item_id) {
165
+ const file = await this.uploadFileApi(fileData, app_id, item_id);
166
+ this.addFileToStorage(app_id, file);
167
+ return file;
168
+ }
169
+
170
+ async uploadFileFromString(
171
+ source,
172
+ file_name,
173
+ app_id,
174
+ item_id,
175
+ extension,
176
+ format,
177
+ element_id
178
+ ) {
179
+ const file = await this.uploadFileFromStringApi(
180
+ source,
181
+ file_name,
182
+ app_id,
183
+ item_id,
184
+ extension,
185
+ format,
186
+ element_id
187
+ );
188
+ this.addFileToStorage(app_id, file);
189
+ return file;
190
+ }
191
+
192
+ async updateFileFromString(data, file_id, file_name, extension, format) {
193
+ const file = await this.updateFileFromStringApi(
194
+ data,
195
+ file_id,
196
+ file_name,
197
+ extension,
198
+ format
199
+ );
200
+ this.updateFileInStorage(file_id, file.app_id, file);
201
+ return file;
202
+ }
203
+
204
+ deleteFile(app_id, id) {
205
+ this.deleteFileApi(id);
206
+ this.deleteFileFromStorage(id, app_id);
207
+ }
208
+ }
@@ -0,0 +1,17 @@
1
+ import should from "should";
2
+ import { GudHub } from "./../../gudhub.js";
3
+ describe("FILE MANAGER", function () {
4
+ const gudhub = new GudHub();
5
+
6
+ it("GET FILE URL", async function () {
7
+ //-- checking if file exist
8
+ let file = await gudhub.getFile(16259,809199);
9
+ file.should.have.property("url","https://gudhub.com/userdata/16259/809199.jpg");
10
+ });
11
+ it("GET FILES URL's", async function () {
12
+ //-- checking if file exist
13
+ let files = await gudhub.getFiles(16259,[809199,811768]);
14
+ files[0].should.have.property("url","https://gudhub.com/userdata/16259/809199.jpg");
15
+ files[1].should.have.property("url", "https://gudhub.com/userdata/16259/811768.png");
16
+ });
17
+ });
@@ -0,0 +1,5 @@
1
+ import { DocumentManager } from "./DocumentManager/DocumentManager.js";
2
+ import { FileManager } from "./FileManager/FileManager.js";
3
+ import { ChunksManager } from "./ChunksManager/ChunksManager.js";
4
+
5
+ export { FileManager, DocumentManager, ChunksManager };