Abbe API utils
Utilities for converting to Abbe article format. The library provides types for all fields and an abstraction on top of DraftJS for the content. The library can also validate the data against Abbe's API Schema by calling the builder function .validateSchema(abbeUrl)
on the article, where abbeUrl
is the URL to the Abbe API you want to validate the data against.
Create article:
import { Article } from "@bonniernews/abbe-api-utils";
const article = Article.initialize()
.setUuid("8aae8868-c423-4956-89fb-4cbffa75ee20")
.setPublishedAt(new Date("2024-01-29"))
.setCreated(new Date("2024-01-28"))
.setUpdated(new Date("2024-01-30"))
.setExternalId("external-id-123")
.setHeadline("Amazing title")
.setOriginalSource("original-source")
.setArticleState(ArticleState.PUBLISHED)
.setPremiumLevel(PremiumLevel.NONE)
.setNewsValue(NewsValue.ONE)
.setFunctionTags(["2406db2a-f085-4dcd-88a6-b803a94582e0"])
.setStories(["a52f66c2-c844-44c7-9e72-3641872e4318"])
.setBylines(["766156df-a398-4407-805e-db0bbba34104"])
.setArticleType("a2a4b94d-1126-48c0-81e4-0c5b4a4865e7")
.setCategories(["5d329def-c27b-4f0f-aaf5-c1873f674746"])
.setLocations(["6c4defdd-2661-420a-9938-4f5bd1c75be8"])
.setTags(["71fbe627-f0e9-4157-aeb7-67a1be2787e8"])
.setChannels(["1a349e41-8d58-402c-ad61-759c2917acae"])
.setSections(["1289c955-3e10-4074-8dca-d27bd2f52665"])
.setPoints(["1289c955-3e10-4074-8dca-123123213scds"])
.setContent(articleContent)
.setPuff(
Puff.initialize()
.setHeadLine("Puff headline")
.setSubheading("Sub heading")
.setImage("6ccd1a11-9e8a-48c0-a669-196589d8bfbd")
)
.validateSchema("https://abbe-url.com")
.finalize();
Create article content
import { Article } from "@bonniernews/abbe-api-utils";
const content = Article.initializeContent()
.addTitle("Amazing title");
.addPreamble("Amazing preamble");
.addHeadline("Amazing headline");
.addText("Normal text")
.addStyledText("Bold and italic text", [
{ style: Style.BOLD, position: { start: 0, length: 4 } },
{ style: Style.ITALIC, position: { start: 5, length: 4 } },
])
.addStyledText("An awesome link", [
{
style: Style.LINK,
position: { start: 3, length: 7 },
url: "https://google.com",
},
])
.addImage({
uuid: "72a1c287-0604-4297-9612-de6124c5ee0b",
photoAuthor: "Mozart",
caption: "He's Dope"
})
.addImageCollection([
{
uuid: "ece2653f-0fbb-434b-b380-11723cf23e6a",
photoAuthor: "Author 1",
caption: "Caption 1",
},
{
uuid: "6ccd1a11-9e8a-48c0-a669-196589d8bfbd",
photoAuthor: "Author 2",
caption: "Caption 2",
},
{
uuid: "d6d21ff6-f779-4dcd-bcf3-71cfd4c48e74",
photoAuthor: "Author 3",
caption: "Caption 3",
}
])
.addEmbed({
embedUuid: "15e9c365-6dce-4d96-a168-aa3cbe17bb56",
externalId: "22131"
});
article.setContent(content)
If you want to laborate with creating an article in Abbe:
ts-node ./scripts/postAbbeArticle.ts
Test
npm run test
In order to run the tests with schema validation you need to set the ABBE_URL in your .env.schema-test
-file See .env.schema-test.example
for an example. Make sure to be on VPN and then run:
npm run test:schemaValidation
Release
npm version major/minor/patch
npm publish
git push
git push --tags