@infosel-sdk/core
Version:
Core SDK for Infosel financial services platform. Provides essential infrastructure for authentication, HTTP/GraphQL communication, storage management, and error handling.
51 lines • 2.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const sdk_error_1 = tslib_1.__importStar(require("../../errors/sdk_error"));
// Optional import for React Native encrypted storage
let EncryptedStorage = null;
try {
EncryptedStorage = require('react-native-encrypted-storage');
}
catch (error) {
// EncryptedStorage is not available, will use fallback
}
class AppLocalStorage {
getObject(key) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!EncryptedStorage) {
throw new sdk_error_1.default(sdk_error_1.SdkErrorType.LOCAL_STORAGE_NOT_AVAILABLE, 'React Native Encrypted Storage is not available. Please install react-native-encrypted-storage package.');
}
const jsonItem = yield EncryptedStorage.getItem(key);
if (!jsonItem) {
throw new sdk_error_1.default(sdk_error_1.SdkErrorType.LOCAL_STORAGE_KEY_NOT_FOUND, key);
}
return JSON.parse(jsonItem);
});
}
saveObject(key, object) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!EncryptedStorage) {
throw new sdk_error_1.default(sdk_error_1.SdkErrorType.LOCAL_STORAGE_NOT_AVAILABLE, 'React Native Encrypted Storage is not available. Please install react-native-encrypted-storage package.');
}
yield EncryptedStorage.setItem(key, JSON.stringify(object));
return object;
});
}
removeObject(key) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!EncryptedStorage) {
throw new sdk_error_1.default(sdk_error_1.SdkErrorType.LOCAL_STORAGE_NOT_AVAILABLE, 'React Native Encrypted Storage is not available. Please install react-native-encrypted-storage package.');
}
try {
yield EncryptedStorage.removeItem(key);
return true;
}
catch (_) {
return false;
}
});
}
}
exports.default = AppLocalStorage;
//# sourceMappingURL=app_local_storage.native.js.map