Storyblok Management API Typescript Client
typescript library for working with Storyblok management API.
Description
-
consists of:
- a basic CRUD client "
Storyblok
" with throttling and failure-retry - a wrapper library over the CRUD client "
ApiClient
" - typescript conversion of the original storyblok-js-client - "
StoryblokTS
" - abstraction classes with limited functionalities:
- Space
- Component
- Story
- FolderIndex
- Content
- Folder
- RootFolder
- Subfolder
- Asset
- AssetFolder
- a basic CRUD client "
-
ApiClient methods are categorized into the following:
-
API requests are throttled
-
images are compressed and resized using sharp
-
jest is setup for testing (not fully tested)
-
the management API is not fully implemented
Installation
npm install --save storyblok-ts-client
Usage
// Basic CRUD clientconst Storyblok = const storyblok = 'fake_api_token'return storyblok // => space id: 12345 // Management API wrapperconst ApiClient = const apiClient = 'fake_api_token' 12345return apiClientspaces // => space id: 12345 // StoryblokTSconst StoryblokTS = let storyblokTS = oauthToken: 'YOUR_OAUTH_TOKEN'const spaceId = 12345storyblokTSstoryblokTSstoryblokTS
CLI Scripts
# development and testing npm run dev # runs typescript transpiler in watch mode npm start # runs any executable code in the index.js # test - remember to update .env file with a test Storyblok account api token and test space id npm run dev:test # runs jest in watch mode npm test # runs jest npm run coverage # runs jest and check code coverage stat # build npm run build # tslint npm run lint # prettier npm run format
jsdoc2md
API Reference - generated withClasses
Functions
- imageToBuffer(filePath, [compress], [sizeLimit], [forceFormat]) ⇒
Promise
Generate buffered image (image compression and resize is applied accordingly).
- resizeImage(image, sizeLimit) ⇒
Promise
Resize a sharp object
ApiClient
Kind: global class
Implements: IStoryblokClass
Export:
- ApiClient
- new ApiClient(apiToken, spaceId)
- .assetFolders
- .create ⇒
Promise
- .delete ⇒
Promise
- .deleteExisting ⇒
Promise
- .get ⇒
Promise
- .getByName ⇒
Promise
- .getExisting ⇒
Promise
- .create ⇒
- .assets
- .count ⇒
Promise
- .createFromImage ⇒
Promise
- .delete ⇒
Promise
- .deleteExisting ⇒
Promise
- .get ⇒
Promise
- .getByPage ⇒
Promise.<Array.<IAsset>>
- .getByUrl ⇒
Promise
- .getExisting ⇒
Promise
- .register ⇒
Promise
- .upload ⇒
Promise
- .count ⇒
- .components
- .create ⇒
Promise
- .delete ⇒
Promise
- .deleteExisting ⇒
Promise
- .get ⇒
Promise
- .getExisting ⇒
Promise
- .update ⇒
Promise
- .create ⇒
Promise
- .create ⇒
- .spaces
- .get ⇒
Promise
- .get ⇒
- .stories
- .count ⇒
Promise
- .countPages ⇒
Promise
- .create ⇒
Promise
- .delete ⇒
Promise
- .deleteExisting ⇒
Promise
- .get ⇒
Promise
- .getByPage ⇒
Promise
- .getExisting ⇒
Promise
- .publish ⇒
Promise
- .publishPendings ⇒
Promise
- .reorder ⇒
Promise
- .update ⇒
Promise
- .publishPendings ⇒
Promise
- .count ⇒
- .countAssets ⇒
Promise
- .countStories ⇒
Promise
- .countStoryPages ⇒
Promise
- .createAssetFolder ⇒
Promise
- .createAssetFromImage ⇒
Promise
- .createStory ⇒
Promise
- .deleteAsset ⇒
Promise
- .deleteAssetFolder ⇒
Promise
- .deleteComponent ⇒
Promise
- .deleteStory ⇒
Promise
- .deleteExistingAssetFolders ⇒
Promise
- .deleteExistingAssets ⇒
Promise
- .deleteExistingComponents ⇒
Promise
- .deleteExistingStories ⇒
Promise
- .getAsset ⇒
Promise
- .getAssetByUrl ⇒
Promise
- .getAssetFolder ⇒
Promise
- .getAssetFolderByName ⇒
Promise
- .getComponent ⇒
Promise
- .getExistingAssets ⇒
Promise
- .getExistingComponents ⇒
Promise
- .getExistingAssetFolders ⇒
Promise
- .getExistingStories ⇒
Promise
- .getSpace ⇒
Promise
- .getStoriesByPage ⇒
Promise
- .publishStory ⇒
Promise
- .registerAsset ⇒
Promise
- .reorderStory ⇒
Promise
- .updateComponent ⇒
Promise
- .updateStory ⇒
Promise
- .uploadAsset ⇒
Promise
- .getAssetsByPage([page], [perPage]) ⇒
Promise.<Array.<IAsset>>
new ApiClient(apiToken, spaceId)
Management API wrapper around Storyblok class.
Param | Type | Description |
---|---|---|
apiToken | string |
API access token. |
spaceId | number |
Storyblok working space id. |
Example
const ApiClient = const apiClient = 'fake_api_token' 12345
apiClient.assetFolders
Object that contains API methods for asset folder operations
Kind: instance property of ApiClient
Read only: true
- .assetFolders
- .create ⇒
Promise
- .delete ⇒
Promise
- .deleteExisting ⇒
Promise
- .get ⇒
Promise
- .getByName ⇒
Promise
- .getExisting ⇒
Promise
- .create ⇒
Promise
assetFolders.create ⇒ Create an asset folder.
Kind: instance property of assetFolders
Fulfil: IAssetFolder
Details of the asset folder created.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
name | string |
Name of asset folder to create. |
Promise
assetFolders.delete ⇒ Delete a specific asset folder.
Kind: instance property of assetFolders
Fulfil: void
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
id | number |
Id of asset folder to be deleted. |
Promise
assetFolders.deleteExisting ⇒ Delete all existing asset folders.
Kind: instance property of assetFolders
Fulfil: void[]
Reject: AxiosError
Axios error.
Promise
assetFolders.get ⇒ Get a specific asset folder.
Kind: instance property of assetFolders
Fulfil: IAssetFolder
Asset folder information.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
id | number |
Id of the target asset folder. |
Promise
assetFolders.getByName ⇒ Get asset folders by matching asset folders names to the supplied string.
Kind: instance property of assetFolders
Fulfil: IAssetFolder[]
List of matched asset folders.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
searchString | string |
String to search by. |
Promise
assetFolders.getExisting ⇒ Get existing asset folders.
Kind: instance property of assetFolders
Fulfil: IAssetFolder[]
List of existing asset folders.
Reject: AxiosError
Axios error.
apiClient.assets
Object that contains API methods for asset operations
Kind: instance property of ApiClient
Read only: true
- .assets
- .count ⇒
Promise
- .createFromImage ⇒
Promise
- .delete ⇒
Promise
- .deleteExisting ⇒
Promise
- .get ⇒
Promise
- .getByPage ⇒
Promise.<Array.<IAsset>>
- .getByUrl ⇒
Promise
- .getExisting ⇒
Promise
- .register ⇒
Promise
- .upload ⇒
Promise
- .count ⇒
Promise
assets.count ⇒ Get total number of existing assets.
Kind: instance property of assets
Fulfil: number
A count of existing assets.
Reject: AxiosError
Axios error.
Promise
assets.createFromImage ⇒ Create an asset and upload the physical file.
Kind: instance property of assets
Fulfil: string
public access url of the new asset.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
data | IPendingAsset |
Asset information. |
filePath | string |
Absolute file path to the image. |
compress | boolean |
Flag to compress image. |
sizeLimit | number |
Resizing dimension limit value. |
Promise
assets.delete ⇒ Delete a specific asset.
Kind: instance property of assets
Fulfil: IAsset
Information of the deleted asset.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
id | number |
Id of the asset to be deleted. |
Promise
assets.deleteExisting ⇒ Delete all existing assets.
Kind: instance property of assets
Fulfil: IAsset[]
Information on the deleted assets.
Reject: AxiosError
Axios error.
Promise
assets.get ⇒ Get a specific asset.
Kind: instance property of assets
Fulfil: IAsset
Details of the asset.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
id | number |
Id of asset to fetch. |
Promise.<Array.<IAsset>>
assets.getByPage ⇒ Get asset on a specific pagination page number.
Kind: instance property of assets
Fulfil: IAsset[]
Assets on the pagination page.
Reject: AxiosError
Axios error.
Param | Type | Default | Description |
---|---|---|---|
[page] | number |
1 |
Pagination page. |
[perPage] | number |
25 |
Assets per page. |
Promise
assets.getByUrl ⇒ Find a specific asset by its public url.
Kind: instance property of assets
Fulfil: IAsset
Matched asset.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
url | string |
Url to match by. |
Promise
assets.getExisting ⇒ List all existing assets.
Kind: instance property of assets
Fulfil: IAsset[]
A list of existing assets.
Reject: AxiosError
Axios error.
Promise
assets.register ⇒ Register a Storyblok asset.
Kind: instance property of assets
Fulfil: IRegistration
Asset registration info (used for uploading).
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
asset | IPendingAsset |
Information to create asset from. |
asset.filename | string |
File name to register for. |
[asset.asset_folder_id] | number |
(optional) Assign a asset folder. |
[asset.id] | number |
(optional) Id of existing asset to replace with this new asset. |
Promise
assets.upload ⇒ Upload a registered asset with failure-retry (20 retries and incremental delay period of 1250ms with +/- 500ms variance).
Kind: instance property of assets
Fulfil: string
Access url of the uploaded asset.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
buffer | Buffer |
Buffered asset data. |
registration | IRegistration |
Registration info. |
apiClient.components
Object that contains API methods for component operations
Kind: instance property of ApiClient
Read only: true
- .components
- .create ⇒
Promise
- .delete ⇒
Promise
- .deleteExisting ⇒
Promise
- .get ⇒
Promise
- .getExisting ⇒
Promise
- .update ⇒
Promise
- .create ⇒
Promise
- .create ⇒
Promise
components.create ⇒ Create a component.
Kind: instance property of components
Fulfil: IComponent
Details of the component that was created.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
data | IPendingComponent |
Info on component to be created. |
Promise
components.delete ⇒ Delete a specific component.
Kind: instance property of components
Fulfil: IComponent
Details of the deleted component.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
id | number |
Id of component to be deleted. |
Promise
components.deleteExisting ⇒ Delete existing components.
Kind: instance property of components
Fulfil: IComponent[]
A list of deleted components details.
Reject: AxiosError
Axios error.
Promise
components.get ⇒ Fetch for a specific component.
Kind: instance property of components
Fulfil: IComponent
Details of the component definition.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
id | number |
Component id to fetch by. |
Promise
components.getExisting ⇒ List existing components.
Kind: instance property of components
Fulfil: IComponent[]
A list of component definitions.
Reject: AxiosError
Axios error.
Promise
components.update ⇒ Update a component.
Kind: instance property of components
Fulfil: IComponent
Details of component that was updated.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
data | IComponent |
Storyblok component data object with modified info. |
Promise
components.create ⇒ Create a component.
Kind: instance property of components
Fulfil: IComponent
Details of the component that was created.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
data | IPendingComponent |
Info on component to be created. |
apiClient.spaces
Object that contains API methods for space operations
Kind: instance property of ApiClient
Read only: true
Promise
spaces.get ⇒ Get information on the working Storyblok space.
Kind: instance property of spaces
Fulfil: ISpace
Working space information.
Reject: AxiosError
Axios error.
apiClient.stories
Object that contains API methods for story operations
Kind: instance property of ApiClient
Read only: true
- .stories
- .count ⇒
Promise
- .countPages ⇒
Promise
- .create ⇒
Promise
- .delete ⇒
Promise
- .deleteExisting ⇒
Promise
- .get ⇒
Promise
- .getByPage ⇒
Promise
- .getExisting ⇒
Promise
- .publish ⇒
Promise
- .publishPendings ⇒
Promise
- .reorder ⇒
Promise
- .update ⇒
Promise
- .publishPendings ⇒
Promise
- .count ⇒
Promise
stories.count ⇒ Get total number of existing stories (including folders).
Kind: instance property of stories
Fulfil: number
A count of existing stories.
Reject: AxiosError
Axios error.
Promise
stories.countPages ⇒ Get total pagination page count.
Kind: instance property of stories
Fulfil: number
Total story pagination page count.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
[perPage] | number |
(optional) How many stories per page. Defaults to 25. |
Promise
stories.create ⇒ Create a story.
Kind: instance property of stories
Fulfil: IStory
Details of story that was created.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
data | IPendingStory |
Storyblok story data object. |
Promise
stories.delete ⇒ Delete a specific story.
Kind: instance property of stories
Fulfil: IStory
Details of the story that was deleted.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
id | IStory |
Id of the story to be deleted. |
Promise
stories.deleteExisting ⇒ Delete all existing stories.
Kind: instance property of stories
Fulfil: IStory[]
A list of deleted stories details.
Reject: AxiosError
Axios error.
Promise
stories.get ⇒ Get a specific story.
Kind: instance property of stories
Fulfil: IStory
Details of content story.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
id | number |
Id of the content story. |
Promise
stories.getByPage ⇒ Get stories on a pagination page.
Kind: instance property of stories
Fulfil: IStory[]
A page of stories.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
page | number |
Pagination page number. |
[perPage] | number |
(optional) How many stories per page. Defaults to 25. |
Promise
stories.getExisting ⇒ List all existing stories.
Kind: instance property of stories
Fulfil: IStory[]
A list of existing content stories.
Reject: AxiosError
Axios error.
Promise
stories.publish ⇒ Publish a specific story.
Kind: instance property of stories
Fulfil: IStory
Details of the published story
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
id | number |
Id of the story to publish |
Promise
stories.publishPendings ⇒ Publish all unpublished stories.
Kind: instance property of stories
Fulfil: IStory[]
List of published stories.
Reject: AxiosError
Axios error.
Promise
stories.reorder ⇒ Update a story's sequential order.
Kind: instance property of stories
Fulfil: IStory
Details of the moved story.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
id | number |
Id of the story to be moved. |
afterId | number |
Id of reference story to position after. |
Promise
stories.update ⇒ Update a story.
Kind: instance property of stories
Fulfil: IStory
Details of story that was updated.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
data | IStory |
Modified story info. |
Promise
stories.publishPendings ⇒ Publish all unpublished stories.
Kind: instance property of stories
Fulfil: IStory[]
List of published stories.
Reject: AxiosError
Axios error.
Promise
apiClient.countAssets ⇒ Get total number of existing assets.
Kind: instance property of ApiClient
Fulfil: number
A count of existing assets.
Reject: AxiosError
Axios error.
Promise
apiClient.countStories ⇒ Get total number of existing stories (including folders).
Kind: instance property of ApiClient
Fulfil: number
A count of existing stories.
Reject: AxiosError
Axios error.
Promise
apiClient.countStoryPages ⇒ Get total pagination page count.
Kind: instance property of ApiClient
Fulfil: number
Total story pagination page count.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
[perPage] | number |
(optional) How many stories per page. Defaults to 25. |
Promise
apiClient.createAssetFolder ⇒ Create an asset folder.
Kind: instance property of ApiClient
Fulfil: IAssetFolder
Details of the asset folder created.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
name | string |
Name of asset folder to create. |
Promise
apiClient.createAssetFromImage ⇒ Create an asset and upload the physical file.
Kind: instance property of ApiClient
Fulfil: string
Public access url of the new asset.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
data | IPendingAsset |
Asset information. |
filePath | string |
Absolute file path to the image. |
compress | boolean |
Flag to compress image. |
sizeLimit | number |
Resizing dimension limit value. |
Promise
apiClient.createStory ⇒ Create a story.
Kind: instance property of ApiClient
Fulfil: IStory
Details of story that was created.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
data | IPendingStory |
Storyblok story data object. |
Promise
apiClient.deleteAsset ⇒ Delete a specific asset.
Kind: instance property of ApiClient
Fulfil: IAsset
Information of the deleted asset.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
id | number |
Id of the asset to be deleted. |
Promise
apiClient.deleteAssetFolder ⇒ Delete a specific asset folder.
Kind: instance property of ApiClient
Fulfil: void
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
id | number |
Id of asset folder to be deleted. |
Promise
apiClient.deleteComponent ⇒ Delete a specific component.
Kind: instance property of ApiClient
Fulfil: IComponent
Details of the deleted component.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
id | number |
Id of component to be deleted. |
Promise
apiClient.deleteStory ⇒ Delete a specific story.
Kind: instance property of ApiClient
Fulfil: IStory
Details of the story that was deleted.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
id | IStory |
Id of the story to be deleted. |
Promise
apiClient.deleteExistingAssetFolders ⇒ Delete all existing asset folders.
Kind: instance property of ApiClient
Fulfil: void[]
Reject: AxiosError
Axios error.
Promise
apiClient.deleteExistingAssets ⇒ Delete all existing assets.
Kind: instance property of ApiClient
Fulfil: IAsset[]
Information on the deleted assets.
Reject: AxiosError
Axios error.
Promise
apiClient.deleteExistingComponents ⇒ Delete existing components.
Kind: instance property of ApiClient
Fulfil: IComponent[]
A list of deleted components details.
Reject: AxiosError
Axios error.
Promise
apiClient.deleteExistingStories ⇒ Delete all existing stories.
Kind: instance property of ApiClient
Fulfil: IStory[]
A list of deleted stories details.
Reject: AxiosError
Axios error.
Promise
apiClient.getAsset ⇒ Get a specific asset.
Kind: instance property of ApiClient
Fulfil: IAsset
Details of the asset.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
id | number |
Id of asset to fetch. |
Promise
apiClient.getAssetByUrl ⇒ Find a specific asset by its public url.
Kind: instance property of ApiClient
Fulfil: IAsset
Matched asset.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
url | string |
Url to match by. |
Promise
apiClient.getAssetFolder ⇒ Get a specific asset folder.
Kind: instance property of ApiClient
Fulfil: IAssetFolder
Asset folder information.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
id | number |
Id of the target asset folder. |
Promise
apiClient.getAssetFolderByName ⇒ Get asset folders by matching asset folders names to the supplied string.
Kind: instance property of ApiClient
Fulfil: IAssetFolder[]
List of matched asset folders.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
searchString | string |
String to search by. |
Promise
apiClient.getComponent ⇒ Fetch for a specific component.
Kind: instance property of ApiClient
Fulfil: IComponent
Details of the component definition.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
id | number |
Component id to fetch by. |
Promise
apiClient.getExistingAssets ⇒ List all existing assets.
Kind: instance property of ApiClient
Fulfil: IAsset[]
A list of existing assets.
Reject: AxiosError
Axios error.
Promise
apiClient.getExistingComponents ⇒ List existing components.
Kind: instance property of ApiClient
Fulfil: IComponent[]
A list of component definitions.
Reject: AxiosError
Axios error.
Promise
apiClient.getExistingAssetFolders ⇒ Get existing asset folders.
Kind: instance property of ApiClient
Fulfil: IAssetFolder[]
List of existing asset folders.
Reject: AxiosError
Axios error.
Promise
apiClient.getExistingStories ⇒ List all existing stories.
Kind: instance property of ApiClient
Fulfil: IStory[]
A list of existing content stories.
Reject: AxiosError
Axios error.
Promise
apiClient.getSpace ⇒ Get information on the working Storyblok space.
Kind: instance property of ApiClient
Fulfil: ISpace
Working space information.
Reject: AxiosError
Axios error.
Promise
apiClient.getStoriesByPage ⇒ Get stories on a pagination page.
Kind: instance property of ApiClient
Fulfil: IStory[]
A page of stories.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
page | number |
Pagination page number. |
[perPage] | number |
(optional) How many stories per page. Defaults to 25. |
Promise
apiClient.publishStory ⇒ Publish a specific story.
Kind: instance property of ApiClient
Fulfil: IStory
Details of the published story
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
id | number |
Id of the story to publish |
Promise
apiClient.registerAsset ⇒ Register a Storyblok asset.
Kind: instance property of ApiClient
Fulfil: IRegistration
Asset registration info (used for uploading).
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
asset | IPendingAsset |
Information to create asset from. |
asset.filename | string |
File name to register for. |
[asset.asset_folder_id] | number |
(optional) Assign a asset folder. |
[asset.id] | number |
(optional) Id of existing asset to replace with this new asset. |
Promise
apiClient.reorderStory ⇒ Update a story's sequential order.
Kind: instance property of ApiClient
Fulfil: IStory
Details of the moved story.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
id | number |
Id of the story to be moved. |
afterId | number |
Reference story to position after. |
Promise
apiClient.updateComponent ⇒ Update a component.
Kind: instance property of ApiClient
Fulfil: IComponent
Details of component that was updated.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
data | IComponent |
Storyblok component data object with modified info. |
Promise
apiClient.updateStory ⇒ Update a story.
Kind: instance property of ApiClient
Fulfil: IStory
Details of story that was updated.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
data | IStory |
Storyblok story data object with modified info. |
Promise
apiClient.uploadAsset ⇒ Upload a registered asset with failure-retry (20 retries and incremental delay period of 1250ms with +/- 500ms variance).
Kind: instance property of ApiClient
Fulfil: string
Access url of the uploaded asset.
Reject: AxiosError
Axios error.
Param | Type | Description |
---|---|---|
buffer | Buffer |
Buffered asset data. |
registration | IRegistration |
Registration info. |
Promise.<Array.<IAsset>>
apiClient.getAssetsByPage([page], [perPage]) ⇒ Get asset on a specific pagination page number.
Kind: instance method of ApiClient
Fulfil: IAsset[]
Assets on the pagination page.
Reject: AxiosError
Axios error.
Param | Type | Default | Description |
---|---|---|---|
[page] | number |
1 |
Pagination page. |
[perPage] | number |
25 |
Assets per page. |
Storyblok
Kind: global class
Implements: IStoryblokClass
Export:
- Storyblok
- new Storyblok(apiToken)
- .delete ⇒
Promise.<any>
- .get ⇒
Promise.<any>
- .post ⇒
Promise.<any>
- .put ⇒
Promise.<any>
new Storyblok(apiToken)
A class to provide basic CRUD request methods to Storyblok's management API with failure-retry options and built-in request throttling. Uses axios library to facilitation the API calls.
Param | Type | Description |
---|---|---|
apiToken | string |
API access token. |
Example
const Storyblok = const storyblok = 'fake_api_token'
Promise.<any>
storyblok.delete ⇒ DELETE request method.
Kind: instance property of Storyblok
Param | Type | Default | Description |
---|---|---|---|
[url] | string |
"'/'" |
Request url. |
[config] | ICustomAxiosRequestConfig |
Request config. |
Example
const Storyblok = const storyblok = 'fake_api_token'const spaceId = 12345const storyId = 123456const url = `//stories/`storyblok // => deleted story id: 123456
Promise.<any>
storyblok.get ⇒ GET request method.
Kind: instance property of Storyblok
Param | Type | Default | Description |
---|---|---|---|
[url] | string |
"'/'" |
Request url. |
[config] | ICustomAxiosRequestConfig |
Request config. |
Example
const Storyblok = const storyblok = 'fake_api_token'const spaceId = 12345const url = `/`storyblok // => space id: 12345
Promise.<any>
storyblok.post ⇒ POST request method.
Kind: instance property of Storyblok
Param | Type | Default | Description |
---|---|---|---|
[url] | string |
"'/'" |
Request url. |
[data] | any |
Request data body. |
|
[config] | ICustomAxiosRequestConfig |
Request config. |
Example
const Storyblok = const storyblok = 'fake_api_token'const spaceId = 12345const url = `//stories`const story = name: 'test' slug: 'test'storyblok // => new story id: 123456
Promise.<any>
storyblok.put ⇒ PUT request method.
Kind: instance property of Storyblok
Param | Type | Default | Description |
---|---|---|---|
[url] | string |
"'/'" |
Request url. |
[data] | any |
Request data body. |
|
[config] | ICustomAxiosRequestConfig |
Request config. |
Example
const Storyblok = const storyblok = 'fake_api_token'const spaceId = 12345const url = `//stories`const story = name: 'test' slug: 'test'storyblok // => new story id: 123456// => new story name: test// => updated story name: new test
StoryblokTS
new StoryblokTS(config, [rateLimit], [endpoint])
This is a thin wrapper for the Storyblok API's to use in Node.js and the browser. It is a typescript conversion of the Universal Javascript SDK library (https://www.npmjs.com/package/storyblok-js-client).
Param | Type | Description |
---|---|---|
config | any |
Configurations. |
config.accessToken | string |
The preview token you can find in your space dashboard at https://app.storyblok.com. |
[config.cache] | any |
Cache types. |
config.cache.type | string |
'none' or 'memory'. |
config.cache.clear | string |
'auto' or 'manual'. |
[config.headers] | any |
Request headers. |
[config.region] | string |
Region. |
[config.https] | boolean |
Switch for https. |
[config.oauthToken] | string |
Management API key. |
[rateLimit] | number |
Throttle value (defaults to 3 for management api and 5 for cdn api). |
[endpoint] | string |
API endpoint. |
Example
// Example for using the content delivery api// 1. Require the Storyblok clientconst StoryblokTS = // 2. Initialize the client with the preview// token from your space dashboard at// https://app.storyblok.comlet Storyblok = accessToken: 'your_access_token' // Example for using the content management api// 1. Require the Storyblok clientconst StoryblokTS = const spaceId = 12345// 2. Initialize the client with the oauth token// from the my account area at// https://app.storyblok.comlet Storyblok = oauthToken: 'YOUR_OAUTH_TOKEN'StoryblokStoryblokStoryblok
Promise
imageToBuffer(filePath, [compress], [sizeLimit], [forceFormat]) ⇒ Generate buffered image (image compression and resize is applied accordingly).
Kind: global function
Fulfil: Buffer
Buffered image data.
Reject: Error
Error value.
Param | Type | Description |
---|---|---|
filePath | string |
Absolute path to image file. |
[compress] | boolean |
Flag to compress image. |
[sizeLimit] | number |
Resizing dimension limit value. |
[forceFormat] | string |
Force convert to a particular format. |
Promise
resizeImage(image, sizeLimit) ⇒ Resize a sharp object
Kind: global function
Fulfil: Sharp
Resized sharp object.
Reject: Error
Error value.
Param | Type | Default | Description |
---|---|---|---|
image | Sharp |
sharp object. |
|
sizeLimit | number |
640 |
Size (in pixels) to limit image dimension. |
© 2018 juniorCitizen