The Key-Value Store provides simple storage for key/value pairs. Use this to persistently store data that you'd like to retrieve through the Query tool.
For example:
1 2import { storage } from '@forge/api'; await storage.set('foo', 'bar'); await storage.get('foo'); await storage.query() .where('key', startsWith('value'))
To safeguard sensitive data in a more secure manner, the Key-Value Store allows for storing encrypted data via the Secret store.
Each installation of your app is subject to the Storage API's quotas and limits. See Storage quotas and Storage limits for more details.
When using the app storage API, we strongly recommend that you:
Using Forge’s persistent hosted storage
requires the storage:app
scope in your manifest file:
1 2permissions: scopes: - storage:app
See Add scopes to call an Atlassian REST API guide for additional information.
The Atlassian cloud provides features that allow admins to control and verify where their Jira and Confluence data is hosted. These features support them in meeting company requirements or regulatory obligations relating to data residency.
Forge's persistent storage options use this same cloud infrastructure to store data. This allows Forge to extend similar data residency features to your app. All data stored on Forge persistent storage automatically inherit these features.
Specifically, if your app stores data on Forge persistent storage, an admin can control where that data is stored. For more details about how this works, see Data residency.
All data stored within the app storage API is namespaced. The namespace includes which Atlassian site, product, and Forge environment your app is installed on. As a result:
Data is transferred, encrypted, and stored on disk according to the Atlassian cloud’s data encryption policies. Once stored, data will persist until deleted or updated by your app.
In addition, the Atlassian Cloud backs up all persistent storage for disaster recovery.
The read and query APIs within the app storage APIs are eventually consistent. This means that the data returned from the API may be slightly out of date.
Writes to keys using set
or delete
use a "last write wins" conflict resolution strategy.
Writes to individual keys are atomic - For example, the value is either updated in full or not.
The app storage API is able to persist any JSON data type except null
. For example:
The JavaScript storage API serializes your objects using JSON.stringify
, and as such
removes functions and the value undefined
from any object you attempt to serialize.
The Key-Value Store and Custom Entity Store use cursors for paginated data access. Queries (both through the Query builder and Complex Query builder) return a cursor in the results. This cursor can be provided to subsequent queries to paginate over larger data sets than you would otherwise be able to fetch.
1 2// Fetch a page of 10 results const { nextCursor } = await storage.query().getMany(); // Fetch the next 10 results await storage.query().cursor(nextCursor).getMany();
Cursors are derived from underlying storage identifiers, and hence are subject to change anytime there is any change in how these underlying storage identifiers are created. This means that cursors are not stable and should not be persisted.
You will have to use the same parameters as the initial query. See the example below.
1 2// Fetch 15 results const { nextCursor } = await storage .query() .limit(15) .where('key', startsWith('account.')) .getMany(); // This is expected usage await storage.query() .limit(15) .where('key', startsWith('account.')) .cursor(nextCursor) .getMany(); // This will produce undefined results await storage.query() .cursor(nextCursor) .getMany();
Keys are lexicographically ordered; this means, for example, that the Query builder and Complex Query builder) will return entities ordered by their key. This property can be used to group related entities or build ad-hoc indexes.
The Key-Value Store and Custom Entity Store don't support indexing of arbitrary attributes. However, it is possible to support this sort of access pattern if your keys are constructed in such a way as to support indexed reads.
Hierarchical keys can be constructed to allow for nested entities to be fetched in a single list operation such as the example below.
1 2import { storage, startsWith } from '@forge/api'; // Nested entities await storage.set('survey-responses#1#{UUID}', { }); await storage.set('survey-responses#1#{UUID}', { }); await storage.set('survey-responses#1#{UUID}', { }); await storage.set('survey-responses#1#{UUID}', { }); const results = await storage .query() .where('key', startsWith('survey-response#1#')) .limit(10) .getMany();
Rate this page: