import { QelosSDKOptions, RequestExtra } from '../types'; import BaseSDK from '../base-sdk'; import { IIntegrationSource, IIntegrationSourceStatusRequest, IIntegrationSourceStatusResult, } from '@qelos/global-types'; export default class QlIntegrationSources extends BaseSDK { private relativePath = '/api/integration-sources'; constructor(private options: QelosSDKOptions) { super(options) } getIntegrationSource(sourceId: string, extra?: RequestExtra) { return this.callJsonApi(`${this.relativePath}/${sourceId}`, extra); } getList(query?: { kind?: string }, extra?: RequestExtra) { return this.callJsonApi(this.relativePath + this.getQueryParams(query), extra); } remove(sourceId: string): Promise { return this.callApi(`${this.relativePath}/${sourceId}`, { method: 'delete' }); } update(sourceId: string, changes: Partial>): Promise { return this.callJsonApi( `${this.relativePath}/${sourceId}`, { method: 'put', headers: { 'content-type': 'application/json' }, body: JSON.stringify(changes) } ) } create(source: Pick): Promise { return this.callJsonApi(this.relativePath, { method: 'post', headers: { 'content-type': 'application/json' }, body: JSON.stringify(source) }) } checkStatus( sourceId: string, overrides?: Partial>, ): Promise { return this.callJsonApi( `${this.relativePath}/${sourceId}/status`, { method: 'post', headers: { 'content-type': 'application/json' }, body: JSON.stringify(overrides ?? {}), }, ); } checkDraftStatus(source: IIntegrationSourceStatusRequest): Promise { return this.callJsonApi( `${this.relativePath}/status`, { method: 'post', headers: { 'content-type': 'application/json' }, body: JSON.stringify(source), }, ); } }