@unvired/react-native-wrapper-sdk 0.0.23 → 0.0.25

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 (42) hide show
  1. package/dist/UnviredWrapper.d.ts +25 -22
  2. package/dist/UnviredWrapper.d.ts.map +1 -1
  3. package/dist/UnviredWrapper.js +32 -48
  4. package/dist/lib/auth/AuthBuilder.d.ts.map +1 -0
  5. package/dist/lib/auth/AuthService.d.ts +27 -0
  6. package/dist/lib/auth/AuthService.d.ts.map +1 -0
  7. package/dist/lib/auth/AuthService.js +46 -0
  8. package/dist/lib/database/DatabaseService.d.ts +43 -0
  9. package/dist/lib/database/DatabaseService.d.ts.map +1 -0
  10. package/dist/lib/database/DatabaseService.js +34 -0
  11. package/dist/lib/file/FileService.d.ts +89 -0
  12. package/dist/lib/file/FileService.d.ts.map +1 -0
  13. package/dist/lib/file/FileService.js +267 -0
  14. package/dist/lib/logger/LoggerService.d.ts +45 -0
  15. package/dist/lib/logger/LoggerService.d.ts.map +1 -0
  16. package/dist/lib/logger/LoggerService.js +65 -0
  17. package/dist/lib/notification/NotificationService.d.ts +28 -0
  18. package/dist/lib/notification/NotificationService.d.ts.map +1 -0
  19. package/dist/lib/notification/NotificationService.js +47 -0
  20. package/dist/lib/settings/SettingsService.d.ts +44 -0
  21. package/dist/lib/settings/SettingsService.d.ts.map +1 -0
  22. package/dist/lib/settings/SettingsService.js +120 -0
  23. package/dist/lib/storage/StorageService.d.ts +13 -0
  24. package/dist/lib/storage/StorageService.d.ts.map +1 -0
  25. package/dist/lib/storage/StorageService.js +19 -0
  26. package/dist/lib/sync/SyncService.d.ts +96 -0
  27. package/dist/lib/sync/SyncService.d.ts.map +1 -0
  28. package/dist/lib/sync/SyncService.js +139 -0
  29. package/package.json +11 -6
  30. package/src/UnviredWrapper.ts +34 -52
  31. package/src/lib/auth/AuthService.ts +45 -0
  32. package/src/lib/database/DatabaseService.ts +53 -0
  33. package/src/lib/file/FileService.ts +313 -0
  34. package/src/lib/logger/LoggerService.ts +70 -0
  35. package/src/lib/notification/NotificationService.ts +45 -0
  36. package/src/lib/settings/SettingsService.ts +150 -0
  37. package/src/lib/storage/StorageService.ts +27 -0
  38. package/src/lib/sync/SyncService.ts +160 -0
  39. package/dist/lib/AuthBuilder.d.ts.map +0 -1
  40. /package/dist/lib/{AuthBuilder.d.ts → auth/AuthBuilder.d.ts} +0 -0
  41. /package/dist/lib/{AuthBuilder.js → auth/AuthBuilder.js} +0 -0
  42. /package/src/lib/{AuthBuilder.ts → auth/AuthBuilder.ts} +0 -0
@@ -0,0 +1,313 @@
1
+ import { PlatformManager } from '@unvired/unvired-ts-core-sdk';
2
+
3
+ export interface IDirectoryReader {
4
+ readEntries(successCallback: (entries: IFileEntry[]) => void, errorCallback: (error: any) => void): void;
5
+ }
6
+
7
+ export interface IFileEntry {
8
+ fullPath: string;
9
+ nativeURL: string;
10
+ isDirectory?: boolean;
11
+ remove(callback: () => void, errorCallback: (error: any) => void): void;
12
+ removeRecursively(callback: () => void, errorCallback: (error: any) => void): void;
13
+ createReader(): IDirectoryReader;
14
+ getDirectory?(path: string, options: { create: boolean }, callback: (entry: IFileEntry) => void, errorCallback: (error: any) => void): void;
15
+ getFile?(path: string, options: { create: boolean }, callback: (entry: IFileEntry) => void, errorCallback: (error: any) => void): void;
16
+ file?(callback: (file: File) => void, errorCallback: (error: any) => void): void;
17
+ createWriter?(callback: (writer: any) => void, errorCallback: (error: any) => void): void;
18
+ }
19
+
20
+ export class FileService {
21
+
22
+ getDocumentDirectory(): string {
23
+ // @ts-ignore
24
+ return PlatformManager.getInstance().getPlatformAdapter().getDocumentDirectory();
25
+ }
26
+
27
+ resolveLocalFileSystemURL(url: string): Promise<IFileEntry> {
28
+ // @ts-ignore
29
+ return PlatformManager.getInstance().getPlatformAdapter().resolveLocalFileSystemURL(url);
30
+ }
31
+
32
+ async getFolderBasedOnUserId(userId: string): Promise<string> {
33
+ // @ts-ignore
34
+ return await PlatformManager.getInstance().getPlatformAdapter().getFolderBasedOnUserId(userId);
35
+ }
36
+
37
+ async deleteUserFolder(userId: string): Promise<void> {
38
+ // @ts-ignore
39
+ await PlatformManager.getInstance().getPlatformAdapter().deleteUserFolder(userId);
40
+ }
41
+
42
+ /**
43
+ * Reads an external file as ArrayBuffer using IFileEntry API
44
+ * @param filePath Absolute path to the file
45
+ */
46
+ async readExternalFile(filePath: string): Promise<ArrayBuffer> {
47
+ // Get the file entry
48
+ const fileEntry = await this.resolveLocalFileSystemURL(filePath);
49
+
50
+ return new Promise((resolve, reject) => {
51
+ // Use the file() method to read the file
52
+ if (!fileEntry.file) {
53
+ reject(new Error('file() method not available on entry'));
54
+ return;
55
+ }
56
+
57
+ fileEntry.file(
58
+ async (fileMetadata: any) => {
59
+ try {
60
+ // Read the file using react-native-fs
61
+ const RNFS = await import('react-native-fs');
62
+ const content = await RNFS.readFile(fileMetadata.path, 'utf8');
63
+
64
+ // Convert string to ArrayBuffer
65
+ const encoder = new TextEncoder();
66
+ resolve(encoder.encode(content).buffer);
67
+ } catch (error) {
68
+ reject(error);
69
+ }
70
+ },
71
+ (error: any) => {
72
+ reject(error);
73
+ }
74
+ );
75
+ });
76
+ }
77
+
78
+ /**
79
+ * Writes data to an external file using IFileEntry API
80
+ * @param filePath Parent directory path
81
+ * @param fileName File name
82
+ * @param data Data to write (ArrayBuffer or string)
83
+ */
84
+ async writeExternalFile(filePath: string, fileName: string, data: ArrayBuffer | string): Promise<void> {
85
+ // Convert data to string if it's ArrayBuffer
86
+ let content: string;
87
+ if (data instanceof ArrayBuffer) {
88
+ const decoder = new TextDecoder();
89
+ content = decoder.decode(data);
90
+ } else {
91
+ content = data;
92
+ }
93
+
94
+ // Get the directory entry
95
+ const dirEntry = await this.resolveLocalFileSystemURL(filePath);
96
+
97
+ return new Promise((resolve, reject) => {
98
+ // Get or create the file
99
+ if (!dirEntry.getFile) {
100
+ reject(new Error('getFile() method not available on directory entry'));
101
+ return;
102
+ }
103
+
104
+ dirEntry.getFile(
105
+ fileName,
106
+ { create: true },
107
+ (fileEntry: IFileEntry) => {
108
+ // Create a writer
109
+ if (!fileEntry.createWriter) {
110
+ reject(new Error('createWriter() method not available on file entry'));
111
+ return;
112
+ }
113
+
114
+ fileEntry.createWriter(
115
+ (writer: any) => {
116
+ writer.onwriteend = () => {
117
+ resolve();
118
+ };
119
+ writer.onerror = (error: any) => {
120
+ reject(error);
121
+ };
122
+
123
+ // Write the content
124
+ writer.write(content);
125
+ },
126
+ (error: any) => {
127
+ reject(error);
128
+ }
129
+ );
130
+ },
131
+ (error: any) => {
132
+ reject(error);
133
+ }
134
+ );
135
+ });
136
+ }
137
+
138
+ /**
139
+ * Deletes an external file using IFileEntry API
140
+ * @param filePath Absolute path to the file
141
+ */
142
+ async deleteExternalFile(filePath: string): Promise<void> {
143
+ const fileEntry = await this.resolveLocalFileSystemURL(filePath);
144
+
145
+ return new Promise((resolve, reject) => {
146
+ fileEntry.remove(
147
+ () => resolve(),
148
+ (error: any) => reject(error)
149
+ );
150
+ });
151
+ }
152
+
153
+ /**
154
+ * Checks if a file exists using IFileEntry API
155
+ * @param filePath Absolute path to the file
156
+ */
157
+ async fileExists(filePath: string): Promise<boolean> {
158
+ try {
159
+ await this.resolveLocalFileSystemURL(filePath);
160
+ return true;
161
+ } catch (error) {
162
+ return false;
163
+ }
164
+ }
165
+
166
+ /**
167
+ * Creates a directory
168
+ * @param dirPath Parent directory path
169
+ * @param dirName Directory name to create
170
+ */
171
+ async createDirectory(dirPath: string, dirName: string): Promise<IFileEntry> {
172
+ const parentEntry = await this.resolveLocalFileSystemURL(dirPath);
173
+
174
+ return new Promise((resolve, reject) => {
175
+ if (!parentEntry.getDirectory) {
176
+ reject(new Error('getDirectory() method not available on entry'));
177
+ return;
178
+ }
179
+
180
+ parentEntry.getDirectory(
181
+ dirName,
182
+ { create: true },
183
+ (dirEntry: IFileEntry) => resolve(dirEntry),
184
+ (error: any) => reject(error)
185
+ );
186
+ });
187
+ }
188
+
189
+ /**
190
+ * Lists files and directories in a directory
191
+ * @param dirPath Directory path to list
192
+ */
193
+ async listDirectory(dirPath: string): Promise<IFileEntry[]> {
194
+ const dirEntry = await this.resolveLocalFileSystemURL(dirPath);
195
+
196
+ return new Promise((resolve, reject) => {
197
+ const reader = dirEntry.createReader();
198
+ reader.readEntries(
199
+ (entries: IFileEntry[]) => resolve(entries),
200
+ (error: any) => reject(error)
201
+ );
202
+ });
203
+ }
204
+
205
+ /**
206
+ * Deletes a directory and all its contents
207
+ * @param dirPath Directory path to delete
208
+ */
209
+ async deleteDirectory(dirPath: string): Promise<void> {
210
+ const dirEntry = await this.resolveLocalFileSystemURL(dirPath);
211
+
212
+ return new Promise((resolve, reject) => {
213
+ dirEntry.removeRecursively(
214
+ () => resolve(),
215
+ (error: any) => reject(error)
216
+ );
217
+ });
218
+ }
219
+
220
+ /**
221
+ * Copies a file
222
+ * @param sourcePath Source file path
223
+ * @param destDir Destination directory path
224
+ * @param newName New file name (optional, keeps original name if not provided)
225
+ */
226
+ async copyFile(sourcePath: string, destDir: string, newName?: string): Promise<void> {
227
+ // Read source file
228
+ const content = await this.readExternalFile(sourcePath);
229
+
230
+ // Get source file name if newName not provided
231
+ const fileName = newName || sourcePath.split('/').pop() || 'file';
232
+
233
+ // Write to destination
234
+ await this.writeExternalFile(destDir, fileName, content);
235
+ }
236
+
237
+ /**
238
+ * Moves/renames a file
239
+ * @param sourcePath Source file path
240
+ * @param destDir Destination directory path
241
+ * @param newName New file name (optional, keeps original name if not provided)
242
+ */
243
+ async moveFile(sourcePath: string, destDir: string, newName?: string): Promise<void> {
244
+ // Copy file to destination
245
+ await this.copyFile(sourcePath, destDir, newName);
246
+
247
+ // Delete source file
248
+ await this.deleteExternalFile(sourcePath);
249
+ }
250
+
251
+ /**
252
+ * Gets file information (size, modification date, etc.)
253
+ * @param filePath File path
254
+ */
255
+ async getFileInfo(filePath: string): Promise<any> {
256
+ const fileEntry = await this.resolveLocalFileSystemURL(filePath);
257
+
258
+ return new Promise((resolve, reject) => {
259
+ if (!fileEntry.file) {
260
+ reject(new Error('file() method not available on entry'));
261
+ return;
262
+ }
263
+
264
+ fileEntry.file(
265
+ (fileMetadata: any) => resolve(fileMetadata),
266
+ (error: any) => reject(error)
267
+ );
268
+ });
269
+ }
270
+
271
+ /**
272
+ * Appends data to an existing file
273
+ * @param filePath File path
274
+ * @param data Data to append
275
+ */
276
+ async appendToFile(filePath: string, data: ArrayBuffer | string): Promise<void> {
277
+ // Convert data to string if it's ArrayBuffer
278
+ let content: string;
279
+ if (data instanceof ArrayBuffer) {
280
+ const decoder = new TextDecoder();
281
+ content = decoder.decode(data);
282
+ } else {
283
+ content = data;
284
+ }
285
+
286
+ const fileEntry = await this.resolveLocalFileSystemURL(filePath);
287
+
288
+ return new Promise((resolve, reject) => {
289
+ if (!fileEntry.createWriter) {
290
+ reject(new Error('createWriter() method not available on file entry'));
291
+ return;
292
+ }
293
+
294
+ fileEntry.createWriter(
295
+ (writer: any) => {
296
+ writer.onwriteend = () => {
297
+ resolve();
298
+ };
299
+ writer.onerror = (error: any) => {
300
+ reject(error);
301
+ };
302
+
303
+ // Append the content
304
+ writer.append(content);
305
+ },
306
+ (error: any) => {
307
+ reject(error);
308
+ }
309
+ );
310
+ });
311
+ }
312
+
313
+ }
@@ -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
+ }
@@ -0,0 +1,45 @@
1
+ import { PlatformManager } from '@unvired/unvired-ts-core-sdk';
2
+
3
+ export class NotificationService {
4
+
5
+ private get adapter() {
6
+ return PlatformManager.getInstance().getPlatformAdapter().getPushNotificationAdapter();
7
+ }
8
+
9
+ /**
10
+ * Requests permission and gets token
11
+ */
12
+ async requestPermission(options?: { forceShow: boolean }): Promise<void> {
13
+ return this.adapter?.requestPermission(options);
14
+ }
15
+
16
+ /**
17
+ * Gets the push token
18
+ */
19
+ async getToken(): Promise<string | undefined> {
20
+ return this.adapter?.getToken();
21
+ }
22
+
23
+ /**
24
+ * Sets callback for token refresh
25
+ */
26
+ onTokenRefresh(callback: (token: string) => void): void {
27
+ this.adapter?.onTokenRefresh(callback);
28
+ }
29
+
30
+ /**
31
+ * Sets listener for incoming notifications (foreground)
32
+ * @param onMessage Callback when a notification is received
33
+ */
34
+ onNotificationReceived(onMessage: (data: any) => void): void {
35
+ this.adapter?.onMessage(onMessage);
36
+ }
37
+
38
+ /**
39
+ * Sets listener for incoming notifications (background)
40
+ * @param onMessage Callback when a notification is received
41
+ */
42
+ onBackgroundNotificationReceived(onMessage: (data: any) => void): void {
43
+ this.adapter?.onBackgroundMessage(onMessage);
44
+ }
45
+ }
@@ -0,0 +1,150 @@
1
+ import {
2
+ SettingsHelper,
3
+ FrameworkSettingsManager,
4
+ FrameworkSettingsFields,
5
+ UserSettingsManager,
6
+ UserSettingsFields,
7
+ UnviredAccountManager,
8
+ HttpConnection,
9
+ AuthenticationService,
10
+ PlatformManager,
11
+ } from '@unvired/unvired-ts-core-sdk';
12
+
13
+ export class SettingsService {
14
+ /**
15
+ * Get current log level
16
+ */
17
+ async getLogLevel(): Promise<string> {
18
+ return FrameworkSettingsManager.getInstance().getFieldValue(FrameworkSettingsFields.logLevel);
19
+ }
20
+
21
+ getDeviceInfo(): string {
22
+ // @ts-ignore
23
+ return PlatformManager.getInstance().getPlatformAdapter().getDeviceInfo();
24
+ }
25
+
26
+ getPlatform(): string {
27
+ // @ts-ignore
28
+ return PlatformManager.getInstance().getPlatformAdapter().getPlatform();
29
+ }
30
+
31
+ getFrontendType(): string {
32
+ // @ts-ignore
33
+ return PlatformManager.getInstance().getPlatformAdapter().getFrontendType();
34
+ }
35
+ /**
36
+ * Set log level
37
+ * @param logLevel Log Level
38
+ */
39
+ async setLogLevel(logLevel: string): Promise<void> {
40
+ return SettingsHelper.setLogLevel(logLevel);
41
+ }
42
+
43
+ /**
44
+ * Send logs to server
45
+ */
46
+ async sendLogToServer(): Promise<void> {
47
+ return SettingsHelper.sendLogsToServer();
48
+ }
49
+
50
+ /**
51
+ * Create and get Log Zip path (for email etc)
52
+ */
53
+ async getLogZipPath(): Promise<string> {
54
+ return SettingsHelper.createAndGetLogZipPath();
55
+ }
56
+
57
+ /**
58
+ * Test Push Notification
59
+ */
60
+ async testPushNotification(): Promise<void> {
61
+ return SettingsHelper.testPushNotification();
62
+ }
63
+
64
+ /**
65
+ * Get list of Info Messages
66
+ */
67
+ async getInfoMessages(headerName: string, lid: string): Promise<any[]> {
68
+ return SettingsHelper.getInfoMessages(headerName, lid);
69
+ }
70
+
71
+ /**
72
+ * Get User Settings / Current Account Information
73
+ */
74
+ async getUserSettings(): Promise<any> {
75
+ const unviredAccount = UnviredAccountManager.getInstance().getLastLoggedInAccount();
76
+ if (!unviredAccount) {
77
+ throw new Error('No account found');
78
+ }
79
+
80
+ let jwtToken = (AuthenticationService as any).instance.jwtToken;
81
+ // Fallback or re-fetch token logic
82
+ if (!jwtToken) {
83
+ jwtToken = unviredAccount.getJwtToken();
84
+ }
85
+
86
+ const serverType = await FrameworkSettingsManager.getInstance().getFieldValue(
87
+ FrameworkSettingsFields.serverType
88
+ );
89
+ const emailId = await FrameworkSettingsManager.getInstance().getFieldValue(
90
+ FrameworkSettingsFields.email
91
+ );
92
+ const unviredUserId = await UserSettingsManager.getInstance().getFieldValue(
93
+ UserSettingsFields.unviredUserId
94
+ );
95
+ const unviredPassword = await UserSettingsManager.getInstance().getFieldValue(
96
+ UserSettingsFields.unviredPassword
97
+ );
98
+
99
+ // Accessing loginParameters from AuthenticationService might need cast if it's protected/private or simply public
100
+ // index.d.ts says: loginParameters: any;
101
+ const loginParams = (AuthenticationService as any).instance.loginParameters || {};
102
+
103
+ return {
104
+ UNVIRED_ID: unviredUserId,
105
+ USER_ID: loginParams.username || unviredUserId,
106
+ FIRST_NAME: unviredAccount.getFirstName(),
107
+ LAST_NAME: unviredAccount.getLastName(),
108
+ FULL_NAME: `${unviredAccount.getFirstName()} ${unviredAccount.getLastName()}`,
109
+ EMAIL: emailId || '',
110
+ SERVER_URL: unviredAccount.getServerURL(),
111
+ SERVER_TYPE: serverType || '',
112
+ LOGIN_TYPE: loginParams.loginType,
113
+ UNVIRED_PASSWORD: unviredPassword || '',
114
+ JWT_TOKEN: jwtToken,
115
+ };
116
+ }
117
+
118
+ /**
119
+ * Set Auth Token
120
+ * @param token JWT Token
121
+ */
122
+ async setAuthToken(token: string): Promise<void> {
123
+ (AuthenticationService as any).instance.jwtToken = token;
124
+ await UserSettingsManager.getInstance().setFieldValue(UserSettingsFields.jwtToken, token);
125
+ }
126
+
127
+ /**
128
+ * Get Auth Token Validity (remaining seconds)
129
+ */
130
+ async getAuthTokenValidity(): Promise<number> {
131
+ const token = await UserSettingsManager.getInstance().getFieldValue(
132
+ UserSettingsFields.jwtToken
133
+ );
134
+ if (!token) return 0;
135
+
136
+ try {
137
+ const parts = token.split('.');
138
+ if (parts.length !== 3) return 0;
139
+
140
+ const payload = JSON.parse(atob(parts[1]));
141
+ if (!payload.exp) return 0;
142
+
143
+ const now = Math.floor(Date.now() / 1000);
144
+ const remaining = payload.exp - now;
145
+ return remaining > 0 ? remaining : 0;
146
+ } catch (e) {
147
+ return 0;
148
+ }
149
+ }
150
+ }
@@ -0,0 +1,27 @@
1
+ import { PlatformManager } from '@unvired/unvired-ts-core-sdk';
2
+
3
+ export interface IStorageAdapter {
4
+ getItem(key: string): void;
5
+ setItem(key: string, value: string): void;
6
+ removeItem(key: string): void;
7
+ clear(): void;
8
+ }
9
+
10
+ export class StorageService {
11
+
12
+ getItem(key: string): void {
13
+ PlatformManager.getInstance().getPlatformAdapter().getStorageAdapter().getItem(key);
14
+ }
15
+
16
+ setItem(key: string, value: string): void {
17
+ PlatformManager.getInstance().getPlatformAdapter().getStorageAdapter().setItem(key, value);
18
+ }
19
+
20
+ removeItem(key: string): void {
21
+ PlatformManager.getInstance().getPlatformAdapter().getStorageAdapter().removeItem(key);
22
+ }
23
+
24
+ clear(): void {
25
+ PlatformManager.getInstance().getPlatformAdapter().getStorageAdapter().clear();
26
+ }
27
+ }