2.6.0 • Published 6 years ago

storyblok-management-api-wrapper v2.6.0

Weekly downloads
58
License
MIT
Repository
github
Last release
6 years ago

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

// 1. require the StoryblokApiClient
const StoryblokApiClient = require("storyblok-management-api-wrapper")

// 2. initialize the client with spaceId and apiKey
const spaceId = 123456
const apiKey = asdfklasjdfaksjfdaksjdfasjk
const apiClient = new StoryblokApiClient({ spaceId, apiKey })

Classes

StoryblokApiClient

instance of Storyblok API interface

Kind: global class

new StoryblokApiClient(config)

initialize an instance

ParamTypeDescription
configObjectsetup parameters
config.spaceIdnumber | stringworking spaceId
config.apiKeystringmanagement API oauth token
config.regionstringregion, default: undefined (optional)
config.timeoutnumbertimeout, default: 0 (optional)
config.httpsbooleanrequest protocol, default: undefined (optional)
config.rateLimitnumberrequest rate limit, default: 3 (optional)

Example

// 1. require the StoryblokApiClient
const StoryblokApiClient = require("storyblok-management-api-wrapper")

// 2. initialize the client with spaceId and apiKey
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

ParamTypeDescription
namestringname of folder to create

storyblokApiClient.createComponent(definition) ⇒ Object

create a component

Kind: instance method of StoryblokApiClient Returns: Object - details of component that was created

ParamTypeDescription
definitionObjectStoryblok component definition object

storyblokApiClient.createStory(storyData) ⇒ Object

create a content story

Kind: instance method of StoryblokApiClient Returns: Object - details of story that was created

ParamTypeDescription
storyDataObjectStoryblok 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

ParamTypeDefaultDescription
filePathstringabsolute file path to image
compressionbooleanfalseflag to compress image
dimLimitnumberresize dimension limit value

storyblokApiClient.deleteAsset(assetId) ⇒ number

delete a specific asset

Kind: instance method of StoryblokApiClient Returns: number - assetId is returned on success

ParamTypeDescription
assetIdnumberid 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

ParamTypeDescription
assetFolderIdnumberid 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

ParamTypeDescription
componentIdnumberid 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

ParamTypeDescription
storyIdnumberid of the story to be deleted

storyblokApiClient.getComponent(componentId) ⇒ Object

get a specific component

Kind: instance method of StoryblokApiClient Returns: Object - component definition

ParamTypeDescription
componentIdnumberid 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

ParamTypeDescription
storyIdnumberid 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

ParamTypeDescription
storyIdnumberstory id

storyblokApiClient.reorderStory(storyId, afterId) ⇒ Object

modify a story's sequential order

Kind: instance method of StoryblokApiClient Returns: Object - details of the moved story

ParamTypeDescription
storyIdstringid of the story to be moved
afterIdstringto 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

ParamTypeDescription
filenamestringfile 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

ParamTypeDescription
bufferBufferbuffered asset
signedRequestObjectthe server response from 'signAsset()' method

apiErrorHandler(error, fnName)

API error handler

Kind: global function

ParamTypeDescription
errorObjecterror object provided by the request
fnNamestringfunction 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

ParamTypeDefaultDescription
filePathstringabsolute path to image file
compressionbooleanfalseflag to compress image
dimLimitnumberresizing 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

ParamTypeDescription
imageObjectsharp.js image object
compressionbooleanflag 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

ParamTypeDescription
imageObjectsharp.js image object
dimLimitnumbervalue to limit image dimension
2.6.0

6 years ago

2.4.3

6 years ago

2.4.2

6 years ago

2.4.1

6 years ago

2.4.0

6 years ago

2.3.1

6 years ago

2.3.0

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.0

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.16

6 years ago

0.0.15

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago