import {QelosSDKOptions} from './types'; import BaseSDK from './base-sdk'; export interface IBlock { name: string; description?: string; content: string; contentType?: 'content' | 'html' [key: string]: any; } export default class QlBlocks extends BaseSDK { private relativePath = '/api/blocks'; constructor(options: QelosSDKOptions) { super(options) } getBlock(blockId: string) { return this.callJsonApi(`${this.relativePath}/${blockId}`) } getList() { return this.callJsonApi(this.relativePath); } remove(blockId: string): Promise { return this.callApi(`${this.relativePath}/${blockId}`, {method: 'delete'}); } update(blockId: string, changes: Partial): Promise { return this.callJsonApi( `${this.relativePath}/${blockId}`, { method: 'put', headers: {'content-type': 'application/json'}, body: JSON.stringify(changes)} ) } create(block: IBlock): Promise { return this.callJsonApi(this.relativePath, { method: 'post', headers: {'content-type': 'application/json'}, body: JSON.stringify(block) }) } }