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,152 @@
1
+ import DatabaseManager, { DatabaseType } from "../database/databaseManager";
2
+ import { Logger } from "../helper/logger";
3
+ import * as FieldConstants from '../applicationMeta/fieldConstants';
4
+ import * as ServiceConstants from '../helper/serviceConstants';
5
+ import { UnviredAccountManager } from "../helper/unviredAccountManager";
6
+ import { HttpConnection, bearerAuth } from "../helper/httpConnection";
7
+ import { UserSettingsFields, UserSettingsManager } from "../helper/userSettingsManager";
8
+ import { isServerReachable, LoginType, ObjectStatus, SyncStatus } from "../helper/utils";
9
+ import FrameworkHelper from "../helper/frameworkHelper";
10
+ import { Status } from "../helper/status";
11
+ import { AuthenticationService } from "../authenticationService";
12
+
13
+ export default class OutboxAttachmentManager {
14
+ async checkAndUploadAttachmentsInOutBox(entityName:string, inputData: any): Promise<boolean> {
15
+ const databaseManager = DatabaseManager.getInstance();
16
+ const structureMetas = await databaseManager.select(DatabaseType.FrameworkDb, "StructureMeta");
17
+ const structureMeta = structureMetas.find(element => element.structureName === entityName);
18
+ // Invalid condition. Should never occur.
19
+ if (!structureMeta) {
20
+ Logger.logError("OutboxAttachmentManager", "checkAndUploadAttachmentsInOutBox", `Invalid BE. Cannot Upload Attachments. Table Name: ${entityName}`);
21
+ return false;
22
+ }
23
+ // If attachments are not supported do not do anything
24
+ const isAttachmentSupported: boolean = await this.isAttachmentSupportedForBEName(structureMeta.beName);
25
+ if (!isAttachmentSupported) {
26
+ Logger.logInfo("OutboxAttachmentManager", "checkAndUploadAttachmentsInOutBox", `This BE: ${structureMeta.beName} does not support attachments.`);
27
+ return true; // Return true since no attachments to upload
28
+ }
29
+
30
+ Logger.logDebug("OutboxAttachmentManager", "checkAndUploadAttachmentsInOutBox", `This BE: ${structureMeta.beName} supports attachments.`);
31
+
32
+ try {
33
+ const attachmentEntityNames: string[] = structureMetas
34
+ .filter(element => element.beName === structureMeta.beName && element.structureName.endsWith(ServiceConstants.AttachmentBE))
35
+ .map(e => e.structureName);
36
+
37
+ for (const attachmentEntityName of attachmentEntityNames) {
38
+ let attachmentItems: any[] = [];
39
+ try {
40
+ attachmentItems = await this.getAttachmentsMarkedForUploadOutbox(attachmentEntityName, inputData);
41
+ } catch (e) {
42
+ Logger.logError("OutboxAttachmentManager", "checkAndUploadAttachmentsInOutBox", `Error when trying to get attachments marked for upload ${JSON.stringify(e)}`);
43
+ return false;
44
+ }
45
+
46
+ for (const attachmentItem of attachmentItems) {
47
+ try {
48
+ if (!navigator.onLine) {
49
+ Logger.logError("OutboxAttachmentManager", "checkAndUploadAttachmentsInOutBox", "No Internet connection.");
50
+ return false;
51
+ }
52
+ const lastLoggedInAccount = UnviredAccountManager.getInstance().getLastLoggedInAccount();
53
+ if (!(await isServerReachable(lastLoggedInAccount.getServerURL()))) {
54
+ return false;
55
+ }
56
+ const response = await new HttpConnection().uploadAttachment(attachmentItem);
57
+ if (response.status === Status.ok || response.status === Status.created) {
58
+ const isSuccess: boolean = await this.updateAttachmentStatusOutBox(attachmentEntityName, attachmentItem, ServiceConstants.AttachmentStatusUploaded);
59
+ if (!isSuccess) {
60
+ Logger.logError("OutboxAttachmentManager", "checkAndUploadAttachmentsInOutBox", `Failed to update status in ${attachmentEntityName} LID : ${attachmentItem[FieldConstants.FieldLid]}`);
61
+ }
62
+ return true;
63
+ } else {
64
+ Logger.logError("OutboxAttachmentManager", "checkAndUploadAttachmentsInOutBox", "Error while uploading attachment.");
65
+ const infoMessage = {
66
+ lid: FrameworkHelper.getUUID(),
67
+ timestamp: Date.now(),
68
+ objectStatus: ObjectStatus.global,
69
+ syncStatus: SyncStatus.none,
70
+ type: "",
71
+ subtype: "",
72
+ category: 'InfoMessageFailure',
73
+ message: "Error while uploading attachment.",
74
+ bename: entityName,
75
+ belid: attachmentItem[FieldConstants.FieldLid],
76
+ messagedetails: new Uint8Array(0)
77
+ };
78
+ await databaseManager.insert(DatabaseType.FrameworkDb, "InfoMessage", infoMessage, true);
79
+ const isSuccess: boolean = await this.updateAttachmentStatusOutBox(attachmentEntityName, attachmentItem, ServiceConstants.AttachmentStatusErrorInUpload);
80
+ if (!isSuccess) {
81
+ Logger.logError("OutboxAttachmentManager", "checkAndUploadAttachmentsInOutBox", `Failed to update status in ${attachmentEntityName} LID : ${attachmentItem[FieldConstants.FieldLid]}`);
82
+ }
83
+ return false;
84
+ }
85
+ } catch (e) {
86
+ const isSuccess: boolean = await this.updateAttachmentStatusOutBox(attachmentEntityName, attachmentItem, ServiceConstants.AttachmentStatusErrorInUpload);
87
+ if (!isSuccess) {
88
+ Logger.logError("OutboxAttachmentManager", "checkAndUploadAttachmentsInOutBox", `Failed to update status in ${attachmentEntityName} LID : ${attachmentItem[FieldConstants.FieldLid]}`);
89
+ }
90
+ return false;
91
+ }
92
+ }
93
+ }
94
+ return true;
95
+ } catch (e) {
96
+ Logger.logError("OutboxAttachmentManager", "checkAndUploadAttachmentsInOutBox", `Error when trying to check and upload attachments in outbox ${JSON.stringify(e)}`);
97
+ return false;
98
+ }
99
+ }
100
+
101
+ async updateAttachmentStatusOutBox(attachmentItemName: string, attachmentItem: any, attachmentStatus: string): Promise<boolean> {
102
+ attachmentItem[ServiceConstants.AttachmentItemFieldAttachmentStatus] = attachmentStatus;
103
+ const databaseManager = DatabaseManager.getInstance();
104
+ return await databaseManager.update(DatabaseType.AppDb, attachmentItemName, attachmentItem, `${FieldConstants.FieldLid} = '${attachmentItem[FieldConstants.FieldLid]}'`);
105
+ }
106
+
107
+ async isAttachmentSupportedForBEName(beName: string): Promise<boolean> {
108
+ if (!beName) {
109
+ return false;
110
+ }
111
+ try {
112
+ const databaseManager = DatabaseManager.getInstance();
113
+ const beMeta = await databaseManager.select(DatabaseType.FrameworkDb, "BusinessEntityMeta", `beName = '${beName}'`)
114
+ if (beMeta.length === 0) {
115
+ return false;
116
+ }
117
+ return beMeta[0].attachments === "1";
118
+ } catch (e) {
119
+ Logger.logError("OutboxAttachmentManager", "isAttachmentSupportedForBEName", `Error when trying to get BusinessEntityMeta. Error: ${JSON.stringify(e)}`);
120
+ }
121
+ return false;
122
+ }
123
+
124
+ async getAttachmentsMarkedForUploadOutbox(attachmentEntityName: string, inputData: any): Promise<any[]> {
125
+ const parsedData: any = JSON.parse(inputData[ServiceConstants.QueryParamInputMessage]);
126
+ const inputDataKeys: Iterable<string> = Object.keys(parsedData);
127
+ const beData: any = parsedData[inputDataKeys[0]];
128
+
129
+ let headerData: any ;
130
+ for (const key in beData[0]) {
131
+ if (key.endsWith("_HEADER")) {
132
+ headerData = beData[0][key];
133
+ break;
134
+ }
135
+ }
136
+ if (!headerData) {
137
+ Logger.logError("OutboxAttachmentManager", "getAttachmentsMarkedForUploadOutbox", "Header data not available.");
138
+ return [];
139
+ }
140
+ // Check if the header supports attachments, if yes, check if it has any, if yes send to server.
141
+ const whereClause: string = `${FieldConstants.FieldFid} = '${headerData[FieldConstants.FieldLid]}' AND ${ServiceConstants.AttachmentItemFieldAttachmentStatus} = '${ServiceConstants.AttachmentStatusSavedForUpload}'`;
142
+ let attachmentItems: any[] = [];
143
+ try {
144
+ const databaseManager = DatabaseManager.getInstance();
145
+ attachmentItems = await databaseManager.select(DatabaseType.AppDb, attachmentEntityName, whereClause);
146
+ } catch (e) {
147
+ Logger.logError("OutboxAttachmentManager", "getAttachmentsMarkedForUploadOutbox", `Error when trying to get attachments marked for upload ${JSON.stringify(e)}`);
148
+ }
149
+
150
+ return attachmentItems;
151
+ }
152
+ }
@@ -0,0 +1,67 @@
1
+ import DatabaseManager, { DatabaseType } from "../database/databaseManager";
2
+ import * as FieldConstants from "../applicationMeta/fieldConstants";
3
+ import { ObjectStatus, SyncStatus } from "../helper/utils";
4
+ import { RequestType } from "../helper/serviceConstants";
5
+ import { Logger } from "../helper/logger";
6
+
7
+ const fileName = "OutBoxHelper";
8
+ export default class OutBoxHelper {
9
+ static async checkIsInOutBox(beLid: string): Promise<any> {
10
+ if (beLid === "") {
11
+ return null;
12
+ }
13
+ const databaseManager = await DatabaseManager.getInstance();
14
+ const outObjectData = await databaseManager.select(DatabaseType.FrameworkDb, "OutObject", `beHeaderLid = '${beLid}'`);
15
+ return outObjectData.length > 0 ? outObjectData[0] : null;
16
+ }
17
+
18
+ static async checkIsInSentItems(beLid: string): Promise<any> {
19
+ if (beLid === "") {
20
+ return null;
21
+ }
22
+ const databaseManager = await DatabaseManager.getInstance();
23
+ const sentItem = await databaseManager.select(DatabaseType.FrameworkDb, "SentItems", `beHeaderLid = '${beLid}'`);
24
+ return sentItem.length > 0 ? sentItem[0] : null;
25
+ }
26
+
27
+ static async updateSyncStatusToEntityObjects(outObject: any, syncStatus: SyncStatus): Promise<void> {
28
+ const requestType = outObject.requestType;
29
+ const entityName = outObject.beName;
30
+ const beLid = outObject.beHeaderLid;
31
+
32
+ if (requestType === RequestType.RQST.toString()) {
33
+ const databaseManager = await DatabaseManager.getInstance();
34
+ const structureMetaData = await databaseManager.select(DatabaseType.FrameworkDb, "StructureMeta", `structureName = '${entityName}'`);
35
+ if (structureMetaData.length === 0) {
36
+ await Logger.logDebug(
37
+ "OutboxHelper",
38
+ "updateSyncStatusToEntityObjects",
39
+ "No Business Entity got from database, BE-NAME: " +
40
+ outObject.beName +
41
+ ", BE-LID: " +
42
+ beLid);
43
+ return;
44
+ }
45
+ const structureFieldData = await databaseManager.select(DatabaseType.AppDb, structureMetaData[0].structureName, `${FieldConstants.FieldLid} = '${beLid}'`);
46
+ if (structureFieldData.length === 0) {
47
+ await Logger.logDebug(
48
+ "OutboxHelper",
49
+ "updateSyncStatusToEntityObjects",
50
+ `No Business Entity got from database, BE-NAME: ${outObject.beName}, BE-LID: ${beLid}`
51
+ );
52
+ return;
53
+ }
54
+ const data = structureFieldData[0];
55
+
56
+ data[FieldConstants.FieldSyncStatus] = syncStatus;
57
+ await databaseManager.update(DatabaseType.AppDb, entityName, data, `${FieldConstants.FieldLid} = '${beLid}'`);
58
+
59
+ const childStructureMetas = await databaseManager.select(DatabaseType.FrameworkDb, "StructureMeta", `beName = '${structureMetaData[0].beName}' AND isHeader != 1`);
60
+ for (const childStructureMetaData of childStructureMetas) {
61
+ await databaseManager.update(DatabaseType.AppDb, childStructureMetaData.structureName, {
62
+ [FieldConstants.FieldSyncStatus]: syncStatus
63
+ }, `${FieldConstants.FieldFid}='${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.
64
+ }
65
+ }
66
+ }
67
+ }