@apihawk/help-center-sdk
Version:
The ApiHawk Help Center SDK
45 lines (44 loc) • 2.32 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const errors_1 = require("@apihawk/errors");
const help_center_sdk_service_base_1 = require("../lib/help-center-sdk-service-base");
const generate_toc_1 = require("./common/generate-toc");
const parseTags_1 = require("./common/parseTags");
const set_missing_id_attributes_1 = require("./common/set-missing-id-attributes");
class HelpCenterSDKSEO extends help_center_sdk_service_base_1.HelpCenterSDKServiceBase {
searchBySeoUrl(rootCategory, url) {
return __awaiter(this, void 0, void 0, function* () {
const searchResult = yield this.api
.call({
url: `/seo/url?search=/${rootCategory}/${url}`,
method: 'GET'
});
if (searchResult.result.entity_type === 'content') {
// @ts-ignore
const article = searchResult.result.content.entity;
const htmlContent = set_missing_id_attributes_1.default(article.data_html);
const transformedArticle = Object.assign({}, article, {
data_html: set_missing_id_attributes_1.default(article.data_html),
tags: parseTags_1.default(article.tags),
toc: generate_toc_1.default(htmlContent)
});
return Object.assign({}, searchResult, {
content: {
entity: transformedArticle
}
});
}
throw new errors_1.NotFoundError();
});
}
}
exports.HelpCenterSDKSEO = HelpCenterSDKSEO;