@unvired/react-native-wrapper-sdk 0.0.14 → 0.0.15
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/dist/UnviredWrapper.d.ts +25 -22
- package/dist/UnviredWrapper.d.ts.map +1 -1
- package/dist/UnviredWrapper.js +32 -48
- package/dist/lib/auth/AuthBuilder.d.ts.map +1 -0
- package/dist/lib/auth/AuthService.d.ts +27 -0
- package/dist/lib/auth/AuthService.d.ts.map +1 -0
- package/dist/lib/auth/AuthService.js +46 -0
- package/dist/lib/database/DatabaseService.d.ts +86 -0
- package/dist/lib/database/DatabaseService.d.ts.map +1 -0
- package/dist/lib/database/DatabaseService.js +134 -0
- package/dist/lib/file/FileService.d.ts +72 -0
- package/dist/lib/file/FileService.d.ts.map +1 -0
- package/dist/lib/file/FileService.js +136 -0
- package/dist/lib/logger/LoggerService.d.ts +45 -0
- package/dist/lib/logger/LoggerService.d.ts.map +1 -0
- package/dist/lib/logger/LoggerService.js +65 -0
- package/dist/lib/notification/NotificationService.d.ts +28 -0
- package/dist/lib/notification/NotificationService.d.ts.map +1 -0
- package/dist/lib/notification/NotificationService.js +47 -0
- package/dist/lib/settings/SettingsService.d.ts +41 -0
- package/dist/lib/settings/SettingsService.d.ts.map +1 -0
- package/dist/lib/settings/SettingsService.js +108 -0
- package/dist/lib/sync/SyncService.d.ts +96 -0
- package/dist/lib/sync/SyncService.d.ts.map +1 -0
- package/dist/lib/sync/SyncService.js +139 -0
- package/package.json +3 -3
- package/src/UnviredWrapper.ts +34 -52
- package/src/lib/auth/AuthService.ts +45 -0
- package/src/lib/database/DatabaseService.ts +148 -0
- package/src/lib/file/FileService.ts +149 -0
- package/src/lib/logger/LoggerService.ts +70 -0
- package/src/lib/notification/NotificationService.ts +45 -0
- package/src/lib/settings/SettingsService.ts +126 -0
- package/src/lib/sync/SyncService.ts +160 -0
- package/dist/lib/AuthBuilder.d.ts.map +0 -1
- /package/dist/lib/{AuthBuilder.d.ts → auth/AuthBuilder.d.ts} +0 -0
- /package/dist/lib/{AuthBuilder.js → auth/AuthBuilder.js} +0 -0
- /package/src/lib/{AuthBuilder.ts → auth/AuthBuilder.ts} +0 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SyncService = void 0;
|
|
4
|
+
const unvired_ts_core_sdk_1 = require("@unvired/unvired-ts-core-sdk");
|
|
5
|
+
/**
|
|
6
|
+
* Service for handling Synchronization with Unvired Server
|
|
7
|
+
*/
|
|
8
|
+
class SyncService {
|
|
9
|
+
/**
|
|
10
|
+
* Submit data to UMP server in sync mode (Foreground)
|
|
11
|
+
* @param reqType Request Type (RQST/PULL/PUSH/QUERY/REQ)
|
|
12
|
+
* @param header Header Data Structure
|
|
13
|
+
* @param customData Custom data string (optional)
|
|
14
|
+
* @param paFunction Process Agent Function Name
|
|
15
|
+
* @param autoSave Whether to auto-save data in DB
|
|
16
|
+
*/
|
|
17
|
+
async syncForeground(reqType, header, customData = "", paFunction, autoSave) {
|
|
18
|
+
return unvired_ts_core_sdk_1.SyncEngine.syncForeground(reqType, header, customData, paFunction, autoSave);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Submit data to UMP server in async mode (Background)
|
|
22
|
+
* @param reqType Request Type
|
|
23
|
+
* @param header Header Data Structure
|
|
24
|
+
* @param customData Custom data string (optional)
|
|
25
|
+
* @param paFunction Process Agent Function Name
|
|
26
|
+
* @param beName Business Entity Name
|
|
27
|
+
*/
|
|
28
|
+
async syncBackground(reqType, header, customData = "", paFunction, beName) {
|
|
29
|
+
return unvired_ts_core_sdk_1.SyncEngine.syncBackground(reqType, header, customData, paFunction, beName);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Sends request for initial data download
|
|
33
|
+
* @param functions List of functions to execute
|
|
34
|
+
*/
|
|
35
|
+
async sendInitialDataDownloadRequest(functions = []) {
|
|
36
|
+
return unvired_ts_core_sdk_1.SettingsHelper.requestInitialDataDownload(functions);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Gets synchronization state
|
|
40
|
+
* @param callback Callback to receive state updates
|
|
41
|
+
*/
|
|
42
|
+
getSynchronizationState(callback) {
|
|
43
|
+
unvired_ts_core_sdk_1.NotificationListenerHelper.synchronizationStateListener = callback;
|
|
44
|
+
// Initial state
|
|
45
|
+
callback("idle");
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Starts Inbox Handler
|
|
49
|
+
*/
|
|
50
|
+
startInboxHandler() {
|
|
51
|
+
// Correct usage of SyncEngine as per SDK definition
|
|
52
|
+
unvired_ts_core_sdk_1.SyncEngine.startInboxHandler();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Starts Data Sender (Outbox Handler)
|
|
56
|
+
*/
|
|
57
|
+
startDataSender() {
|
|
58
|
+
unvired_ts_core_sdk_1.OutboxService.getInstance().start();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Request for downloading messages from server
|
|
62
|
+
*/
|
|
63
|
+
getMessages() {
|
|
64
|
+
unvired_ts_core_sdk_1.SyncEngine.getMessages();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Register for Data Sender notifications
|
|
68
|
+
* @param callback Callback function
|
|
69
|
+
*/
|
|
70
|
+
registerDataSenderListener(callback) {
|
|
71
|
+
unvired_ts_core_sdk_1.NotificationListenerHelper.dataSenderListener = callback;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Unregister Data Sender notifications
|
|
75
|
+
*/
|
|
76
|
+
unRegisterDataSenderListener() {
|
|
77
|
+
unvired_ts_core_sdk_1.NotificationListenerHelper.dataSenderListener = null;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Register for Sync Items count updates
|
|
81
|
+
* @param callback Callback function
|
|
82
|
+
*/
|
|
83
|
+
registerSyncItemsCountListener(callback) {
|
|
84
|
+
unvired_ts_core_sdk_1.NotificationListenerHelper.syncItemsCountListener = callback;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Check if a BE is in the Outbox queue
|
|
88
|
+
* @param beLid BE Header LID
|
|
89
|
+
*/
|
|
90
|
+
async isInOutBox(beLid) {
|
|
91
|
+
return unvired_ts_core_sdk_1.SettingsHelper.isInOutBoxQueue(beLid);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Check if a BE is in Sent Items
|
|
95
|
+
* @param beLid BE Header LID
|
|
96
|
+
*/
|
|
97
|
+
async isInSentItem(beLid) {
|
|
98
|
+
return unvired_ts_core_sdk_1.SettingsHelper.isInSentItems(beLid);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get count of items in Outbox
|
|
102
|
+
*/
|
|
103
|
+
async outBoxItemCount() {
|
|
104
|
+
return unvired_ts_core_sdk_1.SettingsHelper.getOutboxCount();
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get count of items in Sent Items
|
|
108
|
+
*/
|
|
109
|
+
async sentItemCount() {
|
|
110
|
+
return unvired_ts_core_sdk_1.SettingsHelper.getSentItemsCount();
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Get count of items in Inbox
|
|
114
|
+
*/
|
|
115
|
+
async inBoxItemCount() {
|
|
116
|
+
return unvired_ts_core_sdk_1.SettingsHelper.getInboxCount();
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Delete an entry from Outbox
|
|
120
|
+
* @param beLid BE Header LID
|
|
121
|
+
*/
|
|
122
|
+
async deleteOutBoxEntry(beLid) {
|
|
123
|
+
return unvired_ts_core_sdk_1.SyncEngine.removeOutObjectBasedOnLid(beLid);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Lock Data Sender for a specific BE
|
|
127
|
+
* @param beLid BE LID
|
|
128
|
+
*/
|
|
129
|
+
async lockDataSender(beLid) {
|
|
130
|
+
return unvired_ts_core_sdk_1.SyncEngine.lockDataSender(beLid);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Unlock Data Sender
|
|
134
|
+
*/
|
|
135
|
+
async unlockDataSender() {
|
|
136
|
+
return unvired_ts_core_sdk_1.SyncEngine.unlockDataSender();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.SyncService = SyncService;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unvired/react-native-wrapper-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"description": "Unvired SDK for React Native - Enterprise mobile platform SDK with authentication, sync, and offline database",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"react-native": ">=0.60.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@unvired/react-native-unvired-sdk": "^0.0.
|
|
31
|
-
"@unvired/unvired-ts-core-sdk": "^0.0.
|
|
30
|
+
"@unvired/react-native-unvired-sdk": "^0.0.15",
|
|
31
|
+
"@unvired/unvired-ts-core-sdk": "^0.0.15",
|
|
32
32
|
"axios": "^1.6.5",
|
|
33
33
|
"crypto-js": "^4.2.0",
|
|
34
34
|
"uuid": "^9.0.1"
|
package/src/UnviredWrapper.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { AuthenticationService } from '@unvired/unvired-ts-core-sdk';
|
|
2
|
+
import { AuthService } from './lib/auth/AuthService';
|
|
3
|
+
import { DatabaseService } from './lib/database/DatabaseService';
|
|
4
|
+
import { FileService } from './lib/file/FileService';
|
|
5
|
+
import { NotificationService } from './lib/notification/NotificationService';
|
|
6
|
+
import { SyncService } from './lib/sync/SyncService';
|
|
7
|
+
import { SettingsService } from './lib/settings/SettingsService';
|
|
8
|
+
import { LoggerService } from './lib/logger/LoggerService';
|
|
3
9
|
|
|
4
10
|
/**
|
|
5
11
|
* React Native Wrapper for Unvired Core SDK
|
|
@@ -11,78 +17,54 @@ export class UnviredWrapper {
|
|
|
11
17
|
}
|
|
12
18
|
|
|
13
19
|
/**
|
|
14
|
-
*
|
|
15
|
-
* Can be awaited directly: await sdk.login().setAppName("my-app")
|
|
20
|
+
* Access Authentication operations
|
|
16
21
|
*/
|
|
17
|
-
|
|
18
|
-
return new
|
|
22
|
+
auth(): AuthService {
|
|
23
|
+
return new AuthService();
|
|
19
24
|
}
|
|
20
25
|
|
|
21
26
|
/**
|
|
22
|
-
*
|
|
23
|
-
* Can be awaited directly: await sdk.authenticateAndActivate().setUsername("demo")
|
|
27
|
+
* Access Database operations
|
|
24
28
|
*/
|
|
25
|
-
|
|
26
|
-
return new
|
|
29
|
+
database(): DatabaseService {
|
|
30
|
+
return new DatabaseService();
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
/**
|
|
30
|
-
*
|
|
31
|
-
* Can be awaited directly: await sdk.authenticateLocal().setUsername("demo")
|
|
34
|
+
* Access File/Attachment operations
|
|
32
35
|
*/
|
|
33
|
-
|
|
34
|
-
return new
|
|
36
|
+
file(): FileService {
|
|
37
|
+
return new FileService();
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
/**
|
|
38
|
-
*
|
|
41
|
+
* Access Notification operations
|
|
39
42
|
*/
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return authService.logout();
|
|
43
|
+
notification(): NotificationService {
|
|
44
|
+
return new NotificationService();
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
/**
|
|
46
|
-
*
|
|
48
|
+
* Access Synchronization operations
|
|
47
49
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return authService.clearData();
|
|
50
|
+
sync(): SyncService {
|
|
51
|
+
return new SyncService();
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
static logError(className: string, methodName: string, message: string) {
|
|
59
|
-
return PlatformManager.getInstance().getPlatformAdapter().getLoggerAdapter().logError(className, methodName, message);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
static logDebug(className: string, methodName: string, message: string) {
|
|
63
|
-
return PlatformManager.getInstance().getPlatformAdapter().getLoggerAdapter().logDebug(className, methodName, message);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
static setLogLevel(level: string) {
|
|
68
|
-
return PlatformManager.getInstance().getPlatformAdapter().getLoggerAdapter().setLogLevel(level);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
static async getLogFileURL(): Promise<string> {
|
|
72
|
-
return PlatformManager.getInstance().getPlatformAdapter().getLoggerAdapter().getLogFileURL();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
static async getLogFileContent(): Promise<string> {
|
|
76
|
-
return PlatformManager.getInstance().getPlatformAdapter().getLoggerAdapter().getLogFileContent();
|
|
54
|
+
/**
|
|
55
|
+
* Access Settings and Utility operations
|
|
56
|
+
*/
|
|
57
|
+
settings(): SettingsService {
|
|
58
|
+
return new SettingsService();
|
|
77
59
|
}
|
|
78
60
|
|
|
79
|
-
|
|
80
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Access Logger operations
|
|
63
|
+
*/
|
|
64
|
+
logger(): LoggerService {
|
|
65
|
+
return new LoggerService();
|
|
81
66
|
}
|
|
82
67
|
|
|
83
|
-
static async clearLogFile(): Promise<void> {
|
|
84
|
-
return PlatformManager.getInstance().getPlatformAdapter().getLoggerAdapter().clearLogFile();
|
|
85
|
-
}
|
|
86
68
|
}
|
|
87
69
|
|
|
88
|
-
export default UnviredWrapper;
|
|
70
|
+
export default UnviredWrapper;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import AuthBuilder from './AuthBuilder';
|
|
2
|
+
import { AuthenticationService } from '@unvired/unvired-ts-core-sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Service for handling Authentication operations
|
|
6
|
+
*/
|
|
7
|
+
export class AuthService {
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Returns a builder for login method
|
|
11
|
+
*/
|
|
12
|
+
login(): AuthBuilder {
|
|
13
|
+
return new AuthBuilder('login');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Returns a builder for authenticateAndActivate method
|
|
18
|
+
*/
|
|
19
|
+
authenticateAndActivate(): AuthBuilder {
|
|
20
|
+
return new AuthBuilder('authenticateAndActivate');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Returns a builder for authenticateLocal method
|
|
25
|
+
*/
|
|
26
|
+
authenticateLocal(): AuthBuilder {
|
|
27
|
+
return new AuthBuilder('authenticateLocal');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Logout method - Logs out the current user
|
|
32
|
+
*/
|
|
33
|
+
async logout(): Promise<any> {
|
|
34
|
+
const authService = (AuthenticationService as any).instance;
|
|
35
|
+
return authService.logout();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Clear all data
|
|
40
|
+
*/
|
|
41
|
+
async clearData(): Promise<any> {
|
|
42
|
+
const authService = (AuthenticationService as any).instance;
|
|
43
|
+
return authService.clearData();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { AppDatabaseManager, DatabaseManager, SettingsHelper, FrameworkHelper, PlatformManager, DatabaseType } from '@unvired/unvired-ts-core-sdk';
|
|
2
|
+
|
|
3
|
+
export class DatabaseService {
|
|
4
|
+
private db: AppDatabaseManager;
|
|
5
|
+
|
|
6
|
+
constructor() {
|
|
7
|
+
this.db = AppDatabaseManager.getInstance();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Selects data from the database
|
|
12
|
+
* @param tableName Name of the table
|
|
13
|
+
* @param whereClause Optional SQL where clause
|
|
14
|
+
*/
|
|
15
|
+
async select(tableName: string, whereClause?: string): Promise<any> {
|
|
16
|
+
return this.db.select(tableName, whereClause);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Inserts data into the database
|
|
21
|
+
* @param tableName Name of the table
|
|
22
|
+
* @param structureObject Data object to insert
|
|
23
|
+
* @param isHeader Whether the data is a header or an item
|
|
24
|
+
*/
|
|
25
|
+
async insert(tableName: string, structureObject: any, isHeader: boolean): Promise<any> {
|
|
26
|
+
return this.db.insert(tableName, structureObject, isHeader);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Inserts or updates data in the database
|
|
31
|
+
* @param tableName Name of the table
|
|
32
|
+
* @param structureObject Data object to insert or update
|
|
33
|
+
* @param isHeader Whether the data is a header or an item
|
|
34
|
+
*/
|
|
35
|
+
async insertOrUpdate(tableName: string, structureObject: any, isHeader: boolean): Promise<any> {
|
|
36
|
+
return this.db.insertOrUpdate(tableName, structureObject, isHeader);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Deletes data from the database
|
|
41
|
+
* @param tableName Name of the table
|
|
42
|
+
* @param whereClause Optional SQL where clause
|
|
43
|
+
*/
|
|
44
|
+
async delete(tableName: string, whereClause?: string): Promise<any> {
|
|
45
|
+
return this.db.delete(tableName, whereClause);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Updates data in the database
|
|
50
|
+
* @param tableName Name of the table
|
|
51
|
+
* @param updatedObject Object with updated values
|
|
52
|
+
* @param whereClause SQL where clause identifying rows to update
|
|
53
|
+
*/
|
|
54
|
+
async update(tableName: string, updatedObject: any, whereClause: any): Promise<any> {
|
|
55
|
+
return this.db.update(tableName, updatedObject, whereClause);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Executes a raw SQL statement
|
|
60
|
+
* @param query SQL query
|
|
61
|
+
*/
|
|
62
|
+
async executeStatement(query: string): Promise<any> {
|
|
63
|
+
return this.db.executeStatement(query);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Begins a transaction
|
|
68
|
+
*/
|
|
69
|
+
async beginTransaction(): Promise<void> {
|
|
70
|
+
return this.db.beginTransaction();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Ends (commits) a transaction
|
|
75
|
+
*/
|
|
76
|
+
async endTransaction(): Promise<void> {
|
|
77
|
+
return this.db.endTransaction();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Rolls back a transaction
|
|
82
|
+
*/
|
|
83
|
+
async rollbackTransaction(): Promise<void> {
|
|
84
|
+
return this.db.rollbackTransaction();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Creates a save point
|
|
89
|
+
* @param savePoint Name of the save point
|
|
90
|
+
*/
|
|
91
|
+
async createSavePoint(savePoint: string): Promise<void> {
|
|
92
|
+
return this.db.createSavePoint(savePoint);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Releases a save point
|
|
97
|
+
* @param savePoint Name of the save point
|
|
98
|
+
*/
|
|
99
|
+
async releaseSavePoint(savePoint: string): Promise<void> {
|
|
100
|
+
return this.db.releaseSavePoint(savePoint);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Rolls back to a save point
|
|
105
|
+
* @param savePoint Name of the save point
|
|
106
|
+
*/
|
|
107
|
+
async rollbackToSavePoint(savePoint: string): Promise<void> {
|
|
108
|
+
return this.db.rollbackToSavePoint(savePoint);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Saves Web Data (Browser only)
|
|
113
|
+
*/
|
|
114
|
+
async saveWebData(): Promise<void> {
|
|
115
|
+
if (FrameworkHelper.getPlatform() === 'browser') {
|
|
116
|
+
return DatabaseManager.getInstance().saveWebData();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Exports Web Data
|
|
122
|
+
*/
|
|
123
|
+
async exportWebData(): Promise<void> {
|
|
124
|
+
return DatabaseManager.getInstance().exportWebData();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Prepares database for export
|
|
129
|
+
*/
|
|
130
|
+
async prepareDatabaseForExport(): Promise<void> {
|
|
131
|
+
return SettingsHelper.prepareDatabaseForExport();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Gets the database directory path
|
|
136
|
+
*/
|
|
137
|
+
async getDatabasePath(): Promise<string> {
|
|
138
|
+
return new Promise((resolve, reject) => {
|
|
139
|
+
try {
|
|
140
|
+
const adapter = PlatformManager.getInstance().getPlatformAdapter().getDatabaseAdapter();
|
|
141
|
+
// @ts-ignore - The type might be mismatch in d.ts but logical flow is correct
|
|
142
|
+
adapter.getDBFilePath({ dbType: DatabaseType.AppDb }, (path) => resolve(path));
|
|
143
|
+
} catch (e) {
|
|
144
|
+
reject(e);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { AttachmentHelper, AttachmentQHelper, ServiceConstants, AppDatabaseManager } from '@unvired/unvired-ts-core-sdk';
|
|
2
|
+
|
|
3
|
+
export class FileService {
|
|
4
|
+
|
|
5
|
+
// AttachmentService is not exported from the SDK, so we cannot expose start/stop here directly.
|
|
6
|
+
// If background sync control is needed, it might be via SyncEngine or other means.
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Gets the directory used for storing attachments
|
|
10
|
+
*/
|
|
11
|
+
async getAttachmentDirectory(): Promise<string> {
|
|
12
|
+
let dir = await AttachmentHelper.getAttachmentDirectory();
|
|
13
|
+
if (!dir.endsWith("/")) {
|
|
14
|
+
dir += "/";
|
|
15
|
+
}
|
|
16
|
+
return dir;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Adds an attachment
|
|
21
|
+
* @param attachmentName Name of the attachment
|
|
22
|
+
* @param attachmentData Data as ArrayBuffer
|
|
23
|
+
*/
|
|
24
|
+
async addAttachment(attachmentName: string, attachmentData: ArrayBuffer): Promise<string> {
|
|
25
|
+
return AttachmentHelper.addAttachment(attachmentName, attachmentData);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Gets an attachment's data
|
|
30
|
+
* @param attachmentName Name of the attachment
|
|
31
|
+
*/
|
|
32
|
+
async getAttachment(attachmentName: string): Promise<ArrayBuffer> {
|
|
33
|
+
return AttachmentHelper.getAttachment(attachmentName);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Deletes an attachment
|
|
38
|
+
* @param attachmentName Name of the attachment
|
|
39
|
+
*/
|
|
40
|
+
async deleteAttachment(attachmentName: string): Promise<void> {
|
|
41
|
+
return AttachmentHelper.deleteAttachment(attachmentName);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Gets the file system path of an attachment
|
|
46
|
+
* @param attachmentName Name of the attachment
|
|
47
|
+
*/
|
|
48
|
+
async getAttachmentPath(attachmentName: string): Promise<string> {
|
|
49
|
+
return AttachmentHelper.getAttachmentPath(attachmentName);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Reads a file from the filesystem as ArrayBuffer
|
|
54
|
+
* @param filePath Absolute path to the file
|
|
55
|
+
*/
|
|
56
|
+
async readFileAsArrayBuffer(filePath: string): Promise<ArrayBuffer> {
|
|
57
|
+
return AttachmentHelper.readFileAsArrayBuffer(filePath);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Checks if a file exists
|
|
62
|
+
* @param filePath Absolute path to the file
|
|
63
|
+
*/
|
|
64
|
+
async fileExists(filePath: string): Promise<boolean> {
|
|
65
|
+
return AttachmentHelper.fileExists(filePath);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Reads an external file
|
|
70
|
+
* @param filePath Absolute path to the file
|
|
71
|
+
*/
|
|
72
|
+
async readExternalFile(filePath: string): Promise<ArrayBuffer> {
|
|
73
|
+
return AttachmentHelper.readExternalFile(filePath);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Writes data to an external file
|
|
78
|
+
* @param filePath Parent directory path
|
|
79
|
+
* @param fileName File name
|
|
80
|
+
* @param data Data to write
|
|
81
|
+
*/
|
|
82
|
+
async writeExternalFile(filePath: string, fileName: string, data: ArrayBuffer): Promise<void> {
|
|
83
|
+
return AttachmentHelper.writeExternalFile(filePath, fileName, data);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Deletes an external file
|
|
88
|
+
* @param filePath Absolute path to the file
|
|
89
|
+
*/
|
|
90
|
+
async deleteExternalFile(filePath: string): Promise<void> {
|
|
91
|
+
return AttachmentHelper.deleteExternalFile(filePath);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Create Attachment Item - Copies file to attachment folder and inserts record in DB
|
|
96
|
+
* @param tableName Table name for attachment
|
|
97
|
+
* @param structureObject Attachment item object
|
|
98
|
+
*/
|
|
99
|
+
async createAttachmentItem(tableName: string, structureObject: any): Promise<any> {
|
|
100
|
+
if (!tableName) throw new Error("Table name is null or empty");
|
|
101
|
+
if (!structureObject) throw new Error("Structure object is null or empty");
|
|
102
|
+
|
|
103
|
+
const fileName = structureObject[ServiceConstants.AttachmentItemFieldFileName];
|
|
104
|
+
const localPath = structureObject[ServiceConstants.AttachmentItemFieldLocalPath];
|
|
105
|
+
|
|
106
|
+
if (!fileName) throw new Error("File Name is null or empty");
|
|
107
|
+
if (!localPath) throw new Error("Local Path is null or empty");
|
|
108
|
+
|
|
109
|
+
const arrayBuffer = await AttachmentHelper.readFileAsArrayBuffer(localPath);
|
|
110
|
+
if (!arrayBuffer) {
|
|
111
|
+
throw new Error(`Attachment file could not be read at the location: ${localPath}`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let attachmentName = structureObject[ServiceConstants.AttachmentItemFieldUid];
|
|
115
|
+
if (fileName) {
|
|
116
|
+
attachmentName = fileName;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const attachmentPath = await AttachmentHelper.addAttachment(attachmentName, arrayBuffer);
|
|
120
|
+
structureObject[ServiceConstants.AttachmentItemFieldLocalPath] = attachmentPath;
|
|
121
|
+
structureObject[ServiceConstants.AttachmentItemFieldAttachmentStatus] = ServiceConstants.AttachmentStatusSavedForUpload;
|
|
122
|
+
|
|
123
|
+
await AppDatabaseManager.getInstance().insert(tableName, structureObject, false);
|
|
124
|
+
return structureObject;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Queues an attachment for download
|
|
129
|
+
* @param tableName Table name
|
|
130
|
+
* @param structureObject Structure object
|
|
131
|
+
*/
|
|
132
|
+
async downloadAttachment(tableName: string, structureObject: any): Promise<any> {
|
|
133
|
+
await AttachmentQHelper.queueForDownload(tableName, structureObject, ServiceConstants.FwAttachmentForceDownloadPriority);
|
|
134
|
+
// Note: AttachmentService start is not exposed in SDK exports currently.
|
|
135
|
+
// If needed, SyncEngine might handle it or it should be auto-handled.
|
|
136
|
+
return structureObject;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Downloads an attachment synchronously (waits for completion)
|
|
141
|
+
* @param structureObject Structure object with UID and FileName
|
|
142
|
+
*/
|
|
143
|
+
async downloadAttachmentSync(structureObject: any): Promise<any> {
|
|
144
|
+
const uid = structureObject[ServiceConstants.AttachmentItemFieldUid];
|
|
145
|
+
const fileName = structureObject[ServiceConstants.AttachmentItemFieldFileName];
|
|
146
|
+
const attachmentPath = await AttachmentQHelper.downloadAttachmentAndGetPath(uid, fileName);
|
|
147
|
+
return attachmentPath;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { PlatformManager } from '@unvired/unvired-ts-core-sdk';
|
|
2
|
+
|
|
3
|
+
export class LoggerService {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Log Information
|
|
7
|
+
* @param className Class Name
|
|
8
|
+
* @param methodName Method Name
|
|
9
|
+
* @param message Message
|
|
10
|
+
*/
|
|
11
|
+
info(className: string, methodName: string, message: string): void {
|
|
12
|
+
PlatformManager.getInstance().getPlatformAdapter().getLoggerAdapter().logInfo(className, methodName, message);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Log Error
|
|
17
|
+
* @param className Class Name
|
|
18
|
+
* @param methodName Method Name
|
|
19
|
+
* @param message Message
|
|
20
|
+
*/
|
|
21
|
+
error(className: string, methodName: string, message: string): void {
|
|
22
|
+
PlatformManager.getInstance().getPlatformAdapter().getLoggerAdapter().logError(className, methodName, message);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Log Debug
|
|
27
|
+
* @param className Class Name
|
|
28
|
+
* @param methodName Method Name
|
|
29
|
+
* @param message Message
|
|
30
|
+
*/
|
|
31
|
+
debug(className: string, methodName: string, message: string): void {
|
|
32
|
+
PlatformManager.getInstance().getPlatformAdapter().getLoggerAdapter().logDebug(className, methodName, message);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Set Log Level
|
|
37
|
+
* @param level Log Level
|
|
38
|
+
*/
|
|
39
|
+
setLogLevel(level: string): void {
|
|
40
|
+
PlatformManager.getInstance().getPlatformAdapter().getLoggerAdapter().setLogLevel(level);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Get Log File URL
|
|
45
|
+
*/
|
|
46
|
+
async getLogFileURL(): Promise<string> {
|
|
47
|
+
return PlatformManager.getInstance().getPlatformAdapter().getLoggerAdapter().getLogFileURL();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Get Log File Content
|
|
52
|
+
*/
|
|
53
|
+
async getLogFileContent(): Promise<string> {
|
|
54
|
+
return PlatformManager.getInstance().getPlatformAdapter().getLoggerAdapter().getLogFileContent();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Get Backup Log File Content
|
|
59
|
+
*/
|
|
60
|
+
async getBackupLogFileContent(): Promise<string> {
|
|
61
|
+
return PlatformManager.getInstance().getPlatformAdapter().getLoggerAdapter().getBackupLogFileContent();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Clear Log File
|
|
66
|
+
*/
|
|
67
|
+
async clearLogFile(): Promise<void> {
|
|
68
|
+
return PlatformManager.getInstance().getPlatformAdapter().getLoggerAdapter().clearLogFile();
|
|
69
|
+
}
|
|
70
|
+
}
|