@grabjs/superapp-sdk
    Preparing search index...

    Class StorageModule

    JSBridge module for persisting key-value data to native storage.

    Stores data in the native app's persistent storage, allowing data to survive WebView restarts. This code must run on the Grab SuperApp's WebView to function correctly.

    ES Module:

    import { StorageModule } from '@grabjs/superapp-sdk';
    const storage = new StorageModule();

    CDN (UMD):

    <script src="https://cdn.jsdelivr.net/npm/@grabjs/superapp-sdk/dist/index.js"></script>
    <script>
    const storage = new SuperAppSDK.StorageModule();
    </script>

    Hierarchy (View Summary)

    Index

    Constructors

    Methods

    • Retrieves a boolean value from the native storage.

      Parameters

      • key: string

        The key to retrieve the value for.

      Returns Promise<GetBooleanResponse>

      The stored boolean value.

      Simple usage

      import { StorageModule, isSuccess, isErrorResponse } 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 (isErrorResponse(response)) {
      console.error(`Error ${response.status_code}: ${response.error}`);
      } else {
      console.error('Unhandled response');
      }
    • Retrieves a double (floating point) value from the native storage.

      Parameters

      • key: string

        The key to retrieve the value for.

      Returns Promise<GetDoubleResponse>

      The stored double value.

      Simple usage

      import { StorageModule, isSuccess, isErrorResponse } 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 (isErrorResponse(response)) {
      console.error(`Error ${response.status_code}: ${response.error}`);
      } else {
      console.error('Unhandled response');
      }
    • Retrieves an integer value from the native storage.

      Parameters

      • key: string

        The key to retrieve the value for.

      Returns Promise<GetIntResponse>

      The stored integer value.

      Simple usage

      import { StorageModule, isSuccess, isErrorResponse } 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 (isErrorResponse(response)) {
      console.error(`Error ${response.status_code}: ${response.error}`);
      } else {
      console.error('Unhandled response');
      }
    • Retrieves a string value from the native storage.

      Parameters

      • key: string

        The key to retrieve the value for.

      Returns Promise<GetStringResponse>

      The stored string value.

      Simple usage

      import { StorageModule, isSuccess, isErrorResponse } 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 (isErrorResponse(response)) {
      console.error(`Error ${response.status_code}: ${response.error}`);
      } else {
      console.error('Unhandled response');
      }
    • Removes a single value from the native storage by key.

      Parameters

      • key: string

        The key to remove from storage.

      Returns Promise<RemoveResponse>

      Confirmation that the value was removed.

      Simple usage

      import { StorageModule, isSuccess, isErrorResponse } 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 (isErrorResponse(response)) {
      console.error(`Error ${response.status_code}: ${response.error}`);
      } else {
      console.error('Unhandled response');
      }
    • Removes all values from the native storage.

      Returns Promise<RemoveAllResponse>

      Confirmation that all values were removed.

      Simple usage

      import { StorageModule, isSuccess, isErrorResponse } 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 (isErrorResponse(response)) {
      console.error(`Error ${response.status_code}: ${response.error}`);
      } else {
      console.error('Unhandled response');
      }
    • Stores a boolean value in the native storage.

      Parameters

      • key: string

        The key to store the value under.

      • value: boolean

        The boolean value to store.

      Returns Promise<SetBooleanResponse>

      Confirmation that the boolean value was stored.

      Simple usage

      import { StorageModule, isSuccess, isErrorResponse } 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 (isErrorResponse(response)) {
      console.error(`Error ${response.status_code}: ${response.error}`);
      } else {
      console.error('Unhandled response');
      }
    • Stores a double (floating point) value in the native storage.

      Parameters

      • key: string

        The key to store the value under.

      • value: number

        The double value to store.

      Returns Promise<SetDoubleResponse>

      Confirmation that the double value was stored.

      Simple usage

      import { StorageModule, isSuccess, isErrorResponse } 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 (isErrorResponse(response)) {
      console.error(`Error ${response.status_code}: ${response.error}`);
      } else {
      console.error('Unhandled response');
      }
    • Stores an integer value in the native storage.

      Parameters

      • key: string

        The key to store the value under.

      • value: number

        The integer value to store.

      Returns Promise<SetIntResponse>

      Confirmation that the integer value was stored.

      Simple usage

      import { StorageModule, isSuccess, isErrorResponse } 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 (isErrorResponse(response)) {
      console.error(`Error ${response.status_code}: ${response.error}`);
      } else {
      console.error('Unhandled response');
      }
    • Stores a string value in the native storage.

      Parameters

      • key: string

        The key to store the value under.

      • value: string

        The string value to store.

      Returns Promise<SetStringResponse>

      Confirmation that the string value was stored.

      Simple usage

      import { StorageModule, isSuccess, isErrorResponse } 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 (isErrorResponse(response)) {
      console.error(`Error ${response.status_code}: ${response.error}`);
      } else {
      console.error('Unhandled response');
      }