Skip to main content

Platform Storage

A utility for interacting with the Platform Storage as specififed by the LTI spec

Getting Started

Create a new storage handler:

const client = new PostMessageClient({
origin: "https://platform.example.com",
});
const storage = new PlatformStorage(client);

Basic Operations

First, check if the platform supports storage:

const supported = await storage.isSupported();
if (!supported) {
console.warn("Platform storage not available");
return;
}

Storing Data

await storage.set("user-preference", "dark-mode");

Retrieving Data

// Get a value (returns null if not found)
const preference = await storage.get("user-preference");

// Handle missing data
const settings = await storage.get("user-settings");
if (settings === null) {
console.log("No settings found");
} else {
const parsed = JSON.parse(settings);
console.log("User settings:", parsed);
}

Removing Data

// Remove a stored value
await storage.remove("user-preference");

Error Handling

try {
await storage.set("my-key", "my-value");
} catch (error) {
if (error.response?.error?.code === "storage_full") {
console.error("Storage quota exceeded");
} else {
console.error("Storage operation failed:", error);
}
}