npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@focus-reactive/contentful-ai-sdk

v0.0.5

Published

Content AI SDK adapter for Contentful

Readme

Contentful AI SDK

Installation

To add the SDK to your project, run the following command:

yarn add @focus-reactive/contentful-ai-sdk

Usage

Initialization

Before using the SDK, you must initialize it with the Contentful client and a valid OpenAI token. In React apps, you can use the useSDK hook from the @contentful/react-apps-toolkit package:

import type { SidebarAppSDK } from '@contentful/app-sdk'
import { useSDK } from '@contentful/react-apps-toolkit'
import { initSDK } from '@focus-reactive/contentful-ai-sdk'
import { useEffect } from 'react'

const LocationComponent = () => {
  const sdk = useSDK<SidebarAppSDK>()

  useEffect(() => {
    initSDK({ client: sdk.cma, openAiKey: process.env.REACT_APP_OPENAI_TOKEN! })
  }, [])

  return ...;
}

export default LocationComponent

Alternatively, you can directly initialize the client via createClient with your access token and pass it to the initSDK function.

Using the SDK

import type { SidebarAppSDK } from '@contentful/app-sdk'\
import { useSDK } from '@contentful/react-apps-toolkit'
import { Form } from '@contentful/f36-components'
import { localize } from '@focus-reactive/contentful-ai-sdk'
import { useForm } from 'react-hook-form'
import { useMutation } from '@tanstack/react-query'

export default function Translate() {
  const sdk = useSDK<SidebarAppSDK>()
  const { handleSubmit } = useForm()

  const { mutate } = useMutation({
    mutationFn: localize,
  })

  const onSubmit = (values) => {
    mutate({
      targetLanguage: values.targetLanguage,
      translationLevel: values.translationLevel,
      entryId: sdk.entry.getSys().id,
      localEntryId: values.local,
      globalEntryId: values.global,
    })
  }

  return (
    <Form onSubmit={handleSubmit(onSubmit)}>
      ...
    </Form>
  )
}

API

localize

Translate the fields of an entry to the target language. The field values in the default locale will be used as the source. It can be used for both field-level and entry-level localizations.

Parameters

type LocalizeFieldsProps = {
  translationLevel: 'field';
  targetLanguage: string;
  entryId: string;
};

type LocalizeEntryProps = {
  translationLevel: 'entry';
  targetLanguage: string;
  localEntryId: string;
  globalEntryId: string;
};

type LocalizeProps = LocalizeFieldsProps | LocalizeEntryProps;
  • targetLanguage - language (or locale) to which you want to translate your entry. Available locales must be configured in space settings.
  • translationLevel - which localization level to use.
    • field - add target localization to the current entry
      • entryId - ID of the entry that you want to translate.
    • entry - create a new entry with translated values stored in the default locale and link the global entry (container) with the newly created entry
      • localEntryId - ID of the entry that will be used as a data source.
      • globalEntryId - ID of the entry that will be used as a container for the newly created entry.

Return

Promise<void>

resolveEntries

Identify global and local entries based on whether a given entry refers to any other entries or is being referenced.

Parameters

  • entryId - ID of the entry

Return

{ global: RecognizedEntry; local: RecognizedEntry }, where RecognizedEntry is an object with the following structure:

type RecognizedEntry = {
  id: string;
  name: string;
  contentType: { id: string; name: string };
} | null

If entry is isolated (no references), { global: null, local: entry } will be returned.

findTags

Find the most relevant tags for the entry's content from the space's configured tags.

Parameters

  • entryId - ID of the entry
  • contentTitle - content title for more context

Return

An array of tags, where each tag is an object with the following structure:

type Tag = {
  id: string
  title: string
}

applyTags

Apply tags (with overwrite) to the given entry

Parameters

  • entryId - ID of the entry
  • tags - Array of objects with id property, where id is the ID of the tag

Return

Promise<void>