# Storyblok Management API Typescript Client

[typescript](https://github.com/Microsoft/TypeScript) library for working with [Storyblok management API](https://api.storyblok.com/docs).

[![npm](https://img.shields.io/npm/v/storyblok-ts-client.svg)](https://www.npmjs.com/package/storyblok-ts-client)

## Description

<hr>

* consists of:
  * a basic CRUD client "[`Storyblok`](#Storyblok)" with throttling and failure-retry
  * a wrapper library over the CRUD client "[`ApiClient`](#ApiClient)"
  * typescript conversion of the original [storyblok-js-client](https://github.com/storyblok/storyblok-js-client) - "[`StoryblokTS`](#StoryblokTS)"
  * abstraction classes with limited functionalities:
    * Space
    * Component
    * Story
      * FolderIndex
      * Content
      * Folder
        * RootFolder
        * Subfolder
    * Asset
    * AssetFolder

* [ApiClient](#ApiClient) methods are categorized into the following:

  * [assetFolders](#ApiClient+assetFolders)
  * [assets](#ApiClient+assets)
  * [components](#ApiClient+components)
  * [spaces](#ApiClient+spaces)
  * [stories](#ApiClient+stories)

* API requests are throttled

* images are compressed and resized using [sharp](https://github.com/lovell/sharp)

* [jest](https://github.com/facebook/jest) is setup for testing (not fully tested)

* the management API is not fully implemented

## Installation

<hr>

```bash
npm install --save storyblok-ts-client
```

## Usage

<hr>

```js
// Basic CRUD client
const {Storyblok} = require('storyblok-ts-client')
const storyblok = new Storyblok('fake_api_token')
return storyblok.get('/12345')
  .then(res => console.log('space id:', res.data.id))
  // => space id: 12345

// Management API wrapper
const {ApiClient} = require('storyblok-ts-client')
const apiClient = new ApiClient('fake_api_token', 12345)
return apiClient.spaces.get()
  .then(space => console.log('space id:', space.id))
  // => space id: 12345

// StoryblokTS
const {StoryblokTS} = require('storyblok-ts-client')
let storyblokTS = new StoryblokTS({oauthToken: 'YOUR_OAUTH_TOKEN'})
const spaceId = 12345
storyblokTS.post(`spaces/${spaceId}/stories`, {story: {name: 'xy', slug: 'xy'}})
storyblokTS.put(`spaces/${spaceId}/stories/1`, {story: {name: 'xy', slug: 'xy'}})
storyblokTS.delete(`spaces/${spaceId}/stories/1`, null)
```

## CLI Scripts

<hr>

```bash
# 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
```

## API Reference - generated with [jsdoc2md](https://github.com/jsdoc2md/jsdoc-to-markdown/wiki/How-to-document-TypeScript)

<hr>

{{>main~}}


<hr>

&copy; 2018 juniorCitizen
