Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@kontent-ai/delivery-sdk

Package Overview
Dependencies
Maintainers
3
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kontent-ai/delivery-sdk - npm Package Versions

234

15.2.0

Diff

Changelog

Source

15.2.0 (2024-09-27)

Features

  • exports optional 'Snippet' type used for strongly typed modelling (96ef2d5)
enngage
published 15.1.1 •

Changelog

Source

15.1.1 (2024-09-27)

Bug Fixes

  • re-exports IContentItemElements type (ddc570f)
enngage
published 15.1.0 •

Changelog

Source

15.1.0 (2024-09-26)

Features

  • Adds support for constraining item element properties using pre-defined codenames type (c7b16b7)
  • updates deps (03fdc22)
enngage
published 15.0.0 •

Changelog

Source

15.0.0 (2024-09-16)

Features

enngage
published 15.0.0-0 •

Changelog

Source

15.0.0-0 (2024-09-10)

⚠ BREAKING CHANGES

  • Removes parser & rich text resolver. To work with RTE use the newer and better @kontent-ai/rich-text-resolver library instead.
  • Removes propertyName resolver configuration. All elements are now referenced only by their codenames present in Kontent.ai

Features

  • Adds narrowing types for Taxonomy & Multiple choice elements (3118752)
  • Adds optional generic types to IContentItem narrowing down available values of system attributes (8c894af)
  • Makes RichTextElement take generic parameter narrowing down allowed types of linked items (68b31a8)
  • Removes propertyName resolver configuration. All elements are now referenced only by their codenames present in Kontent.ai (7ef5951)
  • Removes parser & rich text resolver. To work with RTE use the newer and better @kontent-ai/rich-text-resolver library instead. (2bd30c3)
  • updates deps (82c2c11)

Upgrading to new RTE parser

In < 15.0.0 versions of this SDK you were able to resolve RTE elements like this:

import { createRichTextHtmlResolver, createDeliveryClient, linkedItemsHelper } from '@kontent-ai/delivery-sdk';

export type Movie = IContentItem<{
    plot: Elements.RichTextElement;
}>;

export type Actor = IContentItem<{
    firstName: Elements.RichTextElement;
}>;

// get content item with rich text element
const response = (
    await createDeliveryClient({ environmentId: '<YOUR_ENVIRONMENT_ID>' }).item<Movie>('itemCodename').toPromise()
).data;

// get rich text element
const richTextElement = response.item.plot;

// resolve HTML
const resolvedRichText = createRichTextHtmlResolver().resolveRichText({
    element: richTextElement,
    linkedItems: linkedItemsHelper.convertLinkedItemsToArray(response.data.linkedItems),
    imageResolver: (imageId, image) => {
        return {
            imageHtml: `<img class="xImage" src="${image?.url}">`,
            // alternatively you may return just url
            imageUrl: 'customUrl'
        };
    },
    urlResolver: (linkId, linkText, link) => {
        return {
            linkHtml: `<a class="xLink">${link?.link?.urlSlug}</a>`,
            // alternatively you may return just url
            linkUrl: 'customUrl'
        };
    },
    contentItemResolver: (itemId, contentItem) => {
        if (contentItem && contentItem.system.type === 'actor') {
            const actor = contentItem as Actor;
            return {
                contentItemHtml: `<div class="xClass">${actor.elements.firstName.value}</div>`
            };
        }

        return {
            contentItemHtml: ''
        };
    }
});

const resolvedHtml = resolvedRichText.html;

But since this resolver is now removed in >= 15.0.0 you need to resolve RTE using the @kontent-ai/rich-text-resolver package:

import { createDeliveryClient, Elements, IContentItem } from '@kontent-ai/delivery-sdk';
import { PortableTextOptions, toHTML } from '@portabletext/to-html';
import { nodeParse, transformToPortableText, resolveTable, resolveImage } from '@kontent-ai/rich-text-resolver';

type Movie = IContentItem<{
    title: Elements.TextElement;
    plot: Elements.RichTextElement<Actor>;
}>;

type Actor = IContentItem<{
    first_name: Elements.RichTextElement;
}>;

const itemResponse = await createDeliveryClient({
    environmentId: 'da5abe9f-fdad-4168-97cd-b3464be2ccb9'
})
    .item<Movie>('warrior')
    .toPromise();

const richTextElement = itemResponse.data.item.elements.plot;

const linkedItems = Object.values(itemResponse.data.linkedItems);
const parsedTree = nodeParse(richTextElement.value);
const portableText = transformToPortableText(parsedTree);

const portableTextComponents: PortableTextOptions = {
    components: {
        types: {
            image: ({ value }) => {
                return resolveImage(value, (image) => {
                    return `<img class="xImage" src="${image.asset.url}">`;
                });
            },
            component: ({ value }) => {
                const linkedItem = linkedItems.find((item) => item.system.codename === value.component._ref);
                switch (linkedItem?.system.type) {
                    case 'actor': {
                        const actor = linkedItem as Actor;
                        return `<div class="xClass">${actor.elements.first_name.value}</div>`;
                    }
                    default: {
                        return `Resolver for type ${linkedItem?.system.type} not implemented.`;
                    }
                }
            },
            table: ({ value }) => {
                // default impl
                return resolveTable(value, toHTML);
            }
        },
        marks: {
            internalLink: ({ children, value }) => {
                return `<a class="xLink" href="https://yourdomain.com/actor/${value.reference._ref}">${children}</a>`;
            }
        }
    }
};

const resolvedHtml = toHTML(portableText, portableTextComponents);
enngage
published 14.11.0 •

Changelog

Source

14.11.0 (2024-08-15)

Features

  • updates deps (& fixes Axios vulnerability), updates eslint config (ba49770)
enngage
published 14.10.0 •

Changelog

Source

14.10.0 (2024-06-28)

Features

enngage
published 14.9.0 •

Changelog

Source

14.9.0 (2024-04-29)

Features

enngage
published 14.8.0 •

Changelog

Source

14.8.0 (2024-03-06)

Features

  • adds support for 'excludeElements' parameter (fixes https://github.com/kontent-ai/delivery-sdk-js/issues/389) (64a2b17)
  • updates deps, adds clean script, updates engine version to >= v18 (6135b03)
enngage
published 14.7.0 •

Changelog

Source

14.7.0 (2024-02-29)

Features

  • updates deps (and fixes https://github.com/kontent-ai/delivery-sdk-js/issues/387) (4d9df4b)

Bug Fixes

  • escapes codenames to prevent collisions with javascript constructs (fixes https://github.com/kontent-ai/delivery-sdk-js/issues/388) (c5ea589)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc