@unvired/react-native-wrapper-sdk 0.0.21 → 0.0.22

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 +22 -25
  2. package/dist/UnviredWrapper.d.ts.map +1 -1
  3. package/dist/UnviredWrapper.js +48 -32
  4. package/dist/lib/AuthBuilder.d.ts.map +1 -0
  5. package/package.json +6 -11
  6. package/src/UnviredWrapper.ts +52 -34
  7. package/dist/lib/auth/AuthBuilder.d.ts.map +0 -1
  8. package/dist/lib/auth/AuthService.d.ts +0 -27
  9. package/dist/lib/auth/AuthService.d.ts.map +0 -1
  10. package/dist/lib/auth/AuthService.js +0 -46
  11. package/dist/lib/database/DatabaseService.d.ts +0 -43
  12. package/dist/lib/database/DatabaseService.d.ts.map +0 -1
  13. package/dist/lib/database/DatabaseService.js +0 -34
  14. package/dist/lib/file/FileService.d.ts +0 -95
  15. package/dist/lib/file/FileService.d.ts.map +0 -1
  16. package/dist/lib/file/FileService.js +0 -152
  17. package/dist/lib/logger/LoggerService.d.ts +0 -45
  18. package/dist/lib/logger/LoggerService.d.ts.map +0 -1
  19. package/dist/lib/logger/LoggerService.js +0 -65
  20. package/dist/lib/notification/NotificationService.d.ts +0 -28
  21. package/dist/lib/notification/NotificationService.d.ts.map +0 -1
  22. package/dist/lib/notification/NotificationService.js +0 -47
  23. package/dist/lib/settings/SettingsService.d.ts +0 -44
  24. package/dist/lib/settings/SettingsService.d.ts.map +0 -1
  25. package/dist/lib/settings/SettingsService.js +0 -120
  26. package/dist/lib/storage/StorageService.d.ts +0 -13
  27. package/dist/lib/storage/StorageService.d.ts.map +0 -1
  28. package/dist/lib/storage/StorageService.js +0 -19
  29. package/dist/lib/sync/SyncService.d.ts +0 -96
  30. package/dist/lib/sync/SyncService.d.ts.map +0 -1
  31. package/dist/lib/sync/SyncService.js +0 -139
  32. package/src/lib/auth/AuthService.ts +0 -45
  33. package/src/lib/database/DatabaseService.ts +0 -53
  34. package/src/lib/file/FileService.ts +0 -186
  35. package/src/lib/logger/LoggerService.ts +0 -70
  36. package/src/lib/notification/NotificationService.ts +0 -45
  37. package/src/lib/settings/SettingsService.ts +0 -150
  38. package/src/lib/storage/StorageService.ts +0 -27
  39. package/src/lib/sync/SyncService.ts +0 -160
  40. /package/dist/lib/{auth/AuthBuilder.d.ts → AuthBuilder.d.ts} +0 -0
  41. /package/dist/lib/{auth/AuthBuilder.js → AuthBuilder.js} +0 -0
  42. /package/src/lib/{auth/AuthBuilder.ts → AuthBuilder.ts} +0 -0
@@ -1,139 +0,0 @@
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;
@@ -1,45 +0,0 @@
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
- }
@@ -1,53 +0,0 @@
1
- import { PlatformManager } from '@unvired/unvired-ts-core-sdk';
2
-
3
-
4
- export interface IDatabaseAdapter {
5
- create(options: { userId: string }, successCallback: (result: any) => void, errorCallback: (error: any) => void): void;
6
- execute(options: any, successCallback: (result: any) => void, errorCallback: (error: any) => void): void;
7
- executeStatementOnPath(dbPath: string, sqlQuery: string, callback: (result: any) => void): void;
8
- selectFromPath(dbPath: string, sqlQuery: string, callback: (result: any) => void): void;
9
- createDatabase(dbPath: string, callback: () => void): void;
10
- getDBFilePath(options: { dbType: string }, callback: (path: string) => void): void;
11
- saveWebDB(options: { userId: string }, callback: (result: any) => void, errorCallback: (error: any) => void): void;
12
- exportWebDB(options: { userId: string }, callback: (result: any) => void, errorCallback: (error: any) => void): void;
13
- deleteUserData(options: { userId: string }, callback: () => void, errorCallback: (error: any) => void): void;
14
- }
15
-
16
- export class DatabaseService {
17
-
18
- create(options: { userId: string }, successCallback: (result: any) => void, errorCallback: (error: any) => void): void {
19
- PlatformManager.getInstance().getPlatformAdapter().getDatabaseAdapter().create(options, successCallback, errorCallback);
20
- }
21
-
22
- execute(options: any, successCallback: (result: any) => void, errorCallback: (error: any) => void): void {
23
- PlatformManager.getInstance().getPlatformAdapter().getDatabaseAdapter().execute(options, successCallback, errorCallback);
24
- }
25
-
26
- executeStatementOnPath(dbPath: string, sqlQuery: string, callback: (result: any) => void): void {
27
- PlatformManager.getInstance().getPlatformAdapter().getDatabaseAdapter().executeStatementOnPath(dbPath, sqlQuery, callback);
28
- }
29
-
30
- selectFromPath(dbPath: string, sqlQuery: string, callback: (result: any) => void): void {
31
- PlatformManager.getInstance().getPlatformAdapter().getDatabaseAdapter().selectFromPath(dbPath, sqlQuery, callback);
32
- }
33
-
34
- createDatabase(dbPath: string, callback: () => void): void {
35
- PlatformManager.getInstance().getPlatformAdapter().getDatabaseAdapter().createDatabase(dbPath, callback);
36
- }
37
-
38
- getDBFilePath(options: { dbType: string }, callback: (path: string) => void): void {
39
- PlatformManager.getInstance().getPlatformAdapter().getDatabaseAdapter().getDBFilePath(options, callback);
40
- }
41
-
42
- saveWebDB(options: { userId: string }, callback: (result: any) => void, errorCallback: (error: any) => void): void {
43
- PlatformManager.getInstance().getPlatformAdapter().getDatabaseAdapter().saveWebDB(options, callback, errorCallback);
44
- }
45
-
46
- exportWebDB(options: { userId: string }, callback: (result: any) => void, errorCallback: (error: any) => void): void {
47
- PlatformManager.getInstance().getPlatformAdapter().getDatabaseAdapter().exportWebDB(options, callback, errorCallback);
48
- }
49
-
50
- deleteUserData(options: { userId: string }, callback: () => void, errorCallback: (error: any) => void): void {
51
- PlatformManager.getInstance().getPlatformAdapter().getDatabaseAdapter().deleteUserData(options, callback, errorCallback);
52
- }
53
- }
@@ -1,186 +0,0 @@
1
- import { AttachmentHelper, AttachmentQHelper, ServiceConstants, AppDatabaseManager, 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
- // AttachmentService is not exported from the SDK, so we cannot expose start/stop here directly.
43
- // If background sync control is needed, it might be via SyncEngine or other means.
44
-
45
- /**
46
- * Gets the directory used for storing attachments
47
- */
48
- async getAttachmentDirectory(): Promise<string> {
49
- let dir = await AttachmentHelper.getAttachmentDirectory();
50
- if (!dir.endsWith("/")) {
51
- dir += "/";
52
- }
53
- return dir;
54
- }
55
-
56
- /**
57
- * Adds an attachment
58
- * @param attachmentName Name of the attachment
59
- * @param attachmentData Data as ArrayBuffer
60
- */
61
- async addAttachment(attachmentName: string, attachmentData: ArrayBuffer): Promise<string> {
62
- return AttachmentHelper.addAttachment(attachmentName, attachmentData);
63
- }
64
-
65
- /**
66
- * Gets an attachment's data
67
- * @param attachmentName Name of the attachment
68
- */
69
- async getAttachment(attachmentName: string): Promise<ArrayBuffer> {
70
- return AttachmentHelper.getAttachment(attachmentName);
71
- }
72
-
73
- /**
74
- * Deletes an attachment
75
- * @param attachmentName Name of the attachment
76
- */
77
- async deleteAttachment(attachmentName: string): Promise<void> {
78
- return AttachmentHelper.deleteAttachment(attachmentName);
79
- }
80
-
81
- /**
82
- * Gets the file system path of an attachment
83
- * @param attachmentName Name of the attachment
84
- */
85
- async getAttachmentPath(attachmentName: string): Promise<string> {
86
- return AttachmentHelper.getAttachmentPath(attachmentName);
87
- }
88
-
89
- /**
90
- * Reads a file from the filesystem as ArrayBuffer
91
- * @param filePath Absolute path to the file
92
- */
93
- async readFileAsArrayBuffer(filePath: string): Promise<ArrayBuffer> {
94
- return AttachmentHelper.readFileAsArrayBuffer(filePath);
95
- }
96
-
97
- /**
98
- * Checks if a file exists
99
- * @param filePath Absolute path to the file
100
- */
101
- async fileExists(filePath: string): Promise<boolean> {
102
- return AttachmentHelper.fileExists(filePath);
103
- }
104
-
105
- /**
106
- * Reads an external file
107
- * @param filePath Absolute path to the file
108
- */
109
- async readExternalFile(filePath: string): Promise<ArrayBuffer> {
110
- return AttachmentHelper.readExternalFile(filePath);
111
- }
112
-
113
- /**
114
- * Writes data to an external file
115
- * @param filePath Parent directory path
116
- * @param fileName File name
117
- * @param data Data to write
118
- */
119
- async writeExternalFile(filePath: string, fileName: string, data: ArrayBuffer): Promise<void> {
120
- return AttachmentHelper.writeExternalFile(filePath, fileName, data);
121
- }
122
-
123
- /**
124
- * Deletes an external file
125
- * @param filePath Absolute path to the file
126
- */
127
- async deleteExternalFile(filePath: string): Promise<void> {
128
- return AttachmentHelper.deleteExternalFile(filePath);
129
- }
130
-
131
- /**
132
- * Create Attachment Item - Copies file to attachment folder and inserts record in DB
133
- * @param tableName Table name for attachment
134
- * @param structureObject Attachment item object
135
- */
136
- async createAttachmentItem(tableName: string, structureObject: any): Promise<any> {
137
- if (!tableName) throw new Error("Table name is null or empty");
138
- if (!structureObject) throw new Error("Structure object is null or empty");
139
-
140
- const fileName = structureObject[ServiceConstants.AttachmentItemFieldFileName];
141
- const localPath = structureObject[ServiceConstants.AttachmentItemFieldLocalPath];
142
-
143
- if (!fileName) throw new Error("File Name is null or empty");
144
- if (!localPath) throw new Error("Local Path is null or empty");
145
-
146
- const arrayBuffer = await AttachmentHelper.readFileAsArrayBuffer(localPath);
147
- if (!arrayBuffer) {
148
- throw new Error(`Attachment file could not be read at the location: ${localPath}`);
149
- }
150
-
151
- let attachmentName = structureObject[ServiceConstants.AttachmentItemFieldUid];
152
- if (fileName) {
153
- attachmentName = fileName;
154
- }
155
-
156
- const attachmentPath = await AttachmentHelper.addAttachment(attachmentName, arrayBuffer);
157
- structureObject[ServiceConstants.AttachmentItemFieldLocalPath] = attachmentPath;
158
- structureObject[ServiceConstants.AttachmentItemFieldAttachmentStatus] = ServiceConstants.AttachmentStatusSavedForUpload;
159
-
160
- await AppDatabaseManager.getInstance().insert(tableName, structureObject, false);
161
- return structureObject;
162
- }
163
-
164
- /**
165
- * Queues an attachment for download
166
- * @param tableName Table name
167
- * @param structureObject Structure object
168
- */
169
- async downloadAttachment(tableName: string, structureObject: any): Promise<any> {
170
- await AttachmentQHelper.queueForDownload(tableName, structureObject, ServiceConstants.FwAttachmentForceDownloadPriority);
171
- // Note: AttachmentService start is not exposed in SDK exports currently.
172
- // If needed, SyncEngine might handle it or it should be auto-handled.
173
- return structureObject;
174
- }
175
-
176
- /**
177
- * Downloads an attachment synchronously (waits for completion)
178
- * @param structureObject Structure object with UID and FileName
179
- */
180
- async downloadAttachmentSync(structureObject: any): Promise<any> {
181
- const uid = structureObject[ServiceConstants.AttachmentItemFieldUid];
182
- const fileName = structureObject[ServiceConstants.AttachmentItemFieldFileName];
183
- const attachmentPath = await AttachmentQHelper.downloadAttachmentAndGetPath(uid, fileName);
184
- return attachmentPath;
185
- }
186
- }
@@ -1,70 +0,0 @@
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
- }
@@ -1,45 +0,0 @@
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
- }
@@ -1,150 +0,0 @@
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(): Promise<any[]> {
68
- return SettingsHelper.getInfoMessages();
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
- }