
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
contentful-space-types
Advanced tools
Generate TypeScript types from your Contentful space/environment.
Generate typings from your Contentful space/environment.
Thanks to and based on the awesome work of the people at Intercom
we use this in our marketing site to increase developer confidence and productivity, ensure that breaking changes to our Content Types don't cause an outage, and because it's neat.
We based our modified version on their work with a bit of modification to suite our use case better and to allow robust configuration in different projects (with minimal configuration possible, and to work flexibly with both Deliver/Management Contentful APIs).
yarn add --dev contentful-space-types
Then, add the following to your package.json:
{
// ...
"scripts": {
...
"generate:types": "contentful-space-types --output src/types/contentful.d.ts",
...
}
}
Feel free to change the output path to whatever you like.
Codegen is shipped with a client that needs the following environment variables to query the contentful preview API and generate the types
CONTENTFUL_SPACE_IDCONTENTFUL_ACCESS_TOKEN content delivery API access tokenCONTENTFUL_MANAGEMENT_ACCESS_TOKEN personal management access tokenCONTENTFUL_ENVIRONMENT defaults to "master" if not providedCONTENTFUL_HOST defaults to "cdn.contentful.com" (the delivery API) if not provided, it can work with Preview
API if "preview.contentful.com" value is used insteadIf the CONTENTFUL_MANAGEMENT_ACCESS_TOKEN is provided, the management client would be used which has
more capabilities than the delivery client.
The management client can query validations and add them to the type-checking. But if it's not provided, we will fall back to the Contentful Delivery/Preview Client that provide less stricter type-checking types.
Usage
$ contentful-typescript-codegen --output <file> <options>
Options
--output, -o Where to write to
--poll, -p Continuously refresh types
--interval N, -i The interval in seconds at which to poll (defaults to 15)
Here's an idea of what the output will look like for a Content Type:
interface IBlogPostFields {
/** Title */
title: string
/** Body */
body: Document
/** Author link */
author: IAuthor
/** Image */
image: Asset
/** Published? */
published: boolean | null
/** Tags */
tags: string[]
/** Blog CTA variant */
ctaVariant: "new-cta" | "old-cta"
}
/**
* A blog post.
*/
export interface IBlogPost extends Entry<IBlogPostFields> {}
You can see that a few things are handled for you:
author, are resolved to other TypeScript interfaces.| null appended to their type.FAQs
Generate TypeScript types from your Contentful space/environment.
We found that contentful-space-types demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.