Retrieves a boolean value from the native storage.
The key to retrieve the value for.
The stored boolean value. See GetBooleanResponse.
Simple usage
import { StorageModule, isSuccess, isError } from '@grabjs/superapp-sdk';
// Initialize the storage module
const storage = new StorageModule();
// Get a boolean value
const response = await storage.getBoolean('isDarkMode');
// Handle the response
if (isSuccess(response)) {
console.log('Stored value:', response.result.value);
} else if (isError(response)) {
console.error(`Error ${response.status_code}: ${response.error}`);
} else {
console.error('Unhandled response');
}
Retrieves a double (floating point) value from the native storage.
The key to retrieve the value for.
The stored double value. See GetDoubleResponse.
Simple usage
import { StorageModule, isSuccess, isError } from '@grabjs/superapp-sdk';
// Initialize the storage module
const storage = new StorageModule();
// Get a double value
const response = await storage.getDouble('price');
// Handle the response
if (isSuccess(response)) {
console.log('Stored value:', response.result.value);
} else if (isError(response)) {
console.error(`Error ${response.status_code}: ${response.error}`);
} else {
console.error('Unhandled response');
}
Retrieves an integer value from the native storage.
The key to retrieve the value for.
The stored integer value. See GetIntResponse.
Simple usage
import { StorageModule, isSuccess, isError } from '@grabjs/superapp-sdk';
// Initialize the storage module
const storage = new StorageModule();
// Get an integer value
const response = await storage.getInt('userCount');
// Handle the response
if (isSuccess(response)) {
console.log('Stored value:', response.result.value);
} else if (isError(response)) {
console.error(`Error ${response.status_code}: ${response.error}`);
} else {
console.error('Unhandled response');
}
Retrieves a string value from the native storage.
The key to retrieve the value for.
The stored string value. See GetStringResponse.
Simple usage
import { StorageModule, isSuccess, isError } from '@grabjs/superapp-sdk';
// Initialize the storage module
const storage = new StorageModule();
// Get a string value
const response = await storage.getString('username');
// Handle the response
if (isSuccess(response)) {
console.log('Stored value:', response.result.value);
} else if (isError(response)) {
console.error(`Error ${response.status_code}: ${response.error}`);
} else {
console.error('Unhandled response');
}
Removes a single value from the native storage by key.
The key to remove from storage.
Confirmation that the value was removed. See RemoveResponse.
Simple usage
import { StorageModule, isSuccess, isError } from '@grabjs/superapp-sdk';
// Initialize the storage module
const storage = new StorageModule();
// Remove a value
const response = await storage.remove('username');
// Handle the response
if (isSuccess(response)) {
console.log('Value removed successfully');
} else if (isError(response)) {
console.error(`Error ${response.status_code}: ${response.error}`);
} else {
console.error('Unhandled response');
}
Removes all values from the native storage.
Confirmation that all values were removed. See RemoveAllResponse.
Simple usage
import { StorageModule, isSuccess, isError } from '@grabjs/superapp-sdk';
// Initialize the storage module
const storage = new StorageModule();
// Remove all values
const response = await storage.removeAll();
// Handle the response
if (isSuccess(response)) {
console.log('All values removed successfully');
} else if (isError(response)) {
console.error(`Error ${response.status_code}: ${response.error}`);
} else {
console.error('Unhandled response');
}
Stores a boolean value in the native storage.
The key to store the value under.
The boolean value to store.
Confirmation that the boolean value was stored. See SetBooleanResponse.
Simple usage
import { StorageModule, isSuccess, isError } from '@grabjs/superapp-sdk';
// Initialize the storage module
const storage = new StorageModule();
// Set a boolean value
const response = await storage.setBoolean('isDarkMode', true);
// Handle the response
if (isSuccess(response)) {
console.log('Value stored successfully');
} else if (isError(response)) {
console.error(`Error ${response.status_code}: ${response.error}`);
} else {
console.error('Unhandled response');
}
Stores a double (floating point) value in the native storage.
The key to store the value under.
The double value to store.
Confirmation that the double value was stored. See SetDoubleResponse.
Simple usage
import { StorageModule, isSuccess, isError } from '@grabjs/superapp-sdk';
// Initialize the storage module
const storage = new StorageModule();
// Set a double value
const response = await storage.setDouble('price', 19.99);
// Handle the response
if (isSuccess(response)) {
console.log('Value stored successfully');
} else if (isError(response)) {
console.error(`Error ${response.status_code}: ${response.error}`);
} else {
console.error('Unhandled response');
}
Stores an integer value in the native storage.
The key to store the value under.
The integer value to store.
Confirmation that the integer value was stored. See SetIntResponse.
Simple usage
import { StorageModule, isSuccess, isError } from '@grabjs/superapp-sdk';
// Initialize the storage module
const storage = new StorageModule();
// Set an integer value
const response = await storage.setInt('userCount', 42);
// Handle the response
if (isSuccess(response)) {
console.log('Value stored successfully');
} else if (isError(response)) {
console.error(`Error ${response.status_code}: ${response.error}`);
} else {
console.error('Unhandled response');
}
Stores a string value in the native storage.
The key to store the value under.
The string value to store.
Confirmation that the string value was stored. See SetStringResponse.
Simple usage
import { StorageModule, isSuccess, isError } from '@grabjs/superapp-sdk';
// Initialize the storage module
const storage = new StorageModule();
// Set a string value
const response = await storage.setString('username', 'john_doe');
// Handle the response
if (isSuccess(response)) {
console.log('Value stored successfully');
} else if (isError(response)) {
console.error(`Error ${response.status_code}: ${response.error}`);
} else {
console.error('Unhandled response');
}
JSBridge module for persisting key-value data to native storage.
Remarks
Stores data in the native app's persistent storage, allowing data to survive WebView restarts. All stored data is automatically removed when the user logs out. This code must run on the Grab SuperApp's WebView to function correctly.
Example
ES Module:
Example
CDN (UMD):