UNPKG

contentful-management

Version:
39 lines (36 loc) 2.24 kB
import { getUserAgentHeader } from 'contentful-sdk-core'; import { createAdapter } from './create-adapter.mjs'; import createClientApi from './create-contentful-api.mjs'; import { createPlainClient } from './plain/plain-client.mjs'; import * as index from './constants/editor-interface-defaults/index.mjs'; export { index as editorInterfaceDefaults }; export { ScheduledActionStatus } from './entities/scheduled-action.mjs'; export { asIterator } from './plain/as-iterator.mjs'; export { fetchAll } from './plain/pagination-helper.mjs'; export { isDraft, isPublished, isUpdated } from './plain/checks.mjs'; export { RestAdapter } from './adapters/REST/rest-adapter.mjs'; export { makeRequest } from './adapters/REST/make-request.mjs'; /** * 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.mjs.map