44 * @packageDocumentation
55 */
66
7- import type { AdapterParams } from './create-adapter'
8- import type { ClientAPI } from './create-contentful-api'
9- import type { DefaultParams } from './plain/plain-client'
10- import type { MakeRequest , XOR } from './common-types'
11- import type { PlainClientAPI } from './plain/plain-client-types'
12- import type { RestAdapterParams } from './adapters/REST/rest-adapter'
13-
14- import { createAdapter } from './create-adapter'
15- import { createPlainClient } from './plain/plain-client'
16- import { getUserAgentHeader } from 'contentful-sdk-core'
17- import createContentfulApi from './create-contentful-api'
7+ export type { PlainClientDefaultParams } from './plain/plain-client'
188
199export type { ClientAPI } from './create-contentful-api'
2010export type { PlainClientAPI } from './plain/plain-client-types'
2111export type { RestAdapterParams } from './adapters/REST/rest-adapter'
2212export type * from './export-types'
23- export type PlainClientDefaultParams = DefaultParams
2413
2514export { asIterator } from './plain/as-iterator'
2615export { fetchAll } from './plain/pagination-helper'
@@ -29,106 +18,4 @@ export { makeRequest } from './adapters/REST/make-request'
2918export { RestAdapter } from './adapters/REST/rest-adapter'
3019export * as editorInterfaceDefaults from './constants/editor-interface-defaults/index'
3120
32- interface UserAgentParams {
33- /**
34- * Application name and version e.g myApp/version
35- */
36- application ?: string
37- /**
38- * Integration name and version e.g react/version
39- */
40- integration ?: string
41-
42- feature ?: string
43- }
44-
45- export type ClientOptions = UserAgentParams & XOR < RestAdapterParams , AdapterParams >
46-
47- /**
48- * Create a plain client instance
49- *
50- * @param clientOptions
51- * @param opts
52- *
53- * @example Plain Client
54- * ```javascript
55- * const client = contentfulManagement.createClient({
56- * accessToken: 'myAccessToken',
57- * opts: {
58- * type: 'plain'
59- * }
60- * })
61- * ```
62- * @example Plain Client with defaults
63- * ```javascript
64- * const client = contentfulManagement.createClient({
65- * accessToken: 'myAccessToken',
66- * opts: {
67- * type: 'plain',
68- * defaults: {
69- * ...
70- * }
71- * }
72- * })
73- * ```
74- */
75- function createClient (
76- clientOptions : ClientOptions ,
77- opts : {
78- type : 'plain'
79- defaults ?: DefaultParams
80- }
81- ) : PlainClientAPI
82- /**
83- * Create a legacy, chainable client instance
84- * @param clientOptions
85- *
86- * @example Legacy Chainable Client
87- * ```javascript
88- * const client = contentfulManagement.createClient({
89- * accessToken: 'myAccessToken'
90- * })
91- * ```
92- */
93- function createClient ( clientOptions : ClientOptions ) : ClientAPI
94- /**
95- * Create a legacy or plain client instance
96- *
97- * Please check the responding section below:
98- *
99- * * [Plain Client](#createclient)
100- * * [Legacy Chainable Client](#createclient-1)
101- */
102- function createClient (
103- clientOptions : ClientOptions ,
104- opts ?: {
105- type ?: string
106- defaults ?: DefaultParams
107- }
108- ) : ClientAPI | PlainClientAPI {
109- const sdkMain =
110- opts && opts . type === 'plain' ? 'contentful-management-plain.js' : 'contentful-management.js'
111- const userAgent = getUserAgentHeader (
112- // @ts -expect-error
113- `${ sdkMain } /${ __VERSION__ } ` ,
114- clientOptions . application ,
115- clientOptions . integration ,
116- clientOptions . feature
117- )
118-
119- const adapter = createAdapter ( { ...clientOptions , userAgent } )
120-
121- // Parameters<?> and ReturnType<?> only return the types of the last overload
122- // https://github.com/microsoft/TypeScript/issues/26591
123- // @ts -expect-error
124- const makeRequest : MakeRequest = ( options : Parameters < MakeRequest > [ 0 ] ) : ReturnType < MakeRequest > =>
125- adapter . makeRequest ( { ...options , userAgent } )
126-
127- if ( opts && opts . type === 'plain' ) {
128- return createPlainClient ( makeRequest , opts . defaults )
129- } else {
130- return createContentfulApi ( makeRequest ) as ClientAPI
131- }
132- }
133-
134- export { createClient }
21+ export * from './create-client'
0 commit comments