Storyblok Management API Wrapper
library for working with Storyblok management API. Uses axios to make Storyblok management API calls. Based on the official storyblok/storyblok-js-client
Install
npm install --save storyblok-management-api-wrapper
Usage
const StoryblokApiClient = require("storyblok-management-api-wrapper")
const spaceId = 123456
const apiKey = asdfklasjdfaksjfdaksjdfasjk
const apiClient = new StoryblokApiClient({ spaceId, apiKey })
Classes
- StoryblokApiClient
instance of Storyblok API interface
StoryblokApiClient
instance of Storyblok API interface
Kind: global class
new StoryblokApiClient(config)
initialize an instance
Param | Type | Description |
---|
config | Object | setup parameters |
config.spaceId | number | string | working spaceId |
config.apiKey | string | management API oauth token |
config.region | string | region, default: undefined (optional) |
config.timeout | number | timeout, default: 0 (optional) |
config.https | boolean | request protocol, default: undefined (optional) |
config.rateLimit | number | request rate limit, default: 3 (optional) |
Example
const StoryblokApiClient = require("storyblok-management-api-wrapper")
const spaceId = 123456
const apiKey = asdfklasjdfaksjfdaksjdfasjk
const apiClient = new StoryblokApiClient({ spaceId, apiKey })
storyblokApiClient.countAssets() ⇒ number
get total number of existing assets
Kind: instance method of StoryblokApiClient
Returns: number
- get a count of existing assets
storyblokApiClient.countStories() ⇒ number
get total number of existing stories
Storyblok API's space info does not account 'folders' as stories, so "this.getSpace({ spaceId }).then(space => space.stories_count)" does not work for the purpose of this function
must be manually retrieved
Kind: instance method of StoryblokApiClient
Returns: number
- get a count of existing stories
storyblokApiClient.createAssetFolder(name) ⇒ Object
create an asset folder
Kind: instance method of StoryblokApiClient
Returns: Object
- asset folder information
Param | Type | Description |
---|
name | string | name of folder to create |
storyblokApiClient.createComponent(definition) ⇒ Object
create a component
Kind: instance method of StoryblokApiClient
Returns: Object
- details of component that was created
Param | Type | Description |
---|
definition | Object | Storyblok component definition object |
storyblokApiClient.createStory(storyData) ⇒ Object
create a content story
Kind: instance method of StoryblokApiClient
Returns: Object
- details of story that was created
Param | Type | Description |
---|
storyData | Object | Storyblok story data object |
storyblokApiClient.createImageAsset(filePath, compression, dimLimit) ⇒ string
create an asset from image
compression and resize using the sharp.js
library
Kind: instance method of StoryblokApiClient
Returns: string
- public url to access the asset
Param | Type | Default | Description |
---|
filePath | string | | absolute file path to image |
compression | boolean | false | flag to compress image |
dimLimit | number | | resize dimension limit value |
storyblokApiClient.deleteAsset(assetId) ⇒ number
delete a specific asset
Kind: instance method of StoryblokApiClient
Returns: number
- assetId is returned on success
Param | Type | Description |
---|
assetId | number | id of the asset to be deleted |
storyblokApiClient.deleteAssetFolder(assetFolderId) ⇒ number
delete a specific asset folder
Kind: instance method of StoryblokApiClient
Returns: number
- assetFolderId is returned on success
Param | Type | Description |
---|
assetFolderId | number | id of asset folder to be deleted |
storyblokApiClient.deleteComponent(componentId) ⇒ number
delete a specific component
Kind: instance method of StoryblokApiClient
Returns: number
- componentId is returned on success
Param | Type | Description |
---|
componentId | number | id of component to be deleted |
storyblokApiClient.deleteExistingAssets() ⇒ Array.<number>
delete all existing assets
Kind: instance method of StoryblokApiClient
Returns: Array.<number>
- array of asset id's that were removed
storyblokApiClient.deleteExistingComponents() ⇒ Array.<number>
delete all existing components
Kind: instance method of StoryblokApiClient
Returns: Array.<number>
- array of component id's that were removed
storyblokApiClient.deleteExistingStories()
delete all existing stories
Kind: instance method of StoryblokApiClient
storyblokApiClient.deleteStory(storyId) ⇒ number
delete a specific story
Kind: instance method of StoryblokApiClient
Returns: number
- id of story that was removed
Param | Type | Description |
---|
storyId | number | id of the story to be deleted |
storyblokApiClient.getComponent(componentId) ⇒ Object
get a specific component
Kind: instance method of StoryblokApiClient
Returns: Object
- component definition
Param | Type | Description |
---|
componentId | number | id of component |
storyblokApiClient.getExistingAssets() ⇒ Array.<Object>
list all existing assets
Kind: instance method of StoryblokApiClient
Returns: Array.<Object>
- full list of existing assets
storyblokApiClient.getExistingAssetFolders() ⇒ Array.<Object>
list all existing asset folders
Kind: instance method of StoryblokApiClient
Returns: Array.<Object>
- List of asset folder details
storyblokApiClient.getExistingComponents() ⇒ Array.<Object>
list all existing components
(it is assumed that the working space has at most 1000 existing components)
Kind: instance method of StoryblokApiClient
Returns: Array.<Object>
- List of component definitions
storyblokApiClient.getExistingStories() ⇒ Array.<Object>
list all existing stories
Kind: instance method of StoryblokApiClient
Returns: Array.<Object>
- full list of existing content stories
storyblokApiClient.getSpace() ⇒ Object
get information on the working space
Kind: instance method of StoryblokApiClient
Returns: Object
- space information
storyblokApiClient.getStory(storyId) ⇒ Object
get a specific story
Kind: instance method of StoryblokApiClient
Returns: Object
- details of content story
Param | Type | Description |
---|
storyId | number | id of the content story |
storyblokApiClient.publishExistingStories() ⇒ Array.<number>
publish existing stories
Kind: instance method of StoryblokApiClient
Returns: Array.<number>
- list of published story id's
storyblokApiClient.publishStory(storyId) ⇒ number
publish a specific story
Kind: instance method of StoryblokApiClient
Returns: number
- published story id
Param | Type | Description |
---|
storyId | number | story id |
storyblokApiClient.reorderStory(storyId, afterId) ⇒ Object
modify a story's sequential order
Kind: instance method of StoryblokApiClient
Returns: Object
- details of the moved story
Param | Type | Description |
---|
storyId | string | id of the story to be moved |
afterId | string | to be positioned after story of this id |
storyblokApiClient.signAsset(filename) ⇒ Object
register a file as a Storyblok asset
the physical file still has to be uploaded
Kind: instance method of StoryblokApiClient
Returns: Object
- asset signing info
Param | Type | Description |
---|
filename | string | file name to be register |
storyblokApiClient.uploadAsset(buffer, signedRequest) ⇒ string
physically upload an asset after it is registered with 'signAsset()' method
Kind: instance method of StoryblokApiClient
Returns: string
- Url to access the asset
Param | Type | Description |
---|
buffer | Buffer | buffered asset |
signedRequest | Object | the server response from 'signAsset()' method |
apiErrorHandler(error, fnName)
API error handler
Kind: global function
Param | Type | Description |
---|
error | Object | error object provided by the request |
fnName | string | function name where the error occured |
bufferImage(filePath, compression, dimLimit) ⇒ Promise.<Buffer>
Using 'sharp' library to generate data buffer
image compression is applied accordingly
Kind: global function
Returns: Promise.<Buffer>
- buffered image data
Param | Type | Default | Description |
---|
filePath | string | | absolute path to image file |
compression | boolean | false | flag to compress image |
dimLimit | number | | resizing dimension limit value |
compressImage(image, compression) ⇒ Object
takes a sharp.js image object and compress as specified
Kind: global function
Returns: Object
- processed sharp.js image object
Param | Type | Description |
---|
image | Object | sharp.js image object |
compression | boolean | flag to compress image |
resizeImage(image, dimLimit) ⇒ Object
takes a sharp.js image object and resize as specified
Kind: global function
Returns: Object
- processed sharp.js image object
Param | Type | Description |
---|
image | Object | sharp.js image object |
dimLimit | number | value to limit image dimension |