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,172 +0,0 @@
|
|
|
1
|
-
import { DatabaseManager, DatabaseType } from "../database/databaseManager";
|
|
2
|
-
import FrameworkHelper from "./frameworkHelper";
|
|
3
|
-
import { Logger } from "./logger";
|
|
4
|
-
import { ObjectStatus, SyncStatus } from "./utils";
|
|
5
|
-
|
|
6
|
-
export enum UserSettingsFields {
|
|
7
|
-
serverUserId,
|
|
8
|
-
serverPassword,
|
|
9
|
-
unviredUserId,
|
|
10
|
-
unviredPassword,
|
|
11
|
-
serverUrl,
|
|
12
|
-
companyAlias,
|
|
13
|
-
deviceType,
|
|
14
|
-
customDeviceId,
|
|
15
|
-
companyNamespace,
|
|
16
|
-
requestTimeout,
|
|
17
|
-
demoMode,
|
|
18
|
-
domainName,
|
|
19
|
-
loginType,
|
|
20
|
-
notificationTimeout,
|
|
21
|
-
fetchInterval,
|
|
22
|
-
serverCertificateHash,
|
|
23
|
-
currentFrameworkVersion,
|
|
24
|
-
unviredPin,
|
|
25
|
-
unviredId,
|
|
26
|
-
jwtToken
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const stringToUserSettingsFields = (fieldName: string): UserSettingsFields => {
|
|
30
|
-
switch(fieldName) {
|
|
31
|
-
case "serverUserId":
|
|
32
|
-
return UserSettingsFields.serverUserId;
|
|
33
|
-
case "serverPassword":
|
|
34
|
-
return UserSettingsFields.serverPassword;
|
|
35
|
-
case "unviredUserId":
|
|
36
|
-
return UserSettingsFields.unviredUserId;
|
|
37
|
-
case "unviredPassword":
|
|
38
|
-
return UserSettingsFields.unviredPassword;
|
|
39
|
-
case "serverUrl":
|
|
40
|
-
return UserSettingsFields.serverUrl;
|
|
41
|
-
case "companyAlias":
|
|
42
|
-
return UserSettingsFields.companyAlias;
|
|
43
|
-
case "deviceType":
|
|
44
|
-
return UserSettingsFields.deviceType;
|
|
45
|
-
case "customDeviceId":
|
|
46
|
-
return UserSettingsFields.customDeviceId;
|
|
47
|
-
case "companyNamespace":
|
|
48
|
-
return UserSettingsFields.companyNamespace;
|
|
49
|
-
case "requestTimeout":
|
|
50
|
-
return UserSettingsFields.requestTimeout;
|
|
51
|
-
case "demoMode":
|
|
52
|
-
return UserSettingsFields.demoMode;
|
|
53
|
-
case "domainName":
|
|
54
|
-
return UserSettingsFields.domainName;
|
|
55
|
-
case "loginType":
|
|
56
|
-
return UserSettingsFields.loginType;
|
|
57
|
-
case "notificationTimeout":
|
|
58
|
-
return UserSettingsFields.notificationTimeout;
|
|
59
|
-
case "fetchInterval":
|
|
60
|
-
return UserSettingsFields.fetchInterval;
|
|
61
|
-
case "serverCertificateHash":
|
|
62
|
-
return UserSettingsFields.serverCertificateHash;
|
|
63
|
-
case "currentFrameworkVersion":
|
|
64
|
-
return UserSettingsFields.currentFrameworkVersion;
|
|
65
|
-
case "unviredPin":
|
|
66
|
-
return UserSettingsFields.unviredPin;
|
|
67
|
-
case "unviredId":
|
|
68
|
-
return UserSettingsFields.unviredId;
|
|
69
|
-
case "jwtToken":
|
|
70
|
-
return UserSettingsFields.jwtToken;
|
|
71
|
-
default:
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export class UserSettingsManager {
|
|
77
|
-
private userSettingsHashtable: any = {};
|
|
78
|
-
|
|
79
|
-
private static instance: UserSettingsManager | null = null;
|
|
80
|
-
|
|
81
|
-
private constructor() {
|
|
82
|
-
// private constructor to prevent instantiation
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
public static getInstance(): UserSettingsManager {
|
|
86
|
-
if (!UserSettingsManager.instance) {
|
|
87
|
-
UserSettingsManager.instance = new UserSettingsManager();
|
|
88
|
-
}
|
|
89
|
-
return UserSettingsManager.instance;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async setFieldValue(field: UserSettingsFields, fieldValue: any): Promise<void> {
|
|
93
|
-
if (field == null) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
const fieldName = UserSettingsFields[field];
|
|
97
|
-
await this.setFieldValueForKey(fieldName, fieldValue);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async getFieldValue(field: UserSettingsFields): Promise<string> {
|
|
101
|
-
if (field == null) {
|
|
102
|
-
return "";
|
|
103
|
-
}
|
|
104
|
-
const fieldName = UserSettingsFields[field];
|
|
105
|
-
return await this.getFieldValueForKey(fieldName);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
private async setFieldValueForKey(fieldName: string, fieldValue: any): Promise<void> {
|
|
109
|
-
const databaseManager = DatabaseManager.getInstance();
|
|
110
|
-
let userSetting: any;
|
|
111
|
-
try {
|
|
112
|
-
userSetting = await databaseManager.select(DatabaseType.FrameworkDb, "Settings", `fieldName = '${fieldName}'`)
|
|
113
|
-
} catch (e) {}
|
|
114
|
-
|
|
115
|
-
if (userSetting === null || userSetting.length === 0) {
|
|
116
|
-
const settingObject = {
|
|
117
|
-
lid: FrameworkHelper.getUUID(),
|
|
118
|
-
timestamp: Date.now(),
|
|
119
|
-
objectStatus: ObjectStatus.global,
|
|
120
|
-
syncStatus: SyncStatus.none,
|
|
121
|
-
fieldName: fieldName,
|
|
122
|
-
fieldValue: `${fieldValue}`
|
|
123
|
-
};
|
|
124
|
-
this.userSettingsHashtable[fieldName] = settingObject;
|
|
125
|
-
await databaseManager.insert(DatabaseType.FrameworkDb, "Settings", settingObject, true);
|
|
126
|
-
} else {
|
|
127
|
-
const settingObject = {
|
|
128
|
-
lid: userSetting[0].lid,
|
|
129
|
-
timestamp: Date.now(),
|
|
130
|
-
objectStatus: userSetting[0].objectStatus,
|
|
131
|
-
syncStatus: userSetting[0].syncStatus,
|
|
132
|
-
fieldName: fieldName,
|
|
133
|
-
fieldValue: `${fieldValue}`
|
|
134
|
-
};
|
|
135
|
-
this.userSettingsHashtable[fieldName] = settingObject;
|
|
136
|
-
await databaseManager.update(DatabaseType.FrameworkDb, "Settings", settingObject, `lid = '${userSetting[0].lid}'`);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
private async getFieldValueForKey(fieldName: string): Promise<string> {
|
|
141
|
-
if (this.userSettingsHashtable && this.userSettingsHashtable[fieldName]) {
|
|
142
|
-
return this.userSettingsHashtable[fieldName].fieldValue;
|
|
143
|
-
}
|
|
144
|
-
const databaseManager = DatabaseManager.getInstance();
|
|
145
|
-
try {
|
|
146
|
-
const userSetting = await databaseManager.select(DatabaseType.FrameworkDb, "Settings", `fieldName = '${fieldName}'`)
|
|
147
|
-
if (userSetting === null || userSetting.length === 0) {
|
|
148
|
-
return "";
|
|
149
|
-
}
|
|
150
|
-
this.userSettingsHashtable[fieldName] = userSetting[0];
|
|
151
|
-
return userSetting[0].fieldValue;
|
|
152
|
-
} catch (e) {
|
|
153
|
-
Logger.logError("UserSettingsManager", "getFieldValue", `Error while getting settings. Error: ${JSON.stringify(e)}`);
|
|
154
|
-
}
|
|
155
|
-
return "";
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
static getDemoModeUserSettings(loginParameters: any): { [key: string]: any } {
|
|
159
|
-
const tempFrameworkSettings = {
|
|
160
|
-
companyAlias: loginParameters.company,
|
|
161
|
-
isDemo: "true",
|
|
162
|
-
deviceType: FrameworkHelper.getFrontendType(),
|
|
163
|
-
loginType: loginParameters.loginType,
|
|
164
|
-
customDeviceId: "demo",
|
|
165
|
-
serverUserId: "demo",
|
|
166
|
-
serverPassword: "demo",
|
|
167
|
-
serverUrl: loginParameters.url,
|
|
168
|
-
currentFrameworkVersion: "DEMO v1.0"
|
|
169
|
-
};
|
|
170
|
-
return tempFrameworkSettings;
|
|
171
|
-
}
|
|
172
|
-
}
|
package/www/helper/utils.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { Logger } from "./logger";
|
|
2
|
-
import { URLService } from "./urlService";
|
|
3
|
-
|
|
4
|
-
export enum LoginType {
|
|
5
|
-
unvired = 'UNVIRED_ID',
|
|
6
|
-
ads = 'ADS',
|
|
7
|
-
sap = 'SAP',
|
|
8
|
-
email = 'EMAIL',
|
|
9
|
-
saml2 = 'SAML2',
|
|
10
|
-
custom = 'CUSTOM',
|
|
11
|
-
passwordless = "PASSWORDLESS"
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export enum ObjectStatus {
|
|
15
|
-
global = 0,
|
|
16
|
-
add = 1,
|
|
17
|
-
modify = 2,
|
|
18
|
-
delete = 3
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export enum SyncStatus {
|
|
22
|
-
none = 0,
|
|
23
|
-
queued = 1,
|
|
24
|
-
sent = 2,
|
|
25
|
-
error = 3
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export enum LoginListenerType {
|
|
29
|
-
auth_activation_required = 0, // Mobile app not yet activated and requires authentication and activation
|
|
30
|
-
app_requires_login = 1, // Mobile app requires offline / local login
|
|
31
|
-
auth_activation_success = 2, // Account authenticated and activated on the server
|
|
32
|
-
auth_activation_error = 3, // Acoount authentication or aactivation failed on the server
|
|
33
|
-
login_success = 4, // Mobile app login successful
|
|
34
|
-
login_error = 5, // Mobile app login failure
|
|
35
|
-
app_requires_current_account = 6, // Multiple account found hence app has to set current active account
|
|
36
|
-
login_demo = 7 // This value indicates app can proceed with demo mode.
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export enum LogType {
|
|
40
|
-
debug,
|
|
41
|
-
info,
|
|
42
|
-
error
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export class LoginParameters {
|
|
46
|
-
appName: string;
|
|
47
|
-
company: string;
|
|
48
|
-
username: string;
|
|
49
|
-
password: string;
|
|
50
|
-
url: string;
|
|
51
|
-
domain: string;
|
|
52
|
-
loginType: LoginType;
|
|
53
|
-
feUserId: string;
|
|
54
|
-
port: string;
|
|
55
|
-
isRequiredAttachmentBase64: boolean;
|
|
56
|
-
autoSendTime: string;
|
|
57
|
-
autoSyncTime: string;
|
|
58
|
-
metadataJSON: string;
|
|
59
|
-
demoData: string;
|
|
60
|
-
demoModeRequired: boolean;
|
|
61
|
-
persistWebDb: boolean;
|
|
62
|
-
jwtOptions: object;
|
|
63
|
-
loginLanguage: string;
|
|
64
|
-
cacheWebData: boolean;
|
|
65
|
-
requireClientCredentials: boolean;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export async function isInternetConnected(): Promise<boolean> {
|
|
69
|
-
let internetConnected = false
|
|
70
|
-
try {
|
|
71
|
-
const response = await fetch('https://www.google.com/favicon.ico'); // Replace with a reliable resource
|
|
72
|
-
if (response.ok) {
|
|
73
|
-
Logger.logInfo("Utils", "isInternetConnected", "You are connected to the internet");
|
|
74
|
-
internetConnected = true
|
|
75
|
-
} else {
|
|
76
|
-
Logger.logInfo("Utils", "isInternetConnected", "There might be internet connection issues");
|
|
77
|
-
}
|
|
78
|
-
} catch (error) {
|
|
79
|
-
Logger.logError("Utils", "isInternetConnected", "Error checking internet connection: " + error);
|
|
80
|
-
}
|
|
81
|
-
return internetConnected
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export async function isServerReachable(baseUrl: string): Promise<boolean> {
|
|
85
|
-
if (baseUrl.length == 0) {
|
|
86
|
-
await Logger.logError("Utils", "isServerReachable", "Server URL is empty.");
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
const pingUrl = URLService.getPingUrl(baseUrl);
|
|
90
|
-
const url = new URL(pingUrl);
|
|
91
|
-
const controller = new AbortController();
|
|
92
|
-
const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 seconds timeout
|
|
93
|
-
try {
|
|
94
|
-
const response = await fetch(url.toString(), {
|
|
95
|
-
headers: {
|
|
96
|
-
"Accept": "application/json"
|
|
97
|
-
},
|
|
98
|
-
signal: controller.signal
|
|
99
|
-
});
|
|
100
|
-
clearTimeout(timeoutId);
|
|
101
|
-
return response.status === 200;
|
|
102
|
-
} catch (error) {
|
|
103
|
-
if (error.name === 'AbortError') {
|
|
104
|
-
await Logger.logError("HTTPConnection", "isServerReachable", "Server not reachable within 10 seconds. Error: " + error);
|
|
105
|
-
} else {
|
|
106
|
-
await Logger.logError("HTTPConnection", "isServerReachable", "Error while pinging to server. Error: " + error);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
import { AuthenticationService } from "../authenticationService";
|
|
2
|
-
import { HttpConnection } from "../helper/httpConnection";
|
|
3
|
-
import { Logger, LogLevel } from "../helper/logger";
|
|
4
|
-
import { Status } from "../helper/status";
|
|
5
|
-
import { UnviredAccountManager } from "../helper/unviredAccountManager";
|
|
6
|
-
import { isServerReachable, ObjectStatus, SyncStatus } from "../helper/utils";
|
|
7
|
-
import * as ServiceConstants from '../helper/serviceConstants'
|
|
8
|
-
import DatabaseManager, { DatabaseType } from "../database/databaseManager";
|
|
9
|
-
import FrameworkHelper from "../helper/frameworkHelper";
|
|
10
|
-
import SettingsHelper from "../helper/settingsHelper";
|
|
11
|
-
import InboxHelper from "./inboxHelper";
|
|
12
|
-
import InboxService from "./inboxService";
|
|
13
|
-
import { NotificationListenerHelper, NotificationListnerType } from "../helper/notificationListnerHelper";
|
|
14
|
-
|
|
15
|
-
const fileName = "DownloadMessageService"
|
|
16
|
-
export default class DownloadMessageService {
|
|
17
|
-
private static instance: DownloadMessageService;
|
|
18
|
-
private isRunning: boolean = false;
|
|
19
|
-
private shouldStop: boolean = false;
|
|
20
|
-
|
|
21
|
-
private constructor() {}
|
|
22
|
-
|
|
23
|
-
public static getInstance(): DownloadMessageService {
|
|
24
|
-
if (!DownloadMessageService.instance) {
|
|
25
|
-
DownloadMessageService.instance = new DownloadMessageService();
|
|
26
|
-
}
|
|
27
|
-
return DownloadMessageService.instance;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public start(): void {
|
|
31
|
-
if (this.isRunning) {
|
|
32
|
-
Logger.logInfo(fileName, "start", "Download message service is already running.");
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
this.isRunning = true;
|
|
36
|
-
this.shouldStop = false;
|
|
37
|
-
this.checkAndDownloadMessages();
|
|
38
|
-
Logger.logInfo(fileName, "start", "Download message service started.");
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public stop(): void {
|
|
42
|
-
if (this.isRunning) {
|
|
43
|
-
this.shouldStop = true;
|
|
44
|
-
Logger.logInfo(fileName, "stop", "Stopping download message service.");
|
|
45
|
-
} else {
|
|
46
|
-
Logger.logInfo(fileName, "stop", "Download message service is not running.");
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
private async checkAndDownloadMessages(): Promise<void> {
|
|
51
|
-
let downloadedMessagesCount = 0;
|
|
52
|
-
try {
|
|
53
|
-
Logger.logInfo(fileName, "checkAndDownloadMessages", "Starting download message service.")
|
|
54
|
-
let continueDownloading = false;
|
|
55
|
-
do {
|
|
56
|
-
if (this.shouldStop) {
|
|
57
|
-
Logger.logInfo(fileName, "checkAndDownloadMessages", "Stop requested. Exiting message download loop.")
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
if (!navigator.onLine) {
|
|
61
|
-
Logger.logError(fileName, "checkAndDownloadMessages", "Internet is not connected. Exitting message download loop.")
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
const lastLoggedInAccount = UnviredAccountManager.getInstance().getLastLoggedInAccount();
|
|
65
|
-
if (!(await isServerReachable(lastLoggedInAccount.getServerURL()))) {
|
|
66
|
-
Logger.logError(fileName, "checkAndDownloadMessages", "Server is not reachable. Exitting message download loop.")
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
Logger.logInfo(fileName, "checkAndDownloadMessages", "Fetching next message to download.")
|
|
71
|
-
NotificationListenerHelper.postSynchronizationStateNotification(`receiving (${downloadedMessagesCount+1})`);
|
|
72
|
-
continueDownloading = await this.downloadMessage();
|
|
73
|
-
if (continueDownloading) {
|
|
74
|
-
downloadedMessagesCount++;
|
|
75
|
-
}
|
|
76
|
-
} while (continueDownloading);
|
|
77
|
-
Logger.logInfo(fileName, "checkAndDownloadMessages", `No more message to download. Total messages downloaded: ${downloadedMessagesCount}`)
|
|
78
|
-
if (downloadedMessagesCount > 0) {
|
|
79
|
-
NotificationListenerHelper.postDataSenderNotification(null, NotificationListnerType.data_received);
|
|
80
|
-
}
|
|
81
|
-
} catch (e) {
|
|
82
|
-
Logger.logError(fileName, "checkAndDownloadMessages", e.toString())
|
|
83
|
-
} finally {
|
|
84
|
-
Logger.logInfo(fileName, "checkAndDownloadMessages", "Stopping download message service.")
|
|
85
|
-
this.isRunning = false;
|
|
86
|
-
this.shouldStop = false;
|
|
87
|
-
InboxService.getInstance().start()
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
private async downloadMessage(): Promise<boolean> {
|
|
92
|
-
let didDownloadMessages = false;
|
|
93
|
-
try {
|
|
94
|
-
Logger.logInfo(fileName, "downloadMessage", "Starting the main downloading message process.")
|
|
95
|
-
const lastLoggedInAccount = UnviredAccountManager.getInstance().getLastLoggedInAccount();
|
|
96
|
-
const result = await new HttpConnection().downloadMessage(lastLoggedInAccount, AuthenticationService.instance.loginParameters);
|
|
97
|
-
|
|
98
|
-
if (result.httpStatusCode === Status.ok) {
|
|
99
|
-
try {
|
|
100
|
-
Logger.logInfo(fileName, "downloadMessage", "downloadMessageService result")
|
|
101
|
-
const responseData = JSON.parse(result.data);
|
|
102
|
-
const headerObj = JSON.parse(result.header);
|
|
103
|
-
const messageType = headerObj[ServiceConstants.HeaderConstantMessageType.toLowerCase()];
|
|
104
|
-
if (messageType != null &&
|
|
105
|
-
messageType == ServiceConstants.MESSAGE_TYPE_WIPE.toString()) {
|
|
106
|
-
const responseJson = {
|
|
107
|
-
"error":
|
|
108
|
-
"Deleted all the data for this application from device . Please exit the application by pressing the 'Home' button in your device.",
|
|
109
|
-
"systemError": 13
|
|
110
|
-
};
|
|
111
|
-
// TODO: Post Notification to the app
|
|
112
|
-
Logger.logError(fileName, "downloadMessage", "Deleted all the data for this application from device . Please exit the application by pressing the 'Home' button in your device.");
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const conversationId = headerObj[ServiceConstants.HeaderConstantConversationId.toLowerCase()];
|
|
117
|
-
let requestType = headerObj[ServiceConstants.HeaderConstantRequestType.toLowerCase()];
|
|
118
|
-
const pendingMessageCount = headerObj[ServiceConstants.HeaderConstantNumberOfPendingMessages.toLowerCase()];
|
|
119
|
-
if (pendingMessageCount != null && pendingMessageCount > 0) {
|
|
120
|
-
NotificationListenerHelper.postSynchronizationStateNotification(`receiving (${pendingMessageCount})`);
|
|
121
|
-
}
|
|
122
|
-
let type = -1;
|
|
123
|
-
let subType = -1;
|
|
124
|
-
let appId = "";
|
|
125
|
-
let serverId = "";
|
|
126
|
-
let applicationName = "";
|
|
127
|
-
|
|
128
|
-
if (ServiceConstants.Type in responseData && ServiceConstants.Subtype in responseData) {
|
|
129
|
-
type = responseData[ServiceConstants.Type];
|
|
130
|
-
subType = responseData[ServiceConstants.Subtype];
|
|
131
|
-
appId = responseData[ServiceConstants.ApplicationId];
|
|
132
|
-
serverId = responseData[ServiceConstants.ServerId];
|
|
133
|
-
applicationName = responseData[ServiceConstants.AppName];
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (headerObj[ServiceConstants.HeaderConstantPullMode] === ServiceConstants.PullModeDelete) {
|
|
137
|
-
requestType = "PULL_D";
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
Logger.logInfo(fileName, "downloadMessage", `downloadMessageService result. TYPE: ${type}`)
|
|
141
|
-
Logger.logInfo(fileName, "downloadMessage", `downloadMessageService result. SUB_TYPE: ${subType}`)
|
|
142
|
-
const databaseManager = DatabaseManager.getInstance();
|
|
143
|
-
if (conversationId != null && requestType != null) {
|
|
144
|
-
const sentItems = await databaseManager.select(DatabaseType.FrameworkDb, "SentItems", `conversationId = '${conversationId}'`);
|
|
145
|
-
let entityName = "";
|
|
146
|
-
let beLid = "";
|
|
147
|
-
if (sentItems.length > 0) {
|
|
148
|
-
entityName = sentItems[0].beName;
|
|
149
|
-
beLid = sentItems[0].beHeaderLid;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const inObjectData: any = {
|
|
153
|
-
lid: FrameworkHelper.getUUID(),
|
|
154
|
-
timestamp: Date.now(),
|
|
155
|
-
objectStatus: ObjectStatus.global,
|
|
156
|
-
syncStatus: SyncStatus.none,
|
|
157
|
-
conversationId: conversationId,
|
|
158
|
-
requestType: requestType,
|
|
159
|
-
jsonData: entityName,
|
|
160
|
-
beLid: beLid,
|
|
161
|
-
subtype: subType,
|
|
162
|
-
serverId: serverId,
|
|
163
|
-
type: type,
|
|
164
|
-
appName: applicationName,
|
|
165
|
-
appId: appId
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
const inObjectsArray = await databaseManager.select(DatabaseType.FrameworkDb, "InObject", `conversationId = '${conversationId}'`)
|
|
169
|
-
|
|
170
|
-
if (inObjectsArray.length == 0) {
|
|
171
|
-
try {
|
|
172
|
-
await InboxHelper.addInBoxData(conversationId, JSON.stringify(responseData));
|
|
173
|
-
}
|
|
174
|
-
catch (e) {
|
|
175
|
-
Logger.logError(fileName, "downloadMessage", `Failed to add inbox data to file. Error: ${JSON.stringify(e)}`);
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
await databaseManager.insert(DatabaseType.FrameworkDb, "InObject", inObjectData, true);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// TODO: Post Notification to the app
|
|
182
|
-
|
|
183
|
-
Logger.logInfo(fileName, "downloadMessage", "acknowledgeMessageService")
|
|
184
|
-
|
|
185
|
-
const response = await new HttpConnection().acknowledgeMessageService(conversationId);
|
|
186
|
-
|
|
187
|
-
if (response.status !== Status.noContent) {
|
|
188
|
-
Logger.logInfo(fileName, "downloadMessage", `acknowledgeMessageService server return status code ${response.status}.`)
|
|
189
|
-
if (response.status === Status.gone) {
|
|
190
|
-
Logger.logError(fileName, "downloadMessage", `acknowledgeMessageService server return status code 410.`)
|
|
191
|
-
const responseObject = await response.json();
|
|
192
|
-
if (responseObject.systemError != null && responseObject.systemError === 13) {
|
|
193
|
-
// TODO: Post Notification to the app
|
|
194
|
-
return false;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
didDownloadMessages = true;
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
didDownloadMessages = false;
|
|
202
|
-
}
|
|
203
|
-
} catch (e) {
|
|
204
|
-
Logger.logError(fileName, "downloadMessage", `downloadMessageService result - Failed ${JSON.stringify(e)}`)
|
|
205
|
-
return false;
|
|
206
|
-
}
|
|
207
|
-
} else if (result.httpStatusCode === Status.gone) {
|
|
208
|
-
Logger.logError(fileName, "downloadMessage", `downloadMessageService result - Server return status code 410. Response: ${JSON.stringify(result.data)}`)
|
|
209
|
-
const response = result.data;
|
|
210
|
-
// TODO: Post Notification to the app
|
|
211
|
-
return false;
|
|
212
|
-
} else if (result.httpStatusCode === Status.noContent) {
|
|
213
|
-
Logger.logInfo(fileName, "downloadMessage", "Nothing to download. Server return status code: 204")
|
|
214
|
-
// TODO: Post Notification to the app
|
|
215
|
-
return false;
|
|
216
|
-
} else {
|
|
217
|
-
Logger.logError(fileName, "downloadMessage", `downloadMessageService result - Failed ${JSON.stringify(result.data)}`)
|
|
218
|
-
return false;
|
|
219
|
-
}
|
|
220
|
-
} catch (e) {
|
|
221
|
-
if (e.name === 'AbortError') {
|
|
222
|
-
await Logger.logError("HTTPConnection", "makeSyncCall", "Request timed out. Error: " + JSON.stringify(e));
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
Logger.logError(fileName, "downloadMessage", `downloadMessageService result - Failed ${JSON.stringify(e)}`)
|
|
226
|
-
}
|
|
227
|
-
return false;
|
|
228
|
-
}
|
|
229
|
-
Logger.logInfo(fileName, "downloadMessage", "Current message downloaded successfully. Proceed with next message download.")
|
|
230
|
-
return true;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
static async handleMessageTypes(inObject: any): Promise<void> {
|
|
234
|
-
const messageType = inObject.type;
|
|
235
|
-
const subType = inObject.subtype;
|
|
236
|
-
switch (messageType) {
|
|
237
|
-
case ServiceConstants.MESSAGE_TYPE_SYSTEM:
|
|
238
|
-
await DownloadMessageService.systemMessageHandler(subType);
|
|
239
|
-
return;
|
|
240
|
-
default:
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
static async systemMessageHandler(subType: number): Promise<void> {
|
|
246
|
-
switch (subType) {
|
|
247
|
-
case ServiceConstants.MESSAGE_SUBTYPE_SYSTEM_PING:
|
|
248
|
-
await SettingsHelper.queuePingToOutbox();
|
|
249
|
-
return;
|
|
250
|
-
case ServiceConstants.MESSAGE_SUBTYPE_SYSTEM_LOG:
|
|
251
|
-
await SettingsHelper.sendLogsToServer();
|
|
252
|
-
return;
|
|
253
|
-
case ServiceConstants.MESSAGE_SUBTYPE_SYSTEM_LOG_RESET:
|
|
254
|
-
await SettingsHelper.deleteLogs();
|
|
255
|
-
return;
|
|
256
|
-
case ServiceConstants.MESSAGE_SUBTYPE_SYSTEM_LOG_SET_DEBUG:
|
|
257
|
-
await SettingsHelper.setLogLevel(LogLevel.Debug);
|
|
258
|
-
return;
|
|
259
|
-
case ServiceConstants.MESSAGE_SUBTYPE_SYSTEM_LOG_SET_ERROR:
|
|
260
|
-
await SettingsHelper.setLogLevel(LogLevel.Error);
|
|
261
|
-
return;
|
|
262
|
-
case ServiceConstants.MESSAGE_SUBTYPE_SYSTEM_DATA_DUMP:
|
|
263
|
-
await SettingsHelper.sendAppDbToServer();
|
|
264
|
-
return;
|
|
265
|
-
default:
|
|
266
|
-
// TODO: Post Notification to the app
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
package/www/inbox/inboxHelper.ts
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { UnviredAccountManager } from "../helper/unviredAccountManager";
|
|
2
|
-
import { Logger } from "../helper/logger";
|
|
3
|
-
import FrameworkHelper from "../helper/frameworkHelper";
|
|
4
|
-
import DatabaseManager, { DatabaseType } from "../database/databaseManager";
|
|
5
|
-
|
|
6
|
-
const fileName = "InboxHelper";
|
|
7
|
-
|
|
8
|
-
export default class InboxHelper {
|
|
9
|
-
private static readonly INBOX_DIR = 'Inbox/';
|
|
10
|
-
|
|
11
|
-
private static getInboxDirectory(): Promise<string> {
|
|
12
|
-
return new Promise(async (resolve, reject) => {
|
|
13
|
-
const account = UnviredAccountManager.getInstance().getLastLoggedInAccount()
|
|
14
|
-
const userDirectory = await FrameworkHelper.getFolderBasedOnUserId(account.getAccountId());
|
|
15
|
-
const inboxDir = `${userDirectory}${InboxHelper.INBOX_DIR}`;
|
|
16
|
-
window.resolveLocalFileSystemURL(inboxDir, (dir) => {
|
|
17
|
-
Logger.logInfo(fileName, "getInboxDirectory", "Directory exists: " + dir.fullPath);
|
|
18
|
-
resolve(dir.nativeURL);
|
|
19
|
-
}, (error) => {
|
|
20
|
-
Logger.logInfo(fileName, "getInboxDirectory", "Directory did not exist. Error: " + error);
|
|
21
|
-
// Directory did not exist, so creating it.
|
|
22
|
-
Logger.logInfo(fileName, "getInboxDirectory", "Directory did not exist, so creating it: " + inboxDir);
|
|
23
|
-
window.resolveLocalFileSystemURL(userDirectory, (parentDir) => {
|
|
24
|
-
parentDir.getDirectory(InboxHelper.INBOX_DIR, {create: true}, (newDir) => {
|
|
25
|
-
Logger.logInfo(fileName, "getInboxDirectory", "Directory created: " + newDir.nativeURL);
|
|
26
|
-
resolve(newDir.nativeURL);
|
|
27
|
-
}, (error) => {
|
|
28
|
-
Logger.logError(fileName, "getInboxDirectory", "Unable to create Inbox directory. Error: " + error);
|
|
29
|
-
resolve("");
|
|
30
|
-
})
|
|
31
|
-
}, (error) => {
|
|
32
|
-
Logger.logError(fileName, "getInboxDirectory", "Unable to get Inbox directory. Error: " + error);
|
|
33
|
-
resolve("");
|
|
34
|
-
})
|
|
35
|
-
})
|
|
36
|
-
})
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
static addInBoxData(conversationId: string, jsonString: string): Promise<void> {
|
|
40
|
-
return new Promise(async (resolve, reject) => {
|
|
41
|
-
const inboxDir = await this.getInboxDirectory();
|
|
42
|
-
window.resolveLocalFileSystemURL(inboxDir, (dirEntry) => {
|
|
43
|
-
dirEntry.getFile(`${conversationId}.json`, { create: true }, (fileEntry) => {
|
|
44
|
-
fileEntry.createWriter((fileWriter) => {
|
|
45
|
-
fileWriter.onwriteend = () => {
|
|
46
|
-
Logger.logInfo(fileName, "addInBoxData", "Write completed");
|
|
47
|
-
resolve();
|
|
48
|
-
};
|
|
49
|
-
fileWriter.onerror = (e) => {
|
|
50
|
-
Logger.logError(fileName, "addInBoxData", "Write error: " + e);
|
|
51
|
-
reject(e);
|
|
52
|
-
};
|
|
53
|
-
fileWriter.write(jsonString);
|
|
54
|
-
},
|
|
55
|
-
(error) => {
|
|
56
|
-
Logger.logError(fileName, "addInBoxData", "Create writer error: " + error);
|
|
57
|
-
reject(error);
|
|
58
|
-
});
|
|
59
|
-
},
|
|
60
|
-
(error) => {
|
|
61
|
-
Logger.logError(fileName, "addInBoxData", "Get file error: " + error);
|
|
62
|
-
reject(error);
|
|
63
|
-
});
|
|
64
|
-
},
|
|
65
|
-
(error) => {
|
|
66
|
-
Logger.logError(fileName, "addInBoxData", "Resolve file system URL error: " + error);
|
|
67
|
-
reject(error);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
static getInBoxData(conversationId: string): Promise<string> {
|
|
73
|
-
return new Promise(async (resolve, reject) => {
|
|
74
|
-
const inboxDir = await this.getInboxDirectory();
|
|
75
|
-
window.resolveLocalFileSystemURL(inboxDir, (dirEntry) => {
|
|
76
|
-
dirEntry.getFile(`${conversationId}.json`, { create: false }, (fileEntry) => {
|
|
77
|
-
fileEntry.file((file) => {
|
|
78
|
-
const reader = new FileReader();
|
|
79
|
-
reader.onloadend = () => {
|
|
80
|
-
Logger.logInfo(fileName, "getInBoxData", "Read completed");
|
|
81
|
-
resolve(reader.result as string);
|
|
82
|
-
};
|
|
83
|
-
reader.onerror = (e) => {
|
|
84
|
-
Logger.logError(fileName, "getInBoxData", "Read error: " + e);
|
|
85
|
-
reject(e);
|
|
86
|
-
};
|
|
87
|
-
reader.readAsText(file);
|
|
88
|
-
},
|
|
89
|
-
(error) => {
|
|
90
|
-
Logger.logError(fileName, "getInBoxData", "Get file error: " + error);
|
|
91
|
-
reject(error);
|
|
92
|
-
});
|
|
93
|
-
},
|
|
94
|
-
(error) => {
|
|
95
|
-
Logger.logError(fileName, "getInBoxData", "Get file error: " + error);
|
|
96
|
-
reject(error);
|
|
97
|
-
});
|
|
98
|
-
},
|
|
99
|
-
error => {
|
|
100
|
-
Logger.logError(fileName, "getInBoxData", "Resolve file system URL error: " + error);
|
|
101
|
-
reject(error);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
static deleteInBoxData(conversationId: string): Promise<void> {
|
|
107
|
-
return new Promise(async (resolve, reject) => {
|
|
108
|
-
const inboxDir = await this.getInboxDirectory();
|
|
109
|
-
window.resolveLocalFileSystemURL(inboxDir, (dirEntry) => {
|
|
110
|
-
dirEntry.getFile(`${conversationId}.json`, { create: false }, (fileEntry) => {
|
|
111
|
-
fileEntry.remove(() => {
|
|
112
|
-
Logger.logInfo(fileName, "deleteInBoxData", "File removed");
|
|
113
|
-
resolve();
|
|
114
|
-
},
|
|
115
|
-
(error) => {
|
|
116
|
-
Logger.logError(fileName, "deleteInBoxData", "Remove file error: " + error);
|
|
117
|
-
reject(error);
|
|
118
|
-
}
|
|
119
|
-
);
|
|
120
|
-
},
|
|
121
|
-
(error) => {
|
|
122
|
-
Logger.logError(fileName, "deleteInBoxData", "Get file error: " + error);
|
|
123
|
-
reject(error);
|
|
124
|
-
});
|
|
125
|
-
},
|
|
126
|
-
(error) => {
|
|
127
|
-
Logger.logError(fileName, "deleteInBoxData", "Resolve file system URL error: " + error);
|
|
128
|
-
reject(error);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|