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.
- package/package.json +1 -1
- package/plugin.xml +1 -13
- package/www/kernel.js +38344 -1243
- package/aar/README.md +0 -3
- package/aar/Unvired_Kernel_Android.aar +0 -0
- package/aar/Unvired_Kernel_HTML5_Android.aar +0 -0
- package/src/android/build.gradle +0 -35
- package/src/android/xml/provider_paths.xml +0 -21
- package/src/browser/UnviredPluginProxy.js +0 -2430
- package/src/browser/bootstrap.min.js +0 -17
- package/src/browser/codemirror.js +0 -9755
- package/src/browser/jquery-3.2.1.js +0 -10253
- package/src/browser/sql-wasm.wasm +0 -0
- package/src/browser/sql.js +0 -203
- package/src/browser/src_index_worker_js.unvired-db-worker.js +0 -231
- package/src/browser/unvired-db-worker.js +0 -166
- package/src/browser/vendors-node_modules_comlink_dist_esm_comlink_mjs.unvired-db-worker.js +0 -22
- package/src/ios/AttachmentPlugin.h +0 -21
- package/src/ios/AttachmentPlugin.m +0 -180
- package/src/ios/DataStructureHelper.h +0 -28
- package/src/ios/DataStructureHelper.m +0 -188
- package/src/ios/IOSAuthPlugin.h +0 -14
- package/src/ios/IOSAuthPlugin.m +0 -13
- package/src/ios/IOSDatabasePlugin.h +0 -28
- package/src/ios/IOSDatabasePlugin.m +0 -253
- package/src/ios/IOSFWSettingsPlugin.h +0 -65
- package/src/ios/IOSFWSettingsPlugin.m +0 -363
- package/src/ios/IOSLoggerPlugin.h +0 -34
- package/src/ios/IOSLoggerPlugin.m +0 -198
- package/src/ios/IOSLoginPlugin.h +0 -29
- package/src/ios/IOSLoginPlugin.m +0 -480
- package/src/ios/IOSProxyPlugin.h +0 -21
- package/src/ios/IOSProxyPlugin.m +0 -172
- package/src/ios/IOSSyncEnginePlugin.h +0 -54
- package/src/ios/IOSSyncEnginePlugin.m +0 -847
- package/src/ios/PluginConstants.h +0 -195
- package/src/ios/PluginHelper.h +0 -29
- package/src/ios/PluginHelper.m +0 -74
- package/src/ios/SyncHTML5Response.h +0 -50
- package/src/ios/SyncHTML5Response.m +0 -68
- package/www/applicationMeta/applicationMetadataParser.ts +0 -285
- package/www/applicationMeta/fieldConstants.ts +0 -92
- package/www/attachment/attachmentHelper.ts +0 -326
- package/www/attachment/attachmentQHelper.ts +0 -158
- package/www/attachment/attachmentService.ts +0 -259
- package/www/authenticationService.ts +0 -751
- package/www/database/appDatabaseManager.ts +0 -54
- package/www/database/databaseManager.ts +0 -616
- package/www/helper/dbCreateTablesManager.ts +0 -354
- package/www/helper/frameworkHelper.ts +0 -127
- package/www/helper/frameworkSettingsManager.ts +0 -287
- package/www/helper/getMessageTimerManager.ts +0 -81
- package/www/helper/httpConnection.ts +0 -1051
- package/www/helper/logger.ts +0 -312
- package/www/helper/notificationListnerHelper.ts +0 -56
- package/www/helper/passcodeGenerator.ts +0 -61
- package/www/helper/reconciler.ts +0 -1062
- package/www/helper/serverResponseHandler.ts +0 -677
- package/www/helper/serviceConstants.ts +0 -254
- package/www/helper/settingsHelper.ts +0 -386
- package/www/helper/status.ts +0 -83
- package/www/helper/syncInputDataManager.ts +0 -205
- package/www/helper/unviredAccount.ts +0 -104
- package/www/helper/unviredAccountManager.ts +0 -120
- package/www/helper/urlService.ts +0 -43
- package/www/helper/userSettingsManager.ts +0 -172
- package/www/helper/utils.ts +0 -110
- package/www/inbox/downloadMessageService.ts +0 -270
- package/www/inbox/inboxHelper.ts +0 -132
- package/www/inbox/inboxService.ts +0 -223
- package/www/outbox/outboxAttachmentManager.ts +0 -152
- package/www/outbox/outboxHelper.ts +0 -67
- package/www/outbox/outboxService.ts +0 -519
- package/www/subtract.ts +0 -5
- package/www/sum.ts +0 -4
- package/www/syncEngine.ts +0 -687
|
@@ -1,259 +0,0 @@
|
|
|
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 FrameworkHelper from "../helper/frameworkHelper";
|
|
6
|
-
import { UnviredAccountManager } from "../helper/unviredAccountManager";
|
|
7
|
-
import { isServerReachable } from "../helper/utils";
|
|
8
|
-
import { HttpConnection } from "../helper/httpConnection";
|
|
9
|
-
import { Status } from "../helper/status";
|
|
10
|
-
import AttachmentHelper from "./attachmentHelper";
|
|
11
|
-
import { kAttachmentItem, kError, NotificationListenerHelper, NotificationListnerType } from "../helper/notificationListnerHelper";
|
|
12
|
-
|
|
13
|
-
const fileName = "AttachmentService"
|
|
14
|
-
|
|
15
|
-
export default class AttachmentService {
|
|
16
|
-
private static instance: AttachmentService;
|
|
17
|
-
private isRunning: boolean = false;
|
|
18
|
-
private shouldStop: boolean = false;
|
|
19
|
-
|
|
20
|
-
private constructor() {}
|
|
21
|
-
|
|
22
|
-
public static getInstance(): AttachmentService {
|
|
23
|
-
if (!AttachmentService.instance) {
|
|
24
|
-
AttachmentService.instance = new AttachmentService();
|
|
25
|
-
}
|
|
26
|
-
return AttachmentService.instance;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public start(): void {
|
|
30
|
-
if (!this.isRunning) {
|
|
31
|
-
this.isRunning = true;
|
|
32
|
-
this.shouldStop = false;
|
|
33
|
-
this.makeNetworkCallToDownloadAttachment();
|
|
34
|
-
} else {
|
|
35
|
-
Logger.logInfo(fileName, "start", "Attachment download service is already running.");
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public stop(): void {
|
|
40
|
-
if (this.isRunning) {
|
|
41
|
-
this.shouldStop = true;
|
|
42
|
-
Logger.logInfo(fileName, "stop", "Stopping attachment download service.");
|
|
43
|
-
} else {
|
|
44
|
-
Logger.logInfo(fileName, "stop", "Attachment download service is not running.");
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
private async makeNetworkCallToDownloadAttachment(): Promise<void> {
|
|
48
|
-
let continueDownloading = false;
|
|
49
|
-
const map: any = {};
|
|
50
|
-
try {
|
|
51
|
-
do {
|
|
52
|
-
if (this.shouldStop) {
|
|
53
|
-
Logger.logInfo(fileName, "makeNetworkCallToDownloadAttachment", "Stop requested. Exiting attachment download loop.");
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const databaseManager = DatabaseManager.getInstance();
|
|
58
|
-
const attachmentQObject = await databaseManager.getFirstEntity(DatabaseType.FrameworkDb, "AttachmentQObject");
|
|
59
|
-
continueDownloading = attachmentQObject !== null;
|
|
60
|
-
if (attachmentQObject !== null) {
|
|
61
|
-
const attachmentQObjectData = attachmentQObject;
|
|
62
|
-
Logger.logInfo(fileName, "makeNetworkCallToDownloadAttachment", `Processing ATTACHMENT UID : ${attachmentQObjectData.uid}.`);
|
|
63
|
-
|
|
64
|
-
const attachmentItems = await this.getAttachmentItems(attachmentQObjectData);
|
|
65
|
-
if (attachmentItems.length === 0) {
|
|
66
|
-
Logger.logInfo(fileName, "makeNetworkCallToDownloadAttachment", `Unable to get attachment item from database for UID: ${attachmentQObjectData.uid}. Structure Name: ${attachmentQObjectData.beAttachmentStructName}. So, Deleting the attachmentQObject.`);
|
|
67
|
-
try {
|
|
68
|
-
await databaseManager.delete(DatabaseType.FrameworkDb, "AttachmentQObject", `uid = '${attachmentQObjectData.uid}'`);
|
|
69
|
-
} catch (e) {
|
|
70
|
-
Logger.logError(fileName, "makeNetworkCallToDownloadAttachment", `Failed to remove attachment from attachmentQObject. UID: ${attachmentQObjectData.uid}---${JSON.stringify(e)}`);
|
|
71
|
-
}
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const attachmentItem = attachmentItems[0];
|
|
76
|
-
let retryDownload = false;
|
|
77
|
-
let data: any = {};
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
do {
|
|
81
|
-
retryDownload = false;
|
|
82
|
-
if (!navigator.onLine) {
|
|
83
|
-
continueDownloading = false;
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const lastLoggedInAccount = UnviredAccountManager.getInstance().getLastLoggedInAccount();
|
|
88
|
-
if (!(await isServerReachable(lastLoggedInAccount.getServerURL()))) {
|
|
89
|
-
continueDownloading = false;
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const result = await new HttpConnection().downloadAttachment(attachmentQObjectData.uid);
|
|
94
|
-
|
|
95
|
-
if (result.status === Status.ok) {
|
|
96
|
-
let attachmentName = attachmentItem[ServiceConstants.AttachmentItemFieldUid];
|
|
97
|
-
if (attachmentItem[ServiceConstants.AttachmentItemFieldFileName] != null && attachmentItem[ServiceConstants.AttachmentItemFieldFileName] != "") {
|
|
98
|
-
attachmentName = attachmentItem[ServiceConstants.AttachmentItemFieldFileName];
|
|
99
|
-
}
|
|
100
|
-
const arrayBuffer = await result.arrayBuffer();
|
|
101
|
-
try {
|
|
102
|
-
const attachmentPath = await AttachmentHelper.addAttachment(attachmentName, arrayBuffer);
|
|
103
|
-
attachmentItem[ServiceConstants.AttachmentItemFieldLocalPath] = attachmentPath;
|
|
104
|
-
attachmentItem[ServiceConstants.AttachmentItemFieldAttachmentStatus] = ServiceConstants.AttachmentStatusDownloaded;
|
|
105
|
-
NotificationListenerHelper.postDataSenderNotification(attachmentItem, NotificationListnerType.attachmentDownloadSuccess);
|
|
106
|
-
}
|
|
107
|
-
catch (error) {
|
|
108
|
-
continueDownloading = false;
|
|
109
|
-
const errorMessage = "Could not save the file: Error while trying to save the file. Error: " + error;
|
|
110
|
-
Logger.logError(fileName, "makeNetworkCallToDownloadAttachment", errorMessage);
|
|
111
|
-
const notifData = {
|
|
112
|
-
[kAttachmentItem]: attachmentItem,
|
|
113
|
-
[kError]: errorMessage
|
|
114
|
-
}
|
|
115
|
-
NotificationListenerHelper.postDataSenderNotification(notifData, NotificationListnerType.attachmentDownloadError);
|
|
116
|
-
}
|
|
117
|
-
} else if (result.status === Status.gone) {
|
|
118
|
-
|
|
119
|
-
const response = await result.json();
|
|
120
|
-
Logger.logError(fileName, "makeNetworkCallToDownloadAttachment", `Server status code 410. Response ${JSON.stringify(response)}`);
|
|
121
|
-
|
|
122
|
-
const errorMessage = "Error while downloading attachment.";
|
|
123
|
-
attachmentItem[ServiceConstants.AttachmentItemFieldAttachmentStatus] = ServiceConstants.AttachmentStatusErrorInDownload;
|
|
124
|
-
attachmentItem[ServiceConstants.AttachmentItemFieldMessage] = errorMessage;
|
|
125
|
-
continueDownloading = false;
|
|
126
|
-
const notifData = {
|
|
127
|
-
[kAttachmentItem]: attachmentItem,
|
|
128
|
-
[kError]: errorMessage
|
|
129
|
-
}
|
|
130
|
-
NotificationListenerHelper.postDataSenderNotification(notifData, NotificationListnerType.attachmentDownloadError);
|
|
131
|
-
} else if (result.status === Status.noContent) {
|
|
132
|
-
Logger.logInfo(fileName, "makeNetworkCallToDownloadAttachment", `Server Status code 204. Retry downloading after 10 seconds.`);
|
|
133
|
-
|
|
134
|
-
await new Promise(resolve => setTimeout(resolve, 10000));
|
|
135
|
-
if (map[attachmentQObjectData.uid] == null) {
|
|
136
|
-
map[attachmentQObjectData.uid] = 0;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
retryDownload = map[attachmentQObjectData.uid] < 3;
|
|
140
|
-
map[attachmentQObjectData.uid]++;
|
|
141
|
-
|
|
142
|
-
if (!retryDownload) {
|
|
143
|
-
Logger.logInfo(fileName, "makeNetworkCallToDownloadAttachment", `Retry download limit reached. Deleting the attachment Q object.`);
|
|
144
|
-
|
|
145
|
-
const errorMessage = "Unable to download the attachment.";
|
|
146
|
-
attachmentItem[ServiceConstants.AttachmentItemFieldAttachmentStatus] = ServiceConstants.AttachmentStatusErrorInDownload;
|
|
147
|
-
attachmentItem[ServiceConstants.AttachmentItemFieldMessage] = errorMessage;
|
|
148
|
-
const notifData = {
|
|
149
|
-
[kAttachmentItem]: attachmentItem,
|
|
150
|
-
[kError]: errorMessage
|
|
151
|
-
}
|
|
152
|
-
NotificationListenerHelper.postDataSenderNotification(notifData, NotificationListnerType.attachmentDownloadError);
|
|
153
|
-
}
|
|
154
|
-
} else {
|
|
155
|
-
Logger.logError(fileName, "makeNetworkCallToDownloadAttachment", `Server status code ${result.status}. Response ${JSON.stringify(result.body)}`);
|
|
156
|
-
|
|
157
|
-
const response = await result.json();
|
|
158
|
-
let errorMessage = "Unknown Error";
|
|
159
|
-
if (response[ServiceConstants.KeyError] != null) {
|
|
160
|
-
errorMessage = response[ServiceConstants.KeyError];
|
|
161
|
-
}
|
|
162
|
-
if (response[ServiceConstants.KeyAttachmentResponse] != null &&
|
|
163
|
-
(response[ServiceConstants.KeyAttachmentResponse])[ServiceConstants.KeyMessage_]) {
|
|
164
|
-
errorMessage = (response[ServiceConstants.KeyAttachmentResponse])[ServiceConstants.KeyMessage_];
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
attachmentItem[ServiceConstants.AttachmentItemFieldAttachmentStatus] = ServiceConstants.AttachmentStatusErrorInDownload;
|
|
168
|
-
attachmentItem[ServiceConstants.AttachmentItemFieldMessage] = errorMessage;
|
|
169
|
-
const notifData = {
|
|
170
|
-
[kAttachmentItem]: attachmentItem,
|
|
171
|
-
[kError]: errorMessage
|
|
172
|
-
}
|
|
173
|
-
NotificationListenerHelper.postDataSenderNotification(notifData, NotificationListnerType.attachmentDownloadError);
|
|
174
|
-
}
|
|
175
|
-
} while (retryDownload);
|
|
176
|
-
} catch (e) {
|
|
177
|
-
Logger.logError(fileName, "makeNetworkCallToDownloadAttachment", `Error while downloading attachment. Error: ${JSON.stringify(e)}`);
|
|
178
|
-
attachmentItem[ServiceConstants.AttachmentItemFieldAttachmentStatus] = ServiceConstants.AttachmentStatusErrorInDownload;
|
|
179
|
-
attachmentItem[ServiceConstants.AttachmentItemFieldMessage] = `Error while downloading attachment. Error: ${JSON.stringify(e)}`;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
try {
|
|
183
|
-
const result = await databaseManager.update(DatabaseType.AppDb, attachmentQObjectData.beAttachmentStructName, attachmentItem, `${ServiceConstants.AttachmentItemFieldUid} = '${attachmentItem[ServiceConstants.AttachmentItemFieldUid]}'`);
|
|
184
|
-
Logger.logInfo(fileName, "makeNetworkCallToDownloadAttachment", `Updated attachment into database. Attachment Structure Name: ${attachmentQObjectData.beAttachmentStructName}. UID: ${attachmentItem[ServiceConstants.AttachmentItemFieldUid]}. Result: ${JSON.stringify(result)}`);
|
|
185
|
-
} catch (e) {
|
|
186
|
-
Logger.logError(fileName, "makeNetworkCallToDownloadAttachment", `Error while updating attachment into database. Attachment Structure Name: ${attachmentQObjectData.beAttachmentStructName}. UID: ${attachmentItem[ServiceConstants.AttachmentItemFieldUid]}. Error: ${e}`);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
try {
|
|
190
|
-
databaseManager.delete(DatabaseType.FrameworkDb, "AttachmentQObject", `uid = '${attachmentQObjectData.uid}'`);
|
|
191
|
-
} catch (e) {
|
|
192
|
-
Logger.logError(fileName, "makeNetworkCallToDownloadAttachment", `Error while removing attachment from attachmentQObject. UID: ${attachmentQObjectData.uid}---${e.toString()}`);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (map[attachmentQObjectData.uid] != null) {
|
|
196
|
-
delete map[attachmentQObjectData.uid];
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
} while (continueDownloading);
|
|
200
|
-
await this.checkAndUpdateAttachmentDownloadStatus();
|
|
201
|
-
Logger.logInfo(fileName, "makeNetworkCallToDownloadAttachment", `Stopping the attachment service.`);
|
|
202
|
-
}
|
|
203
|
-
catch (e) {
|
|
204
|
-
Logger.logError(fileName, "makeNetworkCallToDownloadAttachment", `Error while downloading attachment. Error: ${e}`);
|
|
205
|
-
}
|
|
206
|
-
finally {
|
|
207
|
-
this.isRunning = false;
|
|
208
|
-
this.shouldStop = false;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
private async getAttachmentItems(attachmentQObjectData: any): Promise<any[]> {
|
|
213
|
-
const databaseManager = DatabaseManager.getInstance();
|
|
214
|
-
const whereClause = `${ServiceConstants.AttachmentItemFieldUid} = '${attachmentQObjectData.uid}'`;
|
|
215
|
-
const attachmentItems = await databaseManager.select(DatabaseType.AppDb, `${attachmentQObjectData.beAttachmentStructName}`, whereClause);
|
|
216
|
-
return attachmentItems;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
private async checkAndUpdateAttachmentDownloadStatus(): Promise<void> {
|
|
220
|
-
try {
|
|
221
|
-
const databaseManager = DatabaseManager.getInstance()
|
|
222
|
-
const attachmentsStructMetas = await databaseManager.select(DatabaseType.FrameworkDb, "StructureMeta", `structureName LIKE '%${ServiceConstants.AttachmentBE}'`);
|
|
223
|
-
const allBusinessEntityMetas = await databaseManager.select(DatabaseType.FrameworkDb, "BusinessEntityMeta");
|
|
224
|
-
|
|
225
|
-
const allAttachmentQItems = await databaseManager.select(DatabaseType.FrameworkDb, "AttachmentQObject");
|
|
226
|
-
const allAttachmentBeLids = allAttachmentQItems.map((e:any) => e.uid);
|
|
227
|
-
let attachmentUidsString = "";
|
|
228
|
-
if (allAttachmentBeLids.length > 0) {
|
|
229
|
-
attachmentUidsString = "'" + allAttachmentBeLids.join("','") + "'";
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
for (const attachmentsStructMeta of attachmentsStructMetas) {
|
|
233
|
-
try {
|
|
234
|
-
const currentBeMeta =
|
|
235
|
-
allBusinessEntityMetas.find(
|
|
236
|
-
(element) => element.beName === attachmentsStructMeta.beName);
|
|
237
|
-
if (currentBeMeta!.save === "false" || currentBeMeta!.attachments !== "1") {
|
|
238
|
-
continue;
|
|
239
|
-
}
|
|
240
|
-
const allData = await databaseManager.select(DatabaseType.AppDb, attachmentsStructMeta.structureName, `${ServiceConstants.AttachmentItemFieldAttachmentStatus}='${ServiceConstants.AttachmentStatusQueuedForDownload}'` + (attachmentUidsString.length > 0 ? ` AND ${ServiceConstants.AttachmentItemFieldUid} NOT IN (${attachmentUidsString})`: ""))
|
|
241
|
-
for (const attachmentData of allData) {
|
|
242
|
-
try {
|
|
243
|
-
await databaseManager.update(DatabaseType.AppDb, attachmentsStructMeta.structureName, {
|
|
244
|
-
[ServiceConstants.AttachmentItemFieldAttachmentStatus]: ServiceConstants.AttachmentStatusErrorInDownload,
|
|
245
|
-
[ServiceConstants.AttachmentItemFieldMessage]: "The connection was interrupted. Please try again."
|
|
246
|
-
}, `${ServiceConstants.AttachmentItemFieldUid} = '${attachmentData[ServiceConstants.AttachmentItemFieldUid]}'`, true); // isFromApp is true because it just need to update the data and should not set the missing fields to null.
|
|
247
|
-
} catch (e) {
|
|
248
|
-
Logger.logError(fileName, "checkAndUpdateAttachmentDownloadStatus", `Error while updating (${attachmentsStructMeta.structureName}) attachment download status into database. Error: ${e}`);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
} catch (e) {
|
|
252
|
-
Logger.logError(fileName, "checkAndUpdateAttachmentDownloadStatus", `Error while getting BE Meta for (${attachmentsStructMeta.structureName}). Error: ${e}`);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
} catch (e) {
|
|
256
|
-
Logger.logError(fileName, "checkAndUpdateAttachmentDownloadStatus", `Error while updating attachment download Status to ERROR. Error: ${e}`);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|