Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ permissions:
on:
push:
branches: ['**']
pull_request:
branches: ['**']

jobs:
build:
Expand Down
52 changes: 42 additions & 10 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
run: |
git config --global user.name 'contentful-automation[bot]'
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+contentful-automation[bot]@users.noreply.github.com'

- name: Checkout code
uses: actions/checkout@v5
with:
Expand Down Expand Up @@ -72,14 +72,6 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish Docs
if: github.event_name == 'push' && contains(fromJSON('["refs/heads/master"]'), github.ref)
run: |
echo "Publishing Documentation"
npm run docs:publish
env:
GITHUB_TOKEN: ${{ steps.vault.outputs.GITHUB_TOKEN }}

- name: Get latest release tag
id: get-tag
run: |
Expand All @@ -88,10 +80,50 @@ jobs:
env:
GITHUB_TOKEN: ${{ steps.vault.outputs.GITHUB_TOKEN }}

- name: Publish Docs
run: |
VERSION=$(echo "${{ steps.get-tag.outputs.tag }}" | sed 's/^v//')
NAMESPACE="contentful-management"
REPO_URL="https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git"
PAGES_URL="https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}"

echo "Publishing docs for v${VERSION}..."
DOCS_BASE_URL="${PAGES_URL}/${NAMESPACE}/latest/" npm run docs:build

PAGES_DIR=$(mktemp -d)
git clone --single-branch --branch gh-pages "$REPO_URL" "$PAGES_DIR"

mkdir -p "$PAGES_DIR/$NAMESPACE/$VERSION"
cp -r ./out/* "$PAGES_DIR/$NAMESPACE/$VERSION/"
rm -rf "$PAGES_DIR/$NAMESPACE/latest"
cp -r "$PAGES_DIR/$NAMESPACE/$VERSION" "$PAGES_DIR/$NAMESPACE/latest"

# Generate versions.json from existing version directories
ls -d "$PAGES_DIR/$NAMESPACE"/*/ 2>/dev/null \
| xargs -I{} basename {} \
| grep -v latest \
| sort -rV \
| jq -R . | jq -s '["latest"] + .' \
> "$PAGES_DIR/$NAMESPACE/versions.json"

# Root redirect
echo "<meta http-equiv=\"refresh\" content=\"0; url=${NAMESPACE}/latest/\">" \
> "$PAGES_DIR/index.html"

cd "$PAGES_DIR"
git add .
git commit -m "docs: publish v${VERSION} [skip ci]" || echo "No changes to commit"
git push origin gh-pages
rm -rf "$PAGES_DIR"

echo "Docs published to ${PAGES_URL}/${NAMESPACE}/latest/"
env:
GITHUB_TOKEN: ${{ steps.vault.outputs.GITHUB_TOKEN }}

- name: Summary
run: |
VERSION=$(echo "${{ steps.get-tag.outputs.tag }}" | sed 's/^v//')
echo "## Release Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Version**: ${{ steps.get-tag.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
echo "- **GitHub Release**: https://github.com/${{ github.repository }}/releases/tag/${{ steps.get-tag.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
echo "- **GitHub Release**: https://github.com/${{ github.repository }}/releases/tag/${{ steps.get-tag.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dist
gh-pages
webpack-build-log.json

# Esdoc dirs
# TypeDoc output
out
gh-pages

Expand Down
44 changes: 15 additions & 29 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,53 +34,39 @@ It also explains what to do in case you want to setup the project locally and ru

# Setup

This project is written in ES2015 and transpiled to ES5 using Babel, to the `dist` directory. This should generally only happen at publishing time, or for testing purposes only.
This project is written in TypeScript. Sources live in `lib/` and are bundled to `dist/` (ESM, CJS, types, browser) using Rollup.

Run `npm install` to install all necessary dependencies. When running `npm install` locally, `dist` is not compiled.
Run `npm install` to install all necessary dependencies. All tools can be accessed via npm scripts — there is no need to install anything globally.

All necessary dependencies are installed under `node_modules` and any necessary tools can be accessed via npm scripts. There is no need to install anything globally.

When importing local, in development code, via `index.js`, this file checks if `dist` exists and uses that. Otherwise, it uses the code from `lib`.

If you have a `dist` directory, run `npm run clean`.

Axios, one of the main dependencies is vendored. This generally shouldn't matter, but if you'd like to understand why, check [SETUP.md](SETUP.md)
If you have a `dist` directory from a previous build, run `npm run clean`.

# Code style

This project uses [standard](https://github.com/feross/standard). Install a relevant editor plugin if you'd like.
This project uses ESLint and Prettier. Run `npm run lint` to check and `npm run prettier:write` to format.

Everywhere where it isn't applicable, follow a style similar to the existing code.
Follow a style similar to the existing code.

# Commit messages and issues

This project uses the [Angular JS Commit Message Conventions](https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit), via semantic-release. See the semantic-release [Default Commit Message Format](https://github.com/semantic-release/semantic-release#default-commit-message-format) section for more details.

# Running tests

This project has unit and integration tests. Both of these run on both Node.js and Browser environments.

Both of these test environments are setup to deal with Babel and code transpiling, so there's no need to worry about that
This project has unit, type, and integration tests, powered by Vitest.

- `npm test` runs all three kinds of tests and generates a coverage report
- `npm run test:unit` runs Node.js unit tests without coverage. `npm run test:cover` to run Node.js unit tests with coverage. `npm run test:debug` runs babel-node in debug mode (same as running `node debug`). In order to see an output of the tests in the terminal run `npm run test:unit-watch`.
- `npm run test:integration` runs the integration tests against the Contentful CDA API. Note: these are tricky to run locally since they currently run against a real contentful org. Focus on unit tests during development as integration tests will be run as part of CI/CD.
- `npm run test:browser` runs both the unit and integration tests using Karma against local browsers.
- `npm run test:ci` runs tests in CI
- `npm run test:browser-remote` runs both the unit and integration tests using Karma against Sauce Labs. This is only usable in the CI environment, as it expects the credentials and connection tunnel to be present.
- `npm test` runs the full test suite (unit + types + integration + size)
- `npx vitest --project unit --run` runs unit tests
- `npx vitest --project types --run` runs type tests
- `npm run test:integration` runs integration tests against the Contentful CMA API. These run against a real Contentful org, so focus on unit tests during development — integration tests run as part of CI/CD.

# Documentation

Code is documented using Typedoc, and reference documentation is published automatically with each new version.
Code is documented using [TypeDoc](https://typedoc.org/), and reference documentation is published automatically to GitHub Pages with each release.

- `npm run docs:watch` watches code directory, and rebuilds documentation when anything changes. Useful for documentation writing and development.
- `npm run docs:dev` builds code and builds docs afterwards. Used by `npm run docs:watch`. Code building is required as the documentation is generated from the unminified ES5 compiled sources, rather than the original ES6 sources. You should then open the generated `out/index.html` in your browser.
- `npm run build:docs` builds documentation.
- `npm run docs:publish` builds documentation and publishes it to github pages.
- `npm run docs:build` generates documentation into `out/`
- `npm run docs:dev` builds documentation in watch mode

# Other tasks

- `npm run clean` removes any built files
- `npm run build` builds vendored files, node package and browser version
- `npm run build:dist` builds ES5 sources from ES6 ones
- `npm run build:standalone` builds unminified and minified sources for browsers
- `npm run clean` removes built files
- `npm run build` builds all bundles (ESM, CJS, types, browser) via Rollup
44 changes: 17 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
<h3 align="center">JavaScript</h3>

<p align="center">
<a href="README.md">Readme</a> ·
<a href="SETUP.md">Setup</a> ·
<a href="MIGRATION.md">Migration</a> ·
<a href="CHANGELOG.md">Changelog</a> ·
<a href="CONTRIBUTING.md">Contributing</a> ·
<a href="SUPPORT.md">Support Policy</a>
<a href="README.md">Readme</a> ·
<a href="SETUP.md">Setup</a> ·
<a href="CHANGELOG.md">Changelog</a> ·
<a href="CONTRIBUTING.md">Contributing</a>
</p>

<p align="center">
Expand All @@ -43,27 +41,25 @@

<!-- TOC -->

- [Features](#features)
- [Supported Environments](#supported-environments)
- [Getting Started](#getting-started)
- [Getting started](#getting-started)
- [Installation](#installation)
- [Node](#node)
- [Browser](#browser-bundle-in-script-tag)
- [Typings](#typings)
- [Node:](#node)
- [Browser bundle in script tag:](#browser-bundle-in-script-tag)
- [Typings](#typings)
- [Authentication](#authentication)
- [Using ES6 import](#using-es6-import)
- [Your first Request](#your-first-request)
- [Using CommonJS require imports](#using-commonjs-require-imports)
- [Your first request](#your-first-request)
- [Legacy Client Interface](#legacy-client-interface)
- [App Framework](#app-framework)
- [Troubleshooting](#troubleshooting)
- [Documentation/References](#documentationreferences)
- [App Framework](#app-framework)
- [Troubleshooting](#troubleshooting)
- [Documentation/References](#documentationreferences)
- [Configuration](#configuration)
- [Reference Documentation](#reference-documentation)
- [Contentful Javascript resources](#contentful-javascript-resources)
- [Cursor Based Pagination](#cursor-based-pagination)
- [REST API reference](#rest-api-reference)
- [Versioning](#versioning)
- [Support Policy](#support-policy)
- [Reach out to us](#reach-out-to-us)
- [Get involved](#get-involved)
- [License](#license)
Expand Down Expand Up @@ -173,7 +169,7 @@ You can use the commonjs require with the library as follows

```js
// import createClient directly
const contentful = require('contentful-management');
const contentful = require('contentful-management')
const client = contentful.createClient({
// This is the access token for this space. Normally you get the token in the Contentful web app
accessToken: 'YOUR_ACCESS_TOKEN',
Expand Down Expand Up @@ -226,8 +222,8 @@ const entries = await scopedClient.entry.getMany({
},
})
```
You can try and change the above example on [Runkit](https://npm.runkit.com/contentful-management).

You can try and change the above example on [Runkit](https://npm.runkit.com/contentful-management).

The benefits of the default client are:

Expand Down Expand Up @@ -463,15 +459,9 @@ In addition, there may be some experimental features in the main build of this S

### Current experimental features

- **AI Agents**: The Agent and Agent Run APIs (`getAgent`, `getAgents`, `getAgentRun`, `getAgentRuns`, `generateWithAgent`, `resumeAgentRun`) are experimental and subject to breaking changes without notice.
- **AI Agents**: The Agent and Agent Run APIs (`getAgent`, `getAgents`, `getAgentRun`, `getAgentRuns`, `generateWithAgent`) are experimental and subject to breaking changes without notice.
- **Component Types**: The Component Type `getMany` endpoint (`componentType.getMany`) is experimental and subject to breaking changes without notice.

## Support Policy

When a new major version is released, the previous major version enters a **6-month maintenance period** during which only critical bug fixes and security patches are provided. After this period, previous versions reach end-of-life and no longer receive updates.

For full details, see our [Support and Maintenance Policy](SUPPORT.md).

## Reach out to us

### You have questions about how to use this library?
Expand Down
40 changes: 0 additions & 40 deletions SUPPORT.md

This file was deleted.

34 changes: 34 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: Getting Started
category: Core
---

# Getting Started

## Plain Client (Recommended)

The plain client provides flat, Promise-based access to all CMA endpoints:

```typescript
import { createClient } from 'contentful-management'

const client = createClient({ accessToken: 'YOUR_ACCESS_TOKEN' })

const entries = await client.entry.getMany({
spaceId: '<space_id>',
environmentId: '<environment_id>',
})
```

See {@link plain/plain-client-types!PlainClientAPI | PlainClientAPI} for the full API reference.

## Legacy Client (Deprecated)

The legacy client uses a nested, chained interface:

```typescript
const client = createClient({ accessToken: 'YOUR_ACCESS_TOKEN' }, { type: 'plain' })
// This returns a ClientAPI instance — see createClientApi
```

See [createClientApi](../create-contentful-api/default) for the full legacy API reference.
30 changes: 30 additions & 0 deletions docs/plugins/version-selector/typedoc-version-selector.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { readFileSync } from 'node:fs'
import { resolve, dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
import { JSX } from 'typedoc'

const __dirname = dirname(fileURLToPath(import.meta.url))
const css = readFileSync(resolve(__dirname, 'version-selector.css'), 'utf-8')
const js = readFileSync(resolve(__dirname, 'version-selector.js'), 'utf-8')

/**
* TypeDoc plugin that injects a version selector dropdown at the top of the
* left sidebar.
*
* At runtime in the browser, the dropdown fetches `versions.json` from the docs
* root (generated by the CI deploy workflow) and lets users switch between
* published documentation versions.
*
* The CSS and JS are kept in separate files (`version-selector.css` and
* `version-selector.js`) for readability, and read at build time.
*
* @param {import('typedoc').Application} app
*/
export function load(app) {
app.renderer.hooks.on('head.end', () => {
return JSX.createElement(JSX.Fragment, null, [
JSX.createElement('style', null, [JSX.createElement(JSX.Raw, { html: css })]),
JSX.createElement('script', null, [JSX.createElement(JSX.Raw, { html: js })]),
])
})
}
Loading
Loading