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

@scayle/storefront-cms-contentful

v1.0.0

Published

Contentful CMS provider integration for the SCAYLE Storefront Application V3

Readme

@scayle/storefront-cms-contentful

Contentful CMS provider integration for the SCAYLE Storefront Application V3.

Requires Storefront Application V3. This package implements CMSProviderService from @scayle/storefront. Controllers resolve the constructed provider from the ServiceRegistry and call fetchPageData/fetchListingPageData directly. It has no standalone use outside a Storefront Application V3 project.

Package entrypoint

| Export | Use | | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ContentfulCMSService | CMSProviderService implementation. Generic over your generated Contentful content-type shape (TPageData), defaulting to MinimalContentfulPageData so the package builds standalone. Manages delivery and preview API clients. | | MinimalContentfulPageData | Minimal interface for the { entry, previewSource? } page payload envelope the service produces. | | isUnconfiguredLocaleError | Predicate identifying a Contentful BadRequest "Unknown locale" error, used for the locale-fallback retry. | | cspConfig | CMSCspConfig for the Contentful web app: iframe embedding, editor scripts, Live Preview worker, and API connect rules. |

See Contentful's Content Delivery API documentation and the contentful SDK docs for the underlying client.

Configuration

ContentfulCMSService requires four configuration fields. The Storefront Application reads these from environment variables via getRequiredEnv (or, for draftContentEnabled, a bare process.env read since it has a default) in src/server/cms/providers/contentful/service.ts. See .env.example for the variable names.

| Field | Required | Purpose | Tenant setup location | Documentation | | --------------------- | -------- | --------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------- | | accessToken | Yes | Content Delivery API access token used to authenticate published-content requests | Settings → API keys → select or create an API key → copy the Content Delivery API - access token field | Authentication | | space | Yes | Contentful space ID that identifies the CMS workspace | Settings → API keys → shown in the list, or Settings → General settings → space ID field | API keys | | previewAccessToken | Yes | Content Preview API access token used to authenticate draft-content requests | Settings → API keys → select or create an API key → copy the Content Preview API - access token field | Authentication | | draftContentEnabled | Yes | Whether draft/unpublished content may be served during an editor session | Set via the storefront's own STOREFRONT_CMS_ALLOW_DRAFTS environment variable, not a Contentful setting | — |

These values map to environment variables as CONTENTFUL_CMS_ACCESS_TOKEN, CONTENTFUL_CMS_SPACE, CONTENTFUL_CMS_PREVIEW_ACCESS_TOKEN, and STOREFRONT_CMS_ALLOW_DRAFTS respectively.

Usage

The Storefront Application instantiates ContentfulCMSService directly in src/server/cms/providers/contentful/service.ts and binds TPageData to its generated CMSPageData type:

import { ContentfulCMSService } from '@scayle/storefront-cms-contentful'
import type { CMSPageData } from '@shared/types/cms/contentful'

export const createCMSService = (storefront: StorefrontContext) =>
  new ContentfulCMSService<CMSPageData>(
    {
      accessToken: getRequiredEnv('CONTENTFUL_CMS_ACCESS_TOKEN'),
      space: getRequiredEnv('CONTENTFUL_CMS_SPACE'),
      previewAccessToken: getRequiredEnv('CONTENTFUL_CMS_PREVIEW_ACCESS_TOKEN'),
      draftContentEnabled:
        process.env.STOREFRONT_CMS_ALLOW_DRAFTS?.toLowerCase() === 'true',
    },
    storefront,
  )

The storefront context is used for the service's own application-level caching.

The Storefront Application registers createCMSService(storefront) as the cms slot on the ServiceRegistry (src/server/registries.ts), alongside every other domain. A controller resolves it from there and calls fetchPageData/fetchListingPageData with this.request (the inbound IncomingRequest):

const pageData = await this.services.cms.fetchPageData(slug, this.request)

See @scayle/storefront's CMS module for the CMSProviderService contract this package implements.

Architecture

ContentfulCMSService implements CMSProviderService directly — there is no shared base class. Each provider package owns its own caching, error handling, and constructor validation, so this package can diverge from Storyblok/Contentstack without a @scayle/storefront release touching them:

  • fetchPageData and fetchListingPageData wrap the raw fetch with application-level caching (context.cache.getOrSet(...), 5-minute TTL, bypassed entirely in preview mode) under the cache-key patterns cms:contentful:page:${slug}:${locale} and cms:contentful:plp:${categoryId}:${locale}. The raw fetches query Contentful's PageComponent and productListingPageComponent content types by fields.slug, retrying once without a locale filter when Contentful reports the requested locale is unconfigured in the space (the retry happens inside the cached fetch, so it's still cached once under the originally requested locale's key). fetchListingPageData also converts a CMSContentNotFoundError into undefined, and rethrows any other error for the caller to log. The query itself comes from buildPageQuery/buildListingQuery, and the response shape from transformPageResponse, both protected so a subclass can override just one without touching the retry or 404 handling around them.
  • Two lazily initialized static singleton clients: a delivery client for published content and a preview client (using CONTENTFUL_CMS_PREVIEW_ACCESS_TOKEN) for draft content, selected per request based on the request's editor-mode state combined with draftContentEnabled. Both go through @scayle/storefront/cms's wrapClientInit, so a bad space ID or token fails with a message naming the client and the env var to check, not a bare SDK error.
  • Preview responses run through contentful-resolve-response to resolve linked entries that the preview API otherwise returns unresolved.
  • isEditorMode detects Contentful's live preview via the _editorMode query parameter.

Extending and customizing

In your project, all customization happens in the Storefront Application's src/server/cms/providers/contentful/service.ts, by subclassing ContentfulCMSService. The class is concrete, so a project that needs no change uses it as is:

  • Query shape: override buildPageQuery(slug, locale) or buildListingQuery(slug, locale) to query a different content type or field name than the default PageComponent / fields.slug shape, without touching client selection, locale-fallback retry, or 404 handling.
  • Response shape: override transformPageResponse(response, useDraftContent) to keep additional response fields beyond what the default extraction produces.
  • CSP rules: re-export a modified cspConfig (imported from this package as a base) if your Contentful space uses a different domain or needs additional directives.

Do not reimplement fetchPageData or fetchListingPageData from scratch. Override only the method that needs to change and call super for everything else, so your subclass tracks fixes made to this package.