cordova-plugin-unvired-universal-sdk 1.0.1

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 (82) hide show
  1. package/README.md +59 -0
  2. package/aar/README.md +3 -0
  3. package/aar/Unvired_Kernel_Android.aar +0 -0
  4. package/aar/Unvired_Kernel_HTML5_Android.aar +0 -0
  5. package/package.json +69 -0
  6. package/plugin.xml +23 -0
  7. package/src/android/build.gradle +35 -0
  8. package/src/android/xml/provider_paths.xml +21 -0
  9. package/src/browser/UnviredPluginProxy.js +2430 -0
  10. package/src/browser/bootstrap.min.js +17 -0
  11. package/src/browser/codemirror.js +9755 -0
  12. package/src/browser/jquery-3.2.1.js +10253 -0
  13. package/src/browser/sql-wasm.wasm +0 -0
  14. package/src/browser/sql.js +203 -0
  15. package/src/browser/src_index_worker_js.unvired-db-worker.js +231 -0
  16. package/src/browser/unvired-db-worker.js +166 -0
  17. package/src/browser/vendors-node_modules_comlink_dist_esm_comlink_mjs.unvired-db-worker.js +22 -0
  18. package/src/ios/AttachmentPlugin.h +21 -0
  19. package/src/ios/AttachmentPlugin.m +180 -0
  20. package/src/ios/DataStructureHelper.h +28 -0
  21. package/src/ios/DataStructureHelper.m +188 -0
  22. package/src/ios/IOSAuthPlugin.h +14 -0
  23. package/src/ios/IOSAuthPlugin.m +13 -0
  24. package/src/ios/IOSDatabasePlugin.h +28 -0
  25. package/src/ios/IOSDatabasePlugin.m +253 -0
  26. package/src/ios/IOSFWSettingsPlugin.h +65 -0
  27. package/src/ios/IOSFWSettingsPlugin.m +363 -0
  28. package/src/ios/IOSLoggerPlugin.h +34 -0
  29. package/src/ios/IOSLoggerPlugin.m +198 -0
  30. package/src/ios/IOSLoginPlugin.h +29 -0
  31. package/src/ios/IOSLoginPlugin.m +480 -0
  32. package/src/ios/IOSProxyPlugin.h +21 -0
  33. package/src/ios/IOSProxyPlugin.m +172 -0
  34. package/src/ios/IOSSyncEnginePlugin.h +54 -0
  35. package/src/ios/IOSSyncEnginePlugin.m +847 -0
  36. package/src/ios/PluginConstants.h +195 -0
  37. package/src/ios/PluginHelper.h +29 -0
  38. package/src/ios/PluginHelper.m +74 -0
  39. package/src/ios/SyncHTML5Response.h +50 -0
  40. package/src/ios/SyncHTML5Response.m +68 -0
  41. package/www/applicationMeta/applicationMetadataParser.ts +285 -0
  42. package/www/applicationMeta/fieldConstants.ts +92 -0
  43. package/www/attachment/attachmentHelper.ts +326 -0
  44. package/www/attachment/attachmentQHelper.ts +158 -0
  45. package/www/attachment/attachmentService.ts +259 -0
  46. package/www/authenticationService.ts +746 -0
  47. package/www/bootstrap.min.js +17 -0
  48. package/www/codemirror.js +9755 -0
  49. package/www/database/appDatabaseManager.ts +54 -0
  50. package/www/database/databaseManager.ts +616 -0
  51. package/www/helper/dbCreateTablesManager.ts +354 -0
  52. package/www/helper/frameworkHelper.ts +127 -0
  53. package/www/helper/frameworkSettingsManager.ts +287 -0
  54. package/www/helper/getMessageTimerManager.ts +81 -0
  55. package/www/helper/httpConnection.ts +1051 -0
  56. package/www/helper/logger.ts +312 -0
  57. package/www/helper/notificationListnerHelper.ts +56 -0
  58. package/www/helper/passcodeGenerator.ts +61 -0
  59. package/www/helper/reconciler.ts +1062 -0
  60. package/www/helper/serverResponseHandler.ts +677 -0
  61. package/www/helper/serviceConstants.ts +254 -0
  62. package/www/helper/settingsHelper.ts +386 -0
  63. package/www/helper/status.ts +83 -0
  64. package/www/helper/syncInputDataManager.ts +205 -0
  65. package/www/helper/unviredAccount.ts +104 -0
  66. package/www/helper/unviredAccountManager.ts +120 -0
  67. package/www/helper/urlService.ts +43 -0
  68. package/www/helper/userSettingsManager.ts +172 -0
  69. package/www/helper/utils.ts +110 -0
  70. package/www/inbox/downloadMessageService.ts +270 -0
  71. package/www/inbox/inboxHelper.ts +132 -0
  72. package/www/inbox/inboxService.ts +223 -0
  73. package/www/jquery-3.2.1.js +10253 -0
  74. package/www/kernel.js +1380 -0
  75. package/www/outbox/outboxAttachmentManager.ts +152 -0
  76. package/www/outbox/outboxHelper.ts +67 -0
  77. package/www/outbox/outboxService.ts +519 -0
  78. package/www/sql-wasm.wasm +0 -0
  79. package/www/sql.js +209 -0
  80. package/www/subtract.ts +5 -0
  81. package/www/sum.ts +4 -0
  82. package/www/syncEngine.ts +687 -0
@@ -0,0 +1,223 @@
1
+ import DatabaseManager, { DatabaseType } from "../database/databaseManager";
2
+ import FrameworkHelper from "../helper/frameworkHelper";
3
+ import { Logger } from "../helper/logger";
4
+ import ServerResponseHandler from "../helper/serverResponseHandler";
5
+ import { ObjectStatus, SyncStatus } from "../helper/utils";
6
+ import DownloadMessageService from "./downloadMessageService";
7
+ import * as ServiceConstants from "../helper/serviceConstants";
8
+ import * as FieldConstants from "../applicationMeta/fieldConstants";
9
+ import InboxHelper from "./inboxHelper";
10
+ import AttachmentService from "../attachment/attachmentService";
11
+ import { NotificationListenerHelper, NotificationListnerType } from "../helper/notificationListnerHelper";
12
+
13
+ const fileName = "InboxService"
14
+ export default class InboxService {
15
+
16
+ private static instance: InboxService;
17
+ private isProcessing: boolean = false;
18
+ private shouldStop: boolean = false;
19
+
20
+ private constructor() {}
21
+
22
+ public static getInstance(): InboxService {
23
+ if (!InboxService.instance) {
24
+ InboxService.instance = new InboxService();
25
+ }
26
+ return InboxService.instance;
27
+ }
28
+
29
+ public start(): void {
30
+ if (!this.isProcessing) {
31
+ this.isProcessing = true;
32
+ this.shouldStop = false;
33
+ this.startInboxProcessing();
34
+ } else {
35
+ Logger.logInfo(fileName, "start", "Inbox processing is already running.");
36
+ }
37
+ }
38
+
39
+ public stop(): void {
40
+ if (this.isProcessing) {
41
+ this.shouldStop = true;
42
+ Logger.logInfo(fileName, "stop", "Stopping inbox processing...");
43
+ } else {
44
+ Logger.logInfo(fileName, "stop", "Inbox processing is not running.");
45
+ }
46
+ }
47
+
48
+ async startInboxProcessing(): Promise<void> {
49
+ Logger.logInfo(fileName, "startInboxProcessing", "Starting inbox processing...");
50
+ let isInboxEmpty = false;
51
+ const databaseManager = DatabaseManager.getInstance();
52
+ const inboxCount = await databaseManager.count(DatabaseType.FrameworkDb, "InObject");
53
+ var currentIndex = 0;
54
+ try {
55
+ do {
56
+ if (this.shouldStop) {
57
+ Logger.logInfo(fileName, "startInboxProcessing", "Stopping inbox processing...");
58
+ break;
59
+ }
60
+ const inObject = await databaseManager.getFirstEntity(DatabaseType.FrameworkDb, "InObject");
61
+ isInboxEmpty = inObject === null;
62
+ if (!isInboxEmpty) {
63
+ currentIndex++;
64
+ const currentProcessingNumber = inboxCount - currentIndex;
65
+ if (currentProcessingNumber > 0) {
66
+ NotificationListenerHelper.postSynchronizationStateNotification(`processing (${currentProcessingNumber})`);
67
+ }
68
+ Logger.logInfo(fileName, "startInboxProcessing", `Processing LID : ${inObject.lid}. Conversation ID : ${inObject.conversationId}.`);
69
+ try {
70
+ if (inObject.type !== -1 && inObject.subtype !== -1) {
71
+ Logger.logInfo(fileName, "startInboxProcessing", `Admin service messages. Starting in-object processing.`);
72
+ await DownloadMessageService.handleMessageTypes(inObject);
73
+ await databaseManager.delete(DatabaseType.FrameworkDb, "InObject", `conversationId = '${inObject.conversationId}'`);
74
+ Logger.logInfo(fileName, "startInboxProcessing", `Admin service messages. Deleting from in-object.`);
75
+ await InboxHelper.deleteInBoxData(inObject.conversationId);
76
+ } else {
77
+ let jsonData: any = {};
78
+ try {
79
+ const inboxData = await InboxHelper.getInBoxData(inObject.conversationId);
80
+ jsonData = JSON.parse(inboxData);
81
+ } catch (e) {
82
+ Logger.logError(fileName, "startInboxProcessing", `Application messages. Error while getting inbox data: ${JSON.stringify(e)}.`);
83
+ await databaseManager.delete(DatabaseType.FrameworkDb, "InObject", `lid = '${inObject.lid}'`);
84
+ continue;
85
+ }
86
+
87
+ try {
88
+ Logger.logInfo(fileName, "startInboxProcessing", `Application messages. Starting in-object processing.`);
89
+ // map["currentConvId"] = inObject.conversationId;
90
+ await ServerResponseHandler.handleResponseData(jsonData, true, false, inObject.beLid, inObject.jsonData, inObject.requestType);
91
+ Logger.logInfo(fileName, "startInboxProcessing", `Application messages. In-object successfully processed.`);
92
+ } catch (e) {
93
+ Logger.logError(fileName, "startInboxProcessing", `Application messages. Error while processing in-object: ${JSON.stringify(e)}.`);
94
+ const infoMessage = {
95
+ lid: FrameworkHelper.getUUID(),
96
+ timestamp: Date.now(),
97
+ objectStatus: ObjectStatus.global,
98
+ syncStatus: SyncStatus.none,
99
+ type: inObject.type.toString(),
100
+ subtype: inObject.subtype.toString(),
101
+ category: FieldConstants.InfoMessageFailure,
102
+ message: `Deleted the InObject from the inobject Queue. Could not handle the In Object because the XML data had a parsing Issue: ${JSON.stringify(e)}. Conversation ID: ${inObject.conversationId}. `,
103
+ bename: inObject.jsonData,
104
+ belid: inObject.beLid,
105
+ messagedetails: new Uint8Array(0)
106
+ };
107
+ await databaseManager.insert(DatabaseType.FrameworkDb, "InfoMessage", infoMessage, true);
108
+ await this.updateSyncStatusToEntityObjects(inObject, SyncStatus.error);
109
+ }
110
+ Logger.logInfo(fileName, "startInboxProcessing", `Application messages. Deleting from in-object.`);
111
+ const result: number = await databaseManager.delete(DatabaseType.FrameworkDb, "InObject", `conversationId = '${inObject.conversationId}'`);
112
+ Logger.logInfo(fileName, "startInboxProcessing", `Application messages. in-object deleted. Result: ${result}`);
113
+ await InboxHelper.deleteInBoxData(inObject.conversationId);
114
+ }
115
+ } catch (e) {
116
+ Logger.logError(fileName, "startInboxProcessing", `Application messages. Error while processing in-object: ${JSON.stringify(e)}.`);
117
+ }
118
+ } else {
119
+ Logger.logInfo(fileName, "startInboxProcessing", `Inbox is empty. Stopping inbox processing.`);
120
+ }
121
+ } while (!isInboxEmpty);
122
+ await this.checkAndUpdateHeaderSyncStatus();
123
+ Logger.logInfo(fileName, "startInboxProcessing", `Inbox processing completed.`);
124
+ NotificationListenerHelper.postSynchronizationStateNotification(`idle`);
125
+ if (inboxCount > 0) {
126
+ NotificationListenerHelper.postDataSenderNotification(null, NotificationListnerType.incomingDataProcessingFinished);
127
+ }
128
+ AttachmentService.getInstance().start();
129
+ }
130
+ catch (e) {
131
+ Logger.logError(fileName, "startInboxProcessing", `Error while starting inbox processing. Error: ${e}`);
132
+ }
133
+ finally {
134
+ this.isProcessing = false;
135
+ this.shouldStop = false;
136
+ }
137
+ }
138
+
139
+ private async checkAndUpdateHeaderSyncStatus(): Promise<void> {
140
+ try {
141
+ const databaseManager = DatabaseManager.getInstance();
142
+ const headerStructMetas: any[] = await databaseManager.select(DatabaseType.FrameworkDb, "StructureMeta", `isHeader = '1'`);
143
+ const allBusinessEntityMetas: any[] = await databaseManager.select(DatabaseType.FrameworkDb, "BusinessEntityMeta");
144
+ const allSentItems = await databaseManager.select(DatabaseType.FrameworkDb, "SentItems");
145
+ const allBeLids: string[] = allSentItems.map(e => e.beHeaderLid);
146
+ let beLidsSting = "";
147
+ if (allBeLids.length > 0) {
148
+ beLidsSting = "'" + allBeLids.join("','") + "'";
149
+ }
150
+ for (const headerStructure of headerStructMetas) {
151
+ try {
152
+ const currentBeMeta = allBusinessEntityMetas.find(element => element.beName === headerStructure.beName);
153
+ if (currentBeMeta?.save === "false") {
154
+ continue;
155
+ }
156
+ Logger.logInfo(fileName, "checkAndUpdateHeaderSyncStatus", `headerStructure: ${JSON.stringify(headerStructure)}.`);
157
+ const allData: any[] = await databaseManager.select(DatabaseType.AppDb, headerStructure.structureName, `${FieldConstants.FieldSyncStatus}=${SyncStatus.sent} AND ${FieldConstants.FieldObjectStatus}=${ObjectStatus.modify}` +
158
+ (beLidsSting.length > 0 ? ` AND ${FieldConstants.FieldLid} NOT IN (${beLidsSting})` : ""))
159
+ for (const headerData of allData) {
160
+ try {
161
+ await databaseManager.update(DatabaseType.AppDb, headerStructure.structureName, {
162
+ [FieldConstants.FieldSyncStatus]: SyncStatus.error,
163
+ [FieldConstants.FieldInfoMsgCat]: FieldConstants.InfoMessageFailure
164
+ }, `${FieldConstants.FieldLid} = '${headerData[FieldConstants.FieldLid]}'`, true); // isFromApp is true because it just need to update the data and should not set the missing fields to null.
165
+ const infoMessage = {
166
+ lid: FrameworkHelper.getUUID(),
167
+ timestamp: Date.now(),
168
+ objectStatus: ObjectStatus.global,
169
+ syncStatus: SyncStatus.none,
170
+ type: "",
171
+ subtype: "",
172
+ category: FieldConstants.InfoMessageFailure,
173
+ message: "The connection was interrupted. Please try again.",
174
+ bename: headerStructure.structureName,
175
+ belid: headerData[FieldConstants.FieldLid],
176
+ messagedetails: new Uint8Array(0)
177
+ };
178
+ await databaseManager.insert(DatabaseType.FrameworkDb, "InfoMessage", infoMessage, true);
179
+ } catch (e) {
180
+ Logger.logError(fileName, "checkAndUpdateHeaderSyncStatus", `Error while updating header (${headerStructure.structureName}) Sync Status to ERROR into database. Error: ${JSON.stringify(e)}`);
181
+ }
182
+ }
183
+ } catch (e) {
184
+ Logger.logError(fileName, "checkAndUpdateHeaderSyncStatus", `Error while getting BE Meta for header (${headerStructure.structureName}). Error: ${JSON.stringify(e)}`);
185
+ }
186
+ }
187
+ } catch (e) {
188
+ Logger.logError(fileName, "checkAndUpdateHeaderSyncStatus", `Error while updating header Sync Status to ERROR. Error: ${JSON.stringify(e)}`);
189
+ }
190
+ }
191
+
192
+ async updateSyncStatusToEntityObjects(inObject: any, syncStatus: SyncStatus): Promise<void> {
193
+ const requestType = inObject.requestType;
194
+ const entityName = inObject.jsonData; // BE Name is set in the jsonData field
195
+ const beLid = inObject.beLid;
196
+
197
+ if (requestType === ServiceConstants.RequestType.RQST.toString()) {
198
+ const databaseManager = DatabaseManager.getInstance();
199
+ const structureMetaData = await databaseManager.select(DatabaseType.FrameworkDb, "StructureMeta", `structureName = '${entityName}'`)
200
+ if (structureMetaData.length === 0) {
201
+ Logger.logError(fileName, "updateSyncStatusToEntityObjects", `No structure meta found for BE-NAME: ${entityName}, BE-LID: ${beLid}`);
202
+ return;
203
+ }
204
+ const structName = structureMetaData[0].structureName;
205
+ const structureFieldData = await databaseManager.select(DatabaseType.AppDb, structName, `${FieldConstants.FieldLid} = '${beLid}'`);
206
+ if (structureFieldData.length === 0) {
207
+ Logger.logError(fileName, "updateSyncStatusToEntityObjects", `No Business Entity got from database, BE-NAME: ${entityName}, BE-LID: ${beLid}`);
208
+ return;
209
+ }
210
+ const data = structureFieldData[0];
211
+
212
+ data[FieldConstants.FieldSyncStatus] = syncStatus;
213
+ await databaseManager.update(DatabaseType.AppDb, structName, data, `${FieldConstants.FieldLid} = '${beLid}'`);
214
+
215
+ const childStructureMetas = await databaseManager.select(DatabaseType.FrameworkDb, "StructureMeta", `beName = '${entityName}' AND isHeader != '1'`);
216
+ for (const childStructureMetaData of childStructureMetas) {
217
+ await databaseManager.update(DatabaseType.AppDb, childStructureMetaData.structureName, {
218
+ [FieldConstants.FieldSyncStatus]: syncStatus
219
+ }, `${FieldConstants.FieldLid}='${beLid}' AND ${FieldConstants.FieldObjectStatus} != ${ObjectStatus.global}`, true); // isFromApp is true because it just need to update the data and should not set the missing fields to null.
220
+ }
221
+ }
222
+ }
223
+ }