UNPKG

contentful-management

Version:
39 lines (36 loc) 2.23 kB
import { getUserAgentHeader } from 'contentful-sdk-core'; import { createAdapter } from './create-adapter.js'; import createClientApi from './create-contentful-api.js'; import { createPlainClient } from './plain/plain-client.js'; import * as index from './constants/editor-interface-defaults/index.js'; export { index as editorInterfaceDefaults }; export { ScheduledActionStatus } from './entities/scheduled-action.js'; export { asIterator } from './plain/as-iterator.js'; export { fetchAll } from './plain/pagination-helper.js'; export { isDraft, isPublished, isUpdated } from './plain/checks.js'; export { RestAdapter } from './adapters/REST/rest-adapter.js'; export { makeRequest } from './adapters/REST/make-request.js'; /** * Contentful Management API SDK. Allows you to create instances of a client * with access to the Contentful Content Management API. * @packageDocumentation */ // Usually, overloads with more specific signatures should come first but some IDEs are often not able to handle overloads with separate TSDocs correctly function createClient(clientOptions, opts = {}) { const sdkMain = opts.type === 'legacy' ? 'contentful-management.js' : 'contentful-management-plain.js'; const userAgent = getUserAgentHeader( // @ts-expect-error "0.0.0-determined-by-semantic-release" is injected by rollup at build time `${sdkMain}/${"0.0.0-determined-by-semantic-release"}`, clientOptions.application, clientOptions.integration, clientOptions.feature); const adapter = createAdapter({ ...clientOptions, userAgent }); // @ts-expect-error Parameters<?> and ReturnType<?> only return the types of the last overload (https://github.com/microsoft/TypeScript/issues/26591) const makeRequest = (options) => adapter.makeRequest({ ...options, userAgent }); if (opts.type === 'legacy') { console.warn('[contentful-management] The nested (legacy) client is deprecated and will be removed in the next major version. Please migrate to the plain client. See the README for migration guidance.'); return createClientApi(makeRequest); } else { return createPlainClient(makeRequest, opts.defaults); } } export { createClient }; //# sourceMappingURL=index.js.map