Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
30b498a
fix: upgrade typedoc, include missing types and plenty of tsdoc fixes
axe312ger Feb 28, 2025
eec3064
dx: simplify doc scripts to essentials
axe312ger Mar 20, 2025
3153cce
refactor: further improving and cleaning up typedocs config
axe312ger Mar 20, 2025
e12b6de
refactor: use @returns instead of @return to match typedocs standard
axe312ger Mar 20, 2025
c9081f5
Merge branch 'master' into refactor/docs
axe312ger Apr 14, 2025
8e024ce
Merge branch 'master' into refactor/docs
axe312ger Apr 24, 2025
0980259
refactor: remove index file in entities folder for cleaner import str…
axe312ger Mar 25, 2025
b9d6dfa
refactor: ensure export types are really only used to export types
axe312ger Mar 25, 2025
72ed3f5
refactor: rename plain/common-types to actually describe what the fil…
axe312ger Mar 25, 2025
cbe77a4
fix: remove confusing outdated ClientParams type and finally export t…
axe312ger Mar 25, 2025
c633bbe
refactor: clean up messy imports and exports in main file - many cook…
axe312ger Mar 25, 2025
59ae491
chore: reinstall to clean up package.json and lock file
axe312ger Mar 25, 2025
38d9914
refactor: rename params to clientOptions in createClient function to …
axe312ger Mar 25, 2025
c5454cd
refactor: remove deprecated, unsupported and unused alphaFeatures
axe312ger Mar 25, 2025
54fcffa
refactor: clean up createClient overloads, add examples for each way …
axe312ger Mar 25, 2025
7afe777
docs: README - clearer distinction between plain and legacy client, h…
axe312ger Mar 27, 2025
5363aca
Refactor/restructure and improve docs (#2592)
axe312ger Apr 24, 2025
c7c3d93
fix: move type-fest to a regular dependency
axe312ger Apr 29, 2025
ffe8500
docs: set link to changelog to github releases page
axe312ger Apr 29, 2025
81f6f67
docs: prever ESM syntax over CommonJS
axe312ger Apr 29, 2025
7abf4ba
docs: remove broken link to runkit
axe312ger Apr 29, 2025
9727036
docs: remove unnesessary mention of version 1.0.0
axe312ger Apr 29, 2025
3621ffa
docs: remove unnesessary colons in node and browser headline
axe312ger Apr 29, 2025
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: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<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="https://github.com/contentful/contentful-management.js/releases">Changelog</a> ·
<a href="CONTRIBUTING.md">Contributing</a>
</p>

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<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="https://github.com/contentful/contentful-management.js/releases">Changelog</a> ·
<a href="CONTRIBUTING.md">Contributing</a>
</p>

Expand Down
251 changes: 113 additions & 138 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<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="https://github.com/contentful/contentful-management.js/releases">Changelog</a> ·
<a href="CONTRIBUTING.md">Contributing</a>
</p>

Expand Down
15 changes: 10 additions & 5 deletions lib/adapters/REST/endpoints/access-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import * as raw from './raw'
* @param {Object} params - Parameters for the request.
* @param {string} params.tokenId - The unique token ID of the access token to retrieve.
* @returns {Promise<AccessTokenProps>} A Promise that resolves with the retrieved access token information.
* @example ```javascript
* @example
* ```javascript
* const contentful = require('contentful-management')
*
* const plainClient = contentful.createClient(
Expand All @@ -42,7 +43,8 @@ export const get: RestEndpoint<'AccessToken', 'get'> = (
* @param {AxiosInstance} http - An Axios HTTP client instance.
* @param {QueryParams} params - Query parameters to filter and customize the request.
* @returns {Promise<CollectionProp<AccessTokenProps>>} A Promise that resolves with a collection of access token properties.
* @example ```javascript
* @example
* ```javascript
* const contentful = require('contentful-management')
*
* const plainClient = contentful.createClient(
Expand Down Expand Up @@ -73,7 +75,8 @@ export const getMany: RestEndpoint<'AccessToken', 'getMany'> = (
* @param {CreatePersonalAccessTokenProps} rawData - Data for creating the personal access token.
* @param {RawAxiosRequestHeaders} [headers] - Optional HTTP headers for the request.
* @returns {Promise<AccessTokenProps>} A Promise that resolves with the created personal access token.
* @example ```javascript
* @example
* ```javascript
* const contentful = require('contentful-management')
*
* const plainClient = contentful.createClient(
Expand Down Expand Up @@ -105,7 +108,8 @@ export const createPersonalAccessToken: RestEndpoint<'AccessToken', 'createPerso
* @param {Object} params - The parameters for revoking the access token.
* @param {string} params.tokenId - The unique identifier of the access token to revoke.
* @returns {Promise<AccessTokenProps>} A Promise that resolves with the updated access token information after revocation.
* @example ```javascript
* @example
* ```javascript
* const contentful = require('contentful-management')
*
* const plainClient = contentful.createClient(
Expand Down Expand Up @@ -133,7 +137,8 @@ export const revoke: RestEndpoint<'AccessToken', 'revoke'> = (
* @param {GetOrganizationParams & QueryParams} params - Parameters for the request, including organization ID and query parameters.
* @param {string} params.organizationId - The unique identifier of the organization.
* @returns {Promise<CollectionProp<AccessTokenProps>>} A promise that resolves to a collection of access tokens.
* @example ```javascript
* @example
* ```javascript
* const contentful = require('contentful-management')
*
* const plainClient = contentful.createClient(
Expand Down
15 changes: 10 additions & 5 deletions lib/adapters/REST/endpoints/oauth-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import type {
* @param {string} params.userId - The unique user ID of the user.
* @param {string} params.oauthApplicationId - The unique application ID of the OAuth application.
* @returns {Promise<OAuthApplicationProps>} A Promise that resolves with the retrieved OAuth Application.
* @example ```javascript
* @example
* ```javascript
* const contentful = require('contentful-management')
*
* const plainClient = contentful.createClient(
Expand Down Expand Up @@ -54,7 +55,8 @@ export const get: RestEndpoint<'OAuthApplication', 'get'> = (
* @param {string} params.userId - The unique user ID of the user.
* @param {QueryParams} params - Query parameters to filter and customize the request.
* @returns {Promise<CursorPaginatedCollectionProp<OAuthApplicationProps>>} A Promise that resolves with a collection of oauth application properties.
* @example ```javascript
* @example
* ```javascript
* const contentful = require('contentful-management')
*
* const plainClient = contentful.createClient(
Expand Down Expand Up @@ -89,7 +91,8 @@ export const getManyForUser: RestEndpoint<'OAuthApplication', 'getManyForUser'>
* @param {string} params.userId - The unique user ID of the user.
* @param {RawAxiosRequestHeaders} [headers] - Optional HTTP headers for the request.
* @returns {Promise<OAuthApplicationProps>} A Promise that resolves with the created oauth application.
* @example ```javascript
* @example
* ```javascript
* const contentful = require('contentful-management')
*
* const plainClient = contentful.createClient(
Expand Down Expand Up @@ -130,7 +133,8 @@ export const create: RestEndpoint<'OAuthApplication', 'create'> = (
* @param {string} params.userId - The unique user ID of the user.
* @param {string} params.oauthApplicationId - The unique application ID of the OAuth application.
* @returns {Promise<OAuthApplicationProps>} A Promise that resolves with the updated oauth application.
* @example ```javascript
* @example
* ```javascript
* const contentful = require('contentful-management')
*
* const plainClient = contentful.createClient(
Expand Down Expand Up @@ -171,7 +175,8 @@ export const update: RestEndpoint<'OAuthApplication', 'update'> = (
* @param {string} params.userId - The unique user ID of the user.
* @param {string} params.oauthApplicationId - The unique application ID of the OAuth application.
* @returns {Promise<void>}
* @example ```javascript
* @example
* ```javascript
* const contentful = require('contentful-management')
*
* const plainClient = contentful.createClient(
Expand Down
2 changes: 1 addition & 1 deletion lib/adapters/REST/make-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { AxiosInstance } from 'contentful-sdk-core'
import type { MakeRequestOptions, MakeRequestPayload } from '../../common-types'
import type { OpPatch } from 'json-patch'
import type { RawAxiosRequestHeaders } from 'axios'
import endpoints from './endpoints'
import endpoints from './endpoints/index'

type makeAxiosRequest = MakeRequestOptions & {
axiosInstance: AxiosInstance
Expand Down
19 changes: 9 additions & 10 deletions lib/common-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */

import { toPlainObject } from 'contentful-sdk-core'
import copy from 'fast-copy'
import type {
Expand All @@ -17,10 +15,11 @@ export const wrapCollection =
<R, T, Rest extends any[]>(fn: (makeRequest: MakeRequest, entity: T, ...rest: Rest) => R) =>
(makeRequest: MakeRequest, data: CollectionProp<T>, ...rest: Rest): Collection<R, T> => {
const collectionData = toPlainObject(copy(data))
// @ts-expect-error
collectionData.items = collectionData.items.map((entity) => fn(makeRequest, entity, ...rest))
// @ts-expect-error
return collectionData

return {
...collectionData,
items: collectionData.items.map((entity) => fn(makeRequest, entity, ...rest)),
}
}

export const wrapCursorPaginatedCollection =
Expand All @@ -31,10 +30,10 @@ export const wrapCursorPaginatedCollection =
...rest: Rest
): CursorPaginatedCollection<R, T> => {
const collectionData = toPlainObject(copy(data))
// @ts-expect-error
collectionData.items = collectionData.items.map((entity) => fn(makeRequest, entity, ...rest))
// @ts-expect-error
return collectionData
return {
...collectionData,
items: collectionData.items.map((entity) => fn(makeRequest, entity, ...rest)),
}
}
export function isSuccessful(statusCode: number) {
return statusCode < 300
Expand Down
107 changes: 8 additions & 99 deletions lib/contentful-management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,109 +4,18 @@
* @packageDocumentation
*/

import { getUserAgentHeader } from 'contentful-sdk-core'
import type { RestAdapterParams } from './adapters/REST/rest-adapter'
import type { MakeRequest, XOR } from './common-types'
import type { AdapterParams } from './create-adapter'
import { createAdapter } from './create-adapter'
import type { ClientAPI } from './create-contentful-api'
import createContentfulApi from './create-contentful-api'
import type { PlainClientAPI } from './plain/common-types'
import type { DefaultParams } from './plain/plain-client'
import { createPlainClient } from './plain/plain-client'
import * as editorInterfaceDefaults from './constants/editor-interface-defaults'
export type { PlainClientDefaultParams } from './plain/plain-client'

export type { ClientAPI } from './create-contentful-api'
export type { PlainClientAPI } from './plain/plain-client-types'
export type { RestAdapterParams } from './adapters/REST/rest-adapter'
export type * from './export-types'

export { asIterator } from './plain/as-iterator'
export { fetchAll } from './plain/pagination-helper'
export { isDraft, isPublished, isUpdated } from './plain/checks'
export type { PlainClientAPI } from './plain/common-types'
export { createClient }
export { RestAdapter } from './adapters/REST/rest-adapter'
export type { RestAdapterParams } from './adapters/REST/rest-adapter'
export { makeRequest } from './adapters/REST/make-request'
export { editorInterfaceDefaults }
export type PlainClientDefaultParams = DefaultParams
export * from './export-types'

interface UserAgentParams {
/**
* Application name and version e.g myApp/version
*/
application?: string
/**
* Integration name and version e.g react/version
*/
integration?: string

feature?: string
}

/**
* @deprecated
*/
export type ClientParams = RestAdapterParams & UserAgentParams

export type ClientOptions = UserAgentParams & XOR<RestAdapterParams, AdapterParams>

/**
* Create a client instance
* @param params - Client initialization parameters
*
* ```javascript
* const client = contentfulManagement.createClient({
* accessToken: 'myAccessToken'
* })
* ```
*/
function createClient(params: ClientOptions): ClientAPI
function createClient(
params: ClientOptions,
opts: {
type: 'plain'
defaults?: DefaultParams
}
): PlainClientAPI
// Usually, overloads with more specific signatures should come first but some IDEs are often not able to handle overloads with separate TSDocs correctly
/**
* @deprecated The `alphaFeatures` option is no longer supported. Please use the function without this option.
*/
function createClient(
params: ClientOptions,
opts: {
type?: 'plain'
alphaFeatures: string[]
defaults?: DefaultParams
}
): ClientAPI | PlainClientAPI
function createClient(
params: ClientOptions,
opts: {
type?: 'plain'
defaults?: DefaultParams
} = {}
): ClientAPI | PlainClientAPI {
const sdkMain =
opts.type === 'plain' ? 'contentful-management-plain.js' : 'contentful-management.js'
const userAgent = getUserAgentHeader(
// @ts-expect-error
`${sdkMain}/${__VERSION__}`,
params.application,
params.integration,
params.feature
)

const adapter = createAdapter({ ...params, userAgent })

// Parameters<?> and ReturnType<?> only return the types of the last overload
// https://github.com/microsoft/TypeScript/issues/26591
// @ts-expect-error
const makeRequest: MakeRequest = (options: Parameters<MakeRequest>[0]): ReturnType<MakeRequest> =>
adapter.makeRequest({ ...options, userAgent })
export { RestAdapter } from './adapters/REST/rest-adapter'
export * as editorInterfaceDefaults from './constants/editor-interface-defaults/index'

if (opts.type === 'plain') {
return createPlainClient(makeRequest, opts.defaults)
} else {
return createContentfulApi(makeRequest) as ClientAPI
}
}
export * from './create-client'
Loading