cordova-plugin-unvired-universal-sdk 1.0.6 → 1.0.8

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 (76) hide show
  1. package/package.json +1 -1
  2. package/plugin.xml +1 -13
  3. package/www/kernel.js +38344 -1243
  4. package/aar/README.md +0 -3
  5. package/aar/Unvired_Kernel_Android.aar +0 -0
  6. package/aar/Unvired_Kernel_HTML5_Android.aar +0 -0
  7. package/src/android/build.gradle +0 -35
  8. package/src/android/xml/provider_paths.xml +0 -21
  9. package/src/browser/UnviredPluginProxy.js +0 -2430
  10. package/src/browser/bootstrap.min.js +0 -17
  11. package/src/browser/codemirror.js +0 -9755
  12. package/src/browser/jquery-3.2.1.js +0 -10253
  13. package/src/browser/sql-wasm.wasm +0 -0
  14. package/src/browser/sql.js +0 -203
  15. package/src/browser/src_index_worker_js.unvired-db-worker.js +0 -231
  16. package/src/browser/unvired-db-worker.js +0 -166
  17. package/src/browser/vendors-node_modules_comlink_dist_esm_comlink_mjs.unvired-db-worker.js +0 -22
  18. package/src/ios/AttachmentPlugin.h +0 -21
  19. package/src/ios/AttachmentPlugin.m +0 -180
  20. package/src/ios/DataStructureHelper.h +0 -28
  21. package/src/ios/DataStructureHelper.m +0 -188
  22. package/src/ios/IOSAuthPlugin.h +0 -14
  23. package/src/ios/IOSAuthPlugin.m +0 -13
  24. package/src/ios/IOSDatabasePlugin.h +0 -28
  25. package/src/ios/IOSDatabasePlugin.m +0 -253
  26. package/src/ios/IOSFWSettingsPlugin.h +0 -65
  27. package/src/ios/IOSFWSettingsPlugin.m +0 -363
  28. package/src/ios/IOSLoggerPlugin.h +0 -34
  29. package/src/ios/IOSLoggerPlugin.m +0 -198
  30. package/src/ios/IOSLoginPlugin.h +0 -29
  31. package/src/ios/IOSLoginPlugin.m +0 -480
  32. package/src/ios/IOSProxyPlugin.h +0 -21
  33. package/src/ios/IOSProxyPlugin.m +0 -172
  34. package/src/ios/IOSSyncEnginePlugin.h +0 -54
  35. package/src/ios/IOSSyncEnginePlugin.m +0 -847
  36. package/src/ios/PluginConstants.h +0 -195
  37. package/src/ios/PluginHelper.h +0 -29
  38. package/src/ios/PluginHelper.m +0 -74
  39. package/src/ios/SyncHTML5Response.h +0 -50
  40. package/src/ios/SyncHTML5Response.m +0 -68
  41. package/www/applicationMeta/applicationMetadataParser.ts +0 -285
  42. package/www/applicationMeta/fieldConstants.ts +0 -92
  43. package/www/attachment/attachmentHelper.ts +0 -326
  44. package/www/attachment/attachmentQHelper.ts +0 -158
  45. package/www/attachment/attachmentService.ts +0 -259
  46. package/www/authenticationService.ts +0 -751
  47. package/www/database/appDatabaseManager.ts +0 -54
  48. package/www/database/databaseManager.ts +0 -616
  49. package/www/helper/dbCreateTablesManager.ts +0 -354
  50. package/www/helper/frameworkHelper.ts +0 -127
  51. package/www/helper/frameworkSettingsManager.ts +0 -287
  52. package/www/helper/getMessageTimerManager.ts +0 -81
  53. package/www/helper/httpConnection.ts +0 -1051
  54. package/www/helper/logger.ts +0 -312
  55. package/www/helper/notificationListnerHelper.ts +0 -56
  56. package/www/helper/passcodeGenerator.ts +0 -61
  57. package/www/helper/reconciler.ts +0 -1062
  58. package/www/helper/serverResponseHandler.ts +0 -677
  59. package/www/helper/serviceConstants.ts +0 -254
  60. package/www/helper/settingsHelper.ts +0 -386
  61. package/www/helper/status.ts +0 -83
  62. package/www/helper/syncInputDataManager.ts +0 -205
  63. package/www/helper/unviredAccount.ts +0 -104
  64. package/www/helper/unviredAccountManager.ts +0 -120
  65. package/www/helper/urlService.ts +0 -43
  66. package/www/helper/userSettingsManager.ts +0 -172
  67. package/www/helper/utils.ts +0 -110
  68. package/www/inbox/downloadMessageService.ts +0 -270
  69. package/www/inbox/inboxHelper.ts +0 -132
  70. package/www/inbox/inboxService.ts +0 -223
  71. package/www/outbox/outboxAttachmentManager.ts +0 -152
  72. package/www/outbox/outboxHelper.ts +0 -67
  73. package/www/outbox/outboxService.ts +0 -519
  74. package/www/subtract.ts +0 -5
  75. package/www/sum.ts +0 -4
  76. package/www/syncEngine.ts +0 -687
package/www/syncEngine.ts DELETED
@@ -1,687 +0,0 @@
1
- import * as FieldConstants from "./applicationMeta/fieldConstants";
2
- import { DatabaseManager, DatabaseType } from "./database/databaseManager";
3
- import FrameworkHelper from "./helper/frameworkHelper";
4
- import { ObjectStatus, SyncStatus, isServerReachable } from "./helper/utils";
5
- import * as ServiceConstants from './helper/serviceConstants';
6
- import { UnviredAccountManager } from "./helper/unviredAccountManager";
7
- import { AuthenticationService, ResultType, SyncResult } from "./authenticationService";
8
- import { OutObjectStatus, RequestType, SyncType } from "./helper/serviceConstants";
9
- import { Logger } from "./helper/logger";
10
- import { FrameworkSettingsManager } from "./helper/frameworkSettingsManager";
11
- import { HttpConnection } from "./helper/httpConnection";
12
- import { Status } from "./helper/status";
13
- import SyncInputDataManager from "./helper/syncInputDataManager";
14
- import SettingsHelper from "./helper/settingsHelper";
15
- import ServerResponseHandler from "./helper/serverResponseHandler";
16
- import OutBoxHelper from "./outbox/outboxHelper";
17
- import DownloadMessageService from "./inbox/downloadMessageService";
18
- import OutboxService from "./outbox/outboxService";
19
- import InboxService from "./inbox/inboxService";
20
-
21
- export class SyncEngine {
22
-
23
- public async syncForeground(reqType: RequestType, header: any, customData: string, paFunction: string, autoSave: boolean): Promise<any> {
24
- return new Promise(async (resolve, reject) => {
25
- try {
26
- const result = await this.handleSend(reqType, header, customData, paFunction, autoSave, false);
27
- if (result.type === ResultType.error) {
28
- Logger.logError("SyncEngine", "syncForeground", `Error: ${JSON.stringify(result)}`);
29
- }
30
- else {
31
- Logger.logDebug("SyncEngine", "syncForeground", `Result: ${JSON.stringify(result)}`);
32
- }
33
- resolve(result);
34
- } catch (e) {
35
- Logger.logError("SyncEngine", "syncForeground", `Error: ${JSON.stringify(e)}`);
36
- reject(e);
37
- }
38
- });
39
- }
40
-
41
- public async syncBackground(reqType: RequestType, header: any, customData: string, paFunction: string, beName: string): Promise<any> {
42
- return new Promise(async (resolve, reject) => {
43
- try {
44
- // TODO: check why beName and beLid are required. And check if bypassAttachment is required.
45
- const result = await this.handleSend(reqType, header, customData, paFunction, true, true);
46
- Logger.logDebug("SyncEngine", "syncBackground", `Result: ${JSON.stringify(result)}`);
47
- resolve(result);
48
- } catch (e) {
49
- Logger.logError("SyncEngine", "syncBackground", `Error: ${JSON.stringify(e)}`);
50
- reject(e);
51
- }
52
- });
53
- }
54
-
55
- public getSynchronizationState(): Promise<any> {
56
- return new Promise((resolve, reject) => {
57
- // TODO:
58
- let isSuccessful = true
59
- if (isSuccessful) {
60
- const result = { /* data to be returned on success */ };
61
- resolve(result);
62
- } else {
63
- const error = { /* error message */ };
64
- reject(error);
65
- }
66
- });
67
- }
68
-
69
- public startInboxHandler(): Promise<any> {
70
- return new Promise((resolve, reject) => {
71
- InboxService.getInstance().start();
72
- resolve(true);
73
- });
74
- }
75
-
76
- public startDataSender(): Promise<any> {
77
- return new Promise((resolve, reject) => {
78
- OutboxService.getInstance().start();
79
- resolve(true);
80
- });
81
- }
82
-
83
- public getMessages(): Promise<any> {
84
- return new Promise((resolve, reject) => {
85
- DownloadMessageService.getInstance().start();
86
- resolve(true);
87
- });
88
- }
89
-
90
- public registerNotifListener(): Promise<any> {
91
- return new Promise((resolve, reject) => {
92
- // TODO:
93
- let isSuccessful = true
94
- if (isSuccessful) {
95
- const result = { /* data to be returned on success */ };
96
- resolve(result);
97
- } else {
98
- const error = { /* error message */ };
99
- reject(error);
100
- }
101
- });
102
- }
103
-
104
- public unRegisterNotifListener(): Promise<void> {
105
- return new Promise((resolve, reject) => {
106
- // TODO:
107
- let isSuccessful = true
108
- if (isSuccessful) {
109
- resolve();
110
- } else {
111
- const error = { /* error message */ };
112
- reject(error);
113
- }
114
- });
115
- }
116
-
117
- public isInOutbox(beLid: string): Promise<any> {
118
- return new Promise((resolve, reject) => {
119
- // TODO:
120
- let isSuccessful = true
121
- if (isSuccessful) {
122
- const result = { /* data to be returned on success */ };
123
- resolve(result);
124
- } else {
125
- const error = { /* error message */ };
126
- reject(error);
127
- }
128
- });
129
- }
130
-
131
- public outBoxItemCount(): Promise<any> {
132
- return new Promise((resolve, reject) => {
133
- // TODO:
134
- let isSuccessful = true
135
- if (isSuccessful) {
136
- const result = { /* data to be returned on success */ };
137
- resolve(result);
138
- } else {
139
- const error = { /* error message */ };
140
- reject(error);
141
- }
142
- });
143
- }
144
-
145
- public isInSentItem(beLid: string): Promise<any> {
146
- return new Promise((resolve, reject) => {
147
- // TODO:
148
- let isSuccessful = true
149
- if (isSuccessful) {
150
- const result = { /* data to be returned on success */ };
151
- resolve(result);
152
- } else {
153
- const error = { /* error message */ };
154
- reject(error);
155
- }
156
- });
157
- }
158
-
159
- public sentItemCount(): Promise<any> {
160
- return new Promise((resolve, reject) => {
161
- // TODO:
162
- let isSuccessful = true
163
- if (isSuccessful) {
164
- const result = { /* data to be returned on success */ };
165
- resolve(result);
166
- } else {
167
- const error = { /* error message */ };
168
- reject(error);
169
- }
170
- });
171
- }
172
-
173
- public inBoxItemCount(): Promise<any> {
174
- return new Promise((resolve, reject) => {
175
- // TODO:
176
- let isSuccessful = true
177
- if (isSuccessful) {
178
- const result = { /* data to be returned on success */ };
179
- resolve(result);
180
- } else {
181
- const error = { /* error message */ };
182
- reject(error);
183
- }
184
- });
185
- }
186
-
187
- public deleteOutBoxEntry(beLid: string): Promise<any> {
188
- return new Promise((resolve, reject) => {
189
- // TODO:
190
- let isSuccessful = true
191
- if (isSuccessful) {
192
- const result = { /* data to be returned on success */ };
193
- resolve(result);
194
- } else {
195
- const error = { /* error message */ };
196
- reject(error);
197
- }
198
- });
199
- }
200
-
201
- public registerForPushNotification(): Promise<any> {
202
- return new Promise((resolve, reject) => {
203
- // TODO:
204
- let isSuccessful = true
205
- if (isSuccessful) {
206
- const result = { /* data to be returned on success */ };
207
- resolve(result);
208
- } else {
209
- const error = { /* error message */ };
210
- reject(error);
211
- }
212
- });
213
- }
214
-
215
- public resetApplicationSyncData(): Promise<any> {
216
- return new Promise((resolve, reject) => {
217
- // TODO:
218
- let isSuccessful = true
219
- if (isSuccessful) {
220
- const result = { /* data to be returned on success */ };
221
- resolve(result);
222
- } else {
223
- const error = { /* error message */ };
224
- reject(error);
225
- }
226
- });
227
- }
228
-
229
- public generateUBJson(headerName: string, header: any, itemName: string, items: any[]): Promise<any> {
230
- return new Promise((resolve, reject) => {
231
- // TODO:
232
- let isSuccessful = true
233
- if (isSuccessful) {
234
- const result = { /* data to be returned on success */ };
235
- resolve(result);
236
- } else {
237
- const error = { /* error message */ };
238
- reject(error);
239
- }
240
- });
241
- }
242
-
243
- public parseRawUBJson(json: string): Promise<any> {
244
- return new Promise((resolve, reject) => {
245
- // TODO:
246
- let isSuccessful = true
247
- if (isSuccessful) {
248
- const result = { /* data to be returned on success */ };
249
- resolve(result);
250
- } else {
251
- const error = { /* error message */ };
252
- reject(error);
253
- }
254
- });
255
- }
256
-
257
- public lockDataSender(beLid: string): Promise<any> {
258
- return new Promise((resolve, reject) => {
259
- // TODO:
260
- let isSuccessful = true
261
- if (isSuccessful) {
262
- const result = {
263
- type: ResultType.success,
264
- data: 2
265
- };
266
- resolve(result);
267
- } else {
268
- const error = {
269
- type: ResultType.error,
270
- error: "Failed to lock data sender."
271
- };
272
- reject(error);
273
- }
274
- });
275
- }
276
- public unlockDataSender(): Promise<any> {
277
- return new Promise((resolve, reject) => {
278
- // TODO:
279
- let isSuccessful = true
280
- if (isSuccessful) {
281
- const result = {
282
- type: ResultType.success,
283
- data: {}
284
- };
285
- resolve(result);
286
- } else {
287
- const error = {
288
- type: ResultType.error,
289
- error: "Failed to unlock data sender."
290
- };
291
- reject(error);
292
- }
293
- });
294
- }
295
-
296
- public removeOutObjectBasedOnLid(lid: string): Promise<any> {
297
- return new Promise((resolve, reject) => {
298
- // TODO:
299
- let isSuccessful = true
300
- if (isSuccessful) {
301
- const result = { /* data to be returned on success */ };
302
- resolve(result);
303
- } else {
304
- const error = { /* error message */ };
305
- reject(error);
306
- }
307
- });
308
- }
309
-
310
- public refreshJWTToken(): Promise<any> {
311
- return new Promise((resolve, reject) => {
312
- // TODO:
313
- let isSuccessful = true
314
- if (isSuccessful) {
315
- const result = { /* data to be returned on success */ };
316
- resolve(result);
317
- } else {
318
- const error = { /* error message */ };
319
- reject(error);
320
- }
321
- });
322
- }
323
-
324
- private async handleSend(requestType: RequestType, header:any, customData: any, paName: string, autoSave: boolean, isAsynchronous: boolean): Promise<SyncResult> {
325
- const selectedAccount = AuthenticationService.instance.loginParameters;
326
- let syncResult = new SyncResult();
327
- if (selectedAccount.isDemoLogin) {
328
- syncResult.code = 201;
329
- syncResult.type = ResultType.success;
330
- syncResult.message = 'Demo login successful.'
331
- return syncResult;
332
- }
333
-
334
- if (!paName) {
335
- syncResult.type = ResultType.error;
336
- syncResult.error = 'Process agent function name is mandatory.'
337
- syncResult.message = 'Process agent function name is mandatory.'
338
- syncResult.code = 0;
339
- return syncResult;
340
- }
341
-
342
- // TODO:
343
- // if (!this.lockedLid) {
344
- // await Logger.logDebug("SyncEngine", "handleSend", "NO BE LOCKED");
345
- // } else {
346
- // await Logger.logDebug("SyncEngine", "handleSend", `BE LOCKED ${this.lockedLid}`);
347
- // }
348
-
349
- if (requestType !== RequestType.PULL && (header != null && header != '' && Object.keys(header).length === 0) && (customData != null && customData != '' && Object.keys(customData).length === 0)) {
350
- syncResult.type = ResultType.error;
351
- syncResult.error = 'Invalid Input data.'
352
- syncResult.message = 'Invalid Input data.'
353
- syncResult.code = 0;
354
- return syncResult;
355
- }
356
- let inputDataObject = {}
357
- let entityName = "";
358
- if (header != null && Object.keys(header).length > 0) {
359
- const allKeys = Object.keys(header)
360
- entityName = allKeys.length > 0 ? allKeys[0] : "";
361
- inputDataObject = header[entityName]
362
- }
363
- else if (customData != null && Object.keys(customData).length > 0) {
364
- inputDataObject = JSON.parse(JSON.stringify(customData))
365
- const allKeys = Object.keys(inputDataObject)
366
-
367
- for (const key of allKeys) {
368
- const value = inputDataObject[key]
369
- if (value instanceof Array) {
370
- const subKeys = Object.keys(value[0])
371
- if (subKeys.length > 0) {
372
- const headerNames = subKeys.filter(subKey => subKey.endsWith("_HEADER"))
373
- if (headerNames.length > 0) {
374
- entityName = headerNames[0]
375
- break;
376
- }
377
- }
378
- else {
379
- break;
380
- }
381
- }
382
- else {
383
- break;
384
- }
385
- }
386
- }
387
- if (requestType === RequestType.RQST && (!entityName || entityName.length === 0)) {
388
- syncResult.type = ResultType.error;
389
- syncResult.error = 'Invalid Input data.'
390
- syncResult.message = 'Invalid Input data.'
391
- syncResult.code = 0;
392
- return syncResult;
393
- }
394
- await Logger.logInfo("SyncEngine", "handleSend", `inputDataObject: ${JSON.stringify(inputDataObject)}`);
395
- const isSensitive = false
396
- const isCustomInput = customData != null && customData.toString().length > 0 && Object.keys(customData).length > 0
397
-
398
-
399
- if (isAsynchronous) {
400
- await Logger.logDebug("SyncEngine", "handleSend", `making async call ${paName}`);
401
- const result = await this.sendAsync(requestType, inputDataObject, entityName, paName, isCustomInput, isSensitive);
402
- return result;
403
- } else {
404
- await Logger.logDebug("SyncEngine", "handleSend", `making sync call ${paName}`);
405
- try {
406
- let inputJson = inputDataObject;
407
- if (header != null && Object.keys(header).length > 0) {
408
- if (requestType === RequestType.REQ || requestType === RequestType.RQST) {
409
- if (FrameworkHelper.getPlatform() !== "browser") {
410
- await SyncInputDataManager.checkAndUploadAttachments(entityName, inputJson);
411
- }
412
- }
413
- inputJson = await SyncInputDataManager.constructInputBeJson(entityName, inputDataObject);
414
- }
415
- const inputDataString = await this.constructRequestString(requestType, inputJson, isCustomInput, isAsynchronous, isSensitive);
416
- if (!navigator.onLine) {
417
- await Logger.logDebug("SyncEngine", "handleSend", "Internet is not connected.");
418
- // throw("Internet is not connected.");
419
- syncResult.type = ResultType.error;
420
- syncResult.error = 'Internet is not connected.'
421
- syncResult.message = 'Internet is not connected.'
422
- syncResult.code = 0;
423
- return syncResult;
424
- }
425
-
426
- if (!(await isServerReachable(AuthenticationService.instance.loginParameters.url))) {
427
- await Logger.logDebug("SyncEngine", "handleSend", "Server not reachable.");
428
- // throw("Server not reachable.");
429
- syncResult.type = ResultType.error;
430
- syncResult.error = 'Server not reachable.'
431
- syncResult.message = 'Server not reachable.'
432
- syncResult.code = 0;
433
- return syncResult;
434
- }
435
- const unviredResult = new SyncResult();
436
- try {
437
- const lastLoggedInAccount = UnviredAccountManager.getInstance().getLastLoggedInAccount();
438
- const result = await new HttpConnection().makeSyncCall(inputDataString, paName, lastLoggedInAccount, AuthenticationService.instance.loginParameters);
439
- let responseObject = JSON.parse(result.data ?? "");
440
- await Logger.logDebug("SyncEngine", "handleSend", `ResponseJson: ${JSON.stringify(responseObject)}`);
441
- await Logger.logDebug("SyncEngine", "handleSend", `Response: ${JSON.stringify(responseObject)}`);
442
- unviredResult.code = result.httpStatusCode;
443
- if (result.httpStatusCode === Status.ok || result.httpStatusCode === Status.created) {
444
- unviredResult.type = ResultType.success;
445
- unviredResult.data = responseObject;
446
- const copiedResponse = JSON.parse(JSON.stringify(responseObject));
447
- if (result.header != null && result.header[ServiceConstants.HeaderConstantPullMode] && result.header[ServiceConstants.HeaderConstantPullMode] === ServiceConstants.PullModeDelete) {
448
- requestType = RequestType.PULLD;
449
- }
450
- await ServerResponseHandler.handleResponseData(copiedResponse || {}, autoSave, true, inputDataObject[FieldConstants.FieldLid] || "", entityName, requestType);
451
- } else {
452
- unviredResult.type = ResultType.error;
453
- unviredResult.error = responseObject;
454
- if (responseObject["systemError"] && responseObject["systemError"] === 13) {
455
- unviredResult.error = responseObject["error"]
456
- unviredResult.message = responseObject["error"]
457
- Logger.logError("SyncEngine", "handleSend", `Error: ${JSON.stringify(responseObject)}`);
458
- await AuthenticationService.instance.clearData();
459
- } else {
460
- await this.handleInfoMessage(responseObject || {}, inputDataObject[FieldConstants.FieldLid] || "", entityName);
461
- }
462
- }
463
- }
464
- catch (error) {
465
- await Logger.logError("SyncEngine", "handleSend", `Error: ${JSON.stringify(error)}`);
466
- unviredResult.type = ResultType.error;
467
- unviredResult.error = error;
468
- unviredResult.message = error;
469
- }
470
- return unviredResult
471
- } catch (e) {
472
- if (e.name === 'AbortError') {
473
- await Logger.logError("SyncEngine", "handleSend", `Timeout Exception: ${JSON.stringify(e)}`);
474
- // throw("Connection timed out. Please check your internet connection and try again. If the issue persists, contact your administrator.");
475
- syncResult.type = ResultType.error;
476
- syncResult.error = 'Connection timed out. Please check your internet connection and try again. If the issue persists, contact your administrator.'
477
- syncResult.message = 'Connection timed out. Please check your internet connection and try again. If the issue persists, contact your administrator.'
478
- syncResult.code = 0;
479
- return syncResult;
480
- } else {
481
- // throw e.message;
482
- syncResult.type = ResultType.error;
483
- syncResult.error = e.message;
484
- syncResult.message = e.message;
485
- syncResult.code = 0;
486
- return syncResult;
487
- }
488
- }
489
- }
490
- }
491
-
492
- private async constructRequestString(requestType:RequestType, dataObject: any, isCustomInput: boolean, isAsynchronous: boolean, isSensitive: boolean): Promise<string> {
493
- const account = AuthenticationService.instance.loginParameters
494
- if (!account) {
495
- await Logger.logError("SyncEngine", "constructRequestString", "Account data not available.");
496
- throw("Account data not available.");
497
- }
498
-
499
- const dataString = Object.keys(dataObject).length === 0 ? "" : JSON.stringify(dataObject);
500
-
501
- const bodyObject: { [key: string]: string } = {
502
- [ServiceConstants.QueryParamFrontendUser]: account.feUserId
503
- };
504
-
505
- if (dataString.length > 0) {
506
- bodyObject[ServiceConstants.QueryParamInputMessage] = dataString;
507
- }
508
-
509
- if (requestType.length > 0) {
510
- bodyObject[ServiceConstants.QueryParamRequestType] = requestType;
511
- }
512
-
513
- if (isCustomInput) {
514
- bodyObject[ServiceConstants.QueryParamMessageFormat] = ServiceConstants.MessageTypeCustom;
515
- }
516
-
517
- if (isAsynchronous) {
518
- const externalRef = FrameworkHelper.getUUID();
519
- bodyObject[ServiceConstants.QueryParamQueuedExecute] = "true";
520
- bodyObject[ServiceConstants.QueryParamExternalReference] = externalRef;
521
- }
522
-
523
- if (isSensitive) {
524
- bodyObject[ServiceConstants.QueryParamSensitive] = "true";
525
- }
526
-
527
- const systemCredentials = await FrameworkSettingsManager.getInstance().getAllSystemCredentials();
528
- if (systemCredentials.length > 0) {
529
- var credDetails = [];
530
- for (const cred of systemCredentials) {
531
- if (cred.portName && cred.userId && cred.password) {
532
- const credDetail = {
533
- port: cred.portName,
534
- user: cred.userId,
535
- password: cred.password
536
- };
537
- credDetails.push(credDetail);
538
- }
539
- }
540
- if (credDetails.length > 0) {
541
- bodyObject[ServiceConstants.QueryParamCredentials] = JSON.stringify(credDetails);
542
- }
543
- }
544
-
545
- const combined = { ...bodyObject, ...(await HttpConnection.getCommonPostParameters()) };
546
-
547
- return JSON.stringify(combined);
548
- }
549
-
550
- private async sendAsync(requestType:RequestType, dataObject: any, entityName: string, paName: string, isCustomInput: boolean, isSensitive: boolean): Promise<SyncResult> {
551
- let syncResult = new SyncResult();
552
- try {
553
- let inputJson = dataObject;
554
- if (!isCustomInput) {
555
- inputJson = await SyncInputDataManager.constructInputBeJson(entityName, dataObject);
556
- }
557
- const isAsyncCall = FrameworkHelper.getPlatform() !== "browser";
558
- const inputDataString = await this.constructRequestString(requestType, inputJson, isCustomInput, isAsyncCall, isSensitive);
559
-
560
- switch (requestType) {
561
- // case RequestType.PULL:
562
- // case RequestType.QUERY:
563
- // if (Object.keys(dataObject).length > 0 && !entityName) {
564
- // await Logger.logError("SyncEngine", "_sendAsync", "BE Name cannot be null");
565
- // throw("BE Name cannot be null");
566
- // }
567
- // break;
568
- case RequestType.RQST:
569
- if (!entityName) {
570
- await Logger.logError("SyncEngine", "_sendAsync", "BE Name cannot be null");
571
- throw("BE Name cannot be null");
572
- }
573
-
574
- if (Object.keys(dataObject).length === 0 || !dataObject[FieldConstants.FieldLid] || !dataObject[FieldConstants.FieldLid].toString().length) {
575
- await Logger.logError("SyncEngine", "_sendAsync", `BE LID cannot be null. BE name: ${entityName}`);
576
- throw(`BE LID cannot be null. BE name: ${entityName}`);
577
- }
578
- break;
579
- default:
580
- break;
581
- }
582
-
583
- const outObjectData = {
584
- lid: FrameworkHelper.getUUID(),
585
- timestamp: Date.now(),
586
- objectStatus: ObjectStatus.global,
587
- syncStatus: SyncStatus.none,
588
- functionName: paName,
589
- beName: entityName,
590
- beHeaderLid: dataObject[FieldConstants.FieldLid] || "",
591
- requestType: requestType,
592
- syncType: isAsyncCall ? SyncType.ASYNC : SyncType.SYNC,
593
- conversationId: "",
594
- messageJson: inputDataString,
595
- companyNameSpace: "",
596
- sendStatus: "",
597
- fieldOutObjectStatus: OutObjectStatus.none.toString(),
598
- isAdminServices: false
599
- };
600
- await this.checkInOutBoxAndQueue(outObjectData);
601
- syncResult.type = ResultType.success;
602
- syncResult.code = 201;
603
- } catch (e) {
604
- syncResult.type = ResultType.error;
605
- syncResult.error = e.message;
606
- syncResult.code = 0;
607
- }
608
- return syncResult
609
- }
610
-
611
- private async handleInfoMessage(responseData: { [key: string]: any }, lid: string, entityName: string): Promise<void> {
612
- if (Object.keys(responseData).length > 0 && responseData[ServiceConstants.KeyInfoMessage]) {
613
- const infoMessages = responseData[ServiceConstants.KeyInfoMessage];
614
- for (const element of infoMessages) {
615
- const infoMessage = {
616
- lid: FrameworkHelper.getUUID(),
617
- timestamp: Date.now(),
618
- objectStatus: ObjectStatus.global,
619
- syncStatus: SyncStatus.none,
620
- type: "",
621
- subtype: "",
622
- category: element[FieldConstants.FieldInfoMessageCategory],
623
- message: element[FieldConstants.FieldInfoMessageMessage],
624
- bename: entityName,
625
- belid: lid,
626
- messagedetails: new Uint8Array(0)
627
- };
628
- await DatabaseManager.getInstance().insert(DatabaseType.FrameworkDb, "InfoMessage", infoMessage, true)
629
- }
630
- }
631
- }
632
-
633
- public async checkInOutBoxAndQueue(entry: any): Promise<void> {
634
- let outObject = await OutBoxHelper.checkIsInOutBox(entry.beHeaderLid);
635
-
636
- if (outObject) {
637
- if (outObject.fieldOutObjectStatus === OutObjectStatus.lockedForSending.toString()) {
638
- await Logger.logError("SyncEngine", "_checkInOutBoxAndQueue", "Cannot modify. OutObject is locked for sending");
639
- return;
640
- }
641
-
642
- if (entry.functionName !== outObject.functionName) {
643
- await Logger.logError("SyncEngine", "_checkInOutBoxAndQueue", `Cannot modify. OutObject is already queued for ${outObject.functionName}`);
644
- return;
645
- }
646
- outObject["fieldOutObjectStatus"] = OutObjectStatus.lockedForModify.toString();
647
-
648
- const databaseManager = DatabaseManager.getInstance();
649
- try {
650
- await Logger.logDebug("SyncEngine", "_checkInOutBoxAndQueue", `Updating to outbox ${outObject.lid}`);
651
- await databaseManager.update(DatabaseType.FrameworkDb, "OutObject", outObject, `${FieldConstants.FieldLid} = '${outObject.lid}'`);
652
- } catch (e) {
653
- await Logger.logError("SyncEngine", "_checkInOutBoxAndQueue", `Update Failed, DBException: ${JSON.stringify(e)}`);
654
- }
655
- OutboxService.getInstance().start();
656
- return;
657
- } else {
658
- outObject = entry;
659
- }
660
-
661
- const sentItem = await OutBoxHelper.checkIsInSentItems(outObject.beHeaderLid);
662
- if (sentItem) {
663
- await Logger.logDebug("SyncEngine", "_checkInOutBoxAndQueue", `Sent to outbox ${outObject.lid}`);
664
-
665
- const error = `Object already present in sent items. Cannot queue the same object twice. BE Name: ${outObject.beName} Process Agent Name: ${outObject.functionName} BE Name: ${outObject.beName} BE Lid: ${outObject.beHeaderLid} Data: ${outObject.messageJson}`;
666
- await Logger.logError("SyncEngine", "_checkInOutBoxAndQueue", error);
667
- throw(error);
668
- }
669
-
670
- await OutBoxHelper.updateSyncStatusToEntityObjects(outObject, SyncStatus.queued);
671
- try {
672
- await Logger.logDebug("SyncEngine", "_checkInOutBoxAndQueue", `Adding to outbox ${outObject.lid}`);
673
- const databaseManager = DatabaseManager.getInstance();
674
- await databaseManager.insert(DatabaseType.FrameworkDb, "OutObject", outObject, true);
675
- const outObjectList = await databaseManager.select(DatabaseType.FrameworkDb, "OutObject");
676
- await Logger.logDebug("SyncEngine", "_checkInOutBoxAndQueue", `Checking in outbox ${outObjectList.length}`);
677
- } catch (e) {
678
- await Logger.logError("SyncEngine", "_checkInOutBoxAndQueue", `Adding to outbox failed ${outObject.lid} ${JSON.stringify(e)}`);
679
- const error = `Exception while adding data structure to outbox. BE Name: ${outObject.beName} Process Agent Name: ${outObject.functionName} Exception: ${JSON.stringify(e)} Data: ${outObject.messageJson}`;
680
- await Logger.logError("SyncEngine", "_checkInOutBoxAndQueue", error);
681
- }
682
- await Logger.logInfo("SyncEngine", "checkInOutBoxAndQueue", "Starting Outbox Service");
683
- OutboxService.getInstance().start();
684
- }
685
- }
686
-
687
- export default new SyncEngine()