Skip to content

beamable-sdk / services / ContentService

Class: ContentService

Defined in: src/services/ContentService.ts:56

Represents a service that can be refreshed.

Extends

Implements

Constructors

Constructor

new ContentService(props): ContentService

Defined in: src/services/ContentService.ts:73

Parameters

props

ApiServiceProps

Returns

ContentService

Overrides

ApiService.constructor

Accessors

contentsCache

Get Signature

get contentsCache(): Record<string, Record<string, ContentBase>>

Defined in: src/services/ContentService.ts:84

Retrieves the contents cache.

Returns

Record<string, Record<string, ContentBase>>


manifestChecksumsCache

Get Signature

get manifestChecksumsCache(): Record<string, ContentManifestChecksum>

Defined in: src/services/ContentService.ts:89

Retrieves the manifest checksums cache.

Returns

Record<string, ContentManifestChecksum>


manifestEntriesCache

Get Signature

get manifestEntriesCache(): Record<string, ClientContentInfoJson[]>

Defined in: src/services/ContentService.ts:94

Retrieves the manifest entries cache.

Returns

Record<string, ClientContentInfoJson[]>

Methods

getById()

getById<T>(params): Promise<ContentTypeFromId<T>>

Defined in: src/services/ContentService.ts:162

Retrieves content by its ID.

Type Parameters

T

T extends string

Parameters

params

GetContentByIdParams<T>

Returns

Promise<ContentTypeFromId<T>>

The content object.

Remarks

This method first checks the in-memory cache, then persistent storage, and finally fetches from the API if not found or if the content is outdated.

Example

const item = await beam.content.getById({
  id: 'items.my_item',
  manifestId: 'global', // Optional, defaults to 'global'
});
console.log(item.properties);

Throws

If the content is not found or cannot be retrieved.


getByIds()

getByIds(params): Promise<ContentBase<unknown>[]>

Defined in: src/services/ContentService.ts:185

Retrieves group of contents by their IDs.

Parameters

params

GetContentByIdsParams

Returns

Promise<ContentBase<unknown>[]>

An array of content objects.

Remarks

This method first checks the in-memory cache, then persistent storage, and finally fetches from the API if not found or if the content is outdated.

Example

const items = await beam.content.getByIds({
  ids: ['items.my_item_1', 'items.my_item_2'],
  manifestId: 'global', // Optional, defaults to 'global'
});
console.log(items[0].properties);

Throws

If any content is not found or cannot be retrieved.


getByType()

getByType<T>(params): Promise<ContentTypeFromId<T>[]>

Defined in: src/services/ContentService.ts:211

Retrieves group of contents by their type.

Type Parameters

T

T extends keyof ContentTypeMap

Parameters

params

GetContentByTypeParams<T>

Returns

Promise<ContentTypeFromId<T>[]>

An array of content objects of the specified type.

Remarks

This method first checks the in-memory cache, then persistent storage, and finally fetches from the API if not found or if the content is outdated.

Example

const items = await beam.content.getByType({
  type: 'items',
  manifestId: 'global', // Optional, defaults to 'global'
});
console.log(items[0].properties);

Throws

If the content is not found or cannot be retrieved.


getManifestEntries()

getManifestEntries(params): Promise<ClientContentInfoJson[]>

Defined in: src/services/ContentService.ts:135

Retrieves all manifest entries for a given manifest ID.

Parameters

params

GetManifestEntriesParams = {}

Returns

Promise<ClientContentInfoJson[]>

An array of manifest entries.

Remarks

This method first checks the in-memory cache, then persistent storage, and finally fetches from the API if not found.

Example

const entries = await beam.content.getManifestEntries({
  manifestId: 'global', // Optional, defaults to 'global'
});
console.log(entries[0].contentId);

refresh()

refresh(data): Promise<ContentManifestChecksum>

Defined in: src/services/ContentService.ts:111

Refreshes the content manifest for a given ID.

Parameters

data

ContentManifestChecksum

Returns

Promise<ContentManifestChecksum>

Remarks

This method fetches the latest content manifest and updates the local cache.

Example

await beam.content.refresh({
  id: 'global',
  checksum: 'some-checksum',
  uid: 'some-uid',
});

Throws

If the refresh fails.

Implementation of

RefreshableService.refresh