Skip to main content
stores

Managing Stores

At the core, Stores provide a secure way for assigned members to upload encrypted files.

  • Stores allow users to upload files to separate file containers.
  • Each Context can contain any number of Stores with a unique identifier (storeId) used to distinguish them.
  • Stores do not need to have unique names or assigned public keys.

Permissions

Stores differentiate two types of users: Managers and Regular Users. The table below shows the differences in their permissions:

ActivityUserManager
Uploading filesyesyes
Editing filesyesyes
Editing Storenoyes
Deleting filesonly their ownall files

Creating Stores

To create a Store, you need a name and a list of public key - userID pairs. Due to the fact that each Store is inside a Context, all the public keys have to be registered inside the given Context. You can do it using Platform REST API.

After creating a Store, all the users with management rights will be able to edit the Store. Skip to Modifying Stores for more info.

Below you can see some examples of creating Stores:

const textEncoder = new TextEncoder();
const context = Endpoint.connection().context('CONTEXT_ID');
const storeId = await context.stores.new({
users: [{ pubKey: 'PUB_KEY', userId: 'USER_ID' }],
managers: [{ pubKey: 'PUB_KEY', userId: 'USER_ID' }],
publicMeta: new Uint8Array(),
privateMeta: textEncoder.encode(
JSON.stringify({
name: 'StoreName'
})
)
});

For JavaScript reference to here.

Important note: Managers declared while creating the Store, also have to be included in the regular user list.

The user list in Stores is designed to be flexible, accommodating a wide range of use cases.

Listing Stores

Your application may include multiple Stores, each associated with different Contexts. You can retrieve a list of all Stores within a given Context. This list will include useful metadata about the Stores, such as the creation date, last file upload date, user list, and information about the last modification. However, to optimize performance, the list will only include the total number of files in each Store, not the full file content.

Here's an example of how to download the last 30 Stores created within a Context:

const PAGE_SIZE = 30
const pageIndex = 0
const sortOrder = 'desc'

const threadList = Endpoint.context(CONTEXT_ID).threads.list(pageIndex, {
pageSize: PAGE_SIZE,
sort: sortOrder
});

To limit collecting too much data when downloading Stores, specify the page index (starting from 0) and the number of items to be included on each page.

Modifying Stores

Depending on your project's specification, it may be necessary to modify a Store. It could be e.g. changing the name or adding/removing users. Each user with management rights is able to modify Stores, delete them as a whole or only particular files.

Updating a Store means overwriting it with the provided data. To successfully update a Store, you must specify its current version. The version field is mandatory to handle multiple updates on the server and it is incremented by 1 with each update.

Below there is an example of modifying a Store:

const ctx = Endpoint.context(CONTEXT_ID)
const thread = ctx.thread(THREAD_ID)
const threadInfo = await thread.info()

await thread.update({
users: threadInfo.users,
managers: threadInfo.managers,
title: 'new Title',
currentVersion: threadInfo.version,
options: {
accessToOldDataForNewUsers: false,
force: false,
generateNewKey: false
}
})

Three additional options are available when changing the list of users inside a Store:

  • accessToOldDataForNewUsers - if marked true, the newly added users will be able to access files sent before they joined the Store;
  • force - applies an update, without checking the current version;
  • generateNewKey - re-encrypts files in the Store. It's useful when a user is removed and we want to prevent them from accessing the Store.