function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
/**
 * Contentful Management API SDK. Allows you to create instances of a client
 * with access to the Contentful Content Management API.
 * @packageDocumentation
 */

import { getUserAgentHeader } from 'contentful-sdk-core';
import { createAdapter } from './create-adapter';
import createContentfulApi from './create-contentful-api';
import { createPlainClient } from './plain/plain-client';
import * as editorInterfaceDefaults from './constants/editor-interface-defaults';
export { asIterator } from './plain/as-iterator';
export { isDraft, isPublished, isUpdated } from './plain/checks';
export { createClient };
export { RestAdapter } from './adapters/REST/rest-adapter';
export { editorInterfaceDefaults };
export * from './export-types';

/**
 * @deprecated
 */

/**
 * Create a client instance
 * @param params - Client initialization parameters
 *
 * ```javascript
 * const client = contentfulManagement.createClient({
 *  accessToken: 'myAccessToken'
 * })
 * ```
 */

// 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, opts = {}) {
  const sdkMain = opts.type === 'plain' ? 'contentful-management-plain.js' : 'contentful-management.js';
  const userAgent = getUserAgentHeader(
  // @ts-expect-error
  `${sdkMain}/${"11.20.0"}`, params.application, params.integration, params.feature);
  const adapter = createAdapter(_objectSpread(_objectSpread({}, 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 = options => adapter.makeRequest(_objectSpread(_objectSpread({}, options), {}, {
    userAgent
  }));
  if (opts.type === 'plain') {
    return createPlainClient(makeRequest, opts.defaults);
  } else {
    return createContentfulApi(makeRequest);
  }
}