-
Notifications
You must be signed in to change notification settings - Fork 97
Refactor: clean up what many devs left untouched (improves DX) #2588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
axe312ger
wants to merge
17
commits into
refactor/docs
Choose a base branch
from
refactor/restructure-to-simplify-and-reduce-circular-dependencies
base: refactor/docs
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0980259
refactor: remove index file in entities folder for cleaner import str…
axe312ger b9d6dfa
refactor: ensure export types are really only used to export types
axe312ger 72ed3f5
refactor: rename plain/common-types to actually describe what the fil…
axe312ger cbe77a4
fix: remove confusing outdated ClientParams type and finally export t…
axe312ger c633bbe
refactor: clean up messy imports and exports in main file - many cook…
axe312ger 59ae491
chore: reinstall to clean up package.json and lock file
axe312ger 38d9914
refactor: rename params to clientOptions in createClient function to …
axe312ger c5454cd
refactor: remove deprecated, unsupported and unused alphaFeatures
axe312ger 54fcffa
refactor: clean up createClient overloads, add examples for each way …
axe312ger 7afe777
docs: README - clearer distinction between plain and legacy client, h…
axe312ger 5363aca
Refactor/restructure and improve docs (#2592)
axe312ger c7c3d93
fix: move type-fest to a regular dependency
axe312ger ffe8500
docs: set link to changelog to github releases page
axe312ger 81f6f67
docs: prever ESM syntax over CommonJS
axe312ger 7abf4ba
docs: remove broken link to runkit
axe312ger 9727036
docs: remove unnesessary mention of version 1.0.0
axe312ger 3621ffa
docs: remove unnesessary colons in node and browser headline
axe312ger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/** | ||
* Navigate below to the `createClient` function to get started with using this library. | ||
* @module | ||
* @category Core | ||
*/ | ||
import type { AdapterParams } from './create-adapter' | ||
import type { ClientAPI } from './create-contentful-api' | ||
import type { PlainClientDefaultParams } from './plain/plain-client' | ||
import type { MakeRequest, XOR } from './common-types' | ||
import type { PlainClientAPI } from './plain/plain-client-types' | ||
import type { RestAdapterParams } from './adapters/REST/rest-adapter' | ||
|
||
import { createAdapter } from './create-adapter' | ||
import { createPlainClient } from './plain/plain-client' | ||
import { getUserAgentHeader } from 'contentful-sdk-core' | ||
import { createClientApi } from './create-contentful-api' | ||
|
||
interface UserAgentParams { | ||
/** | ||
* Application name and version e.g myApp/version | ||
*/ | ||
application?: string | ||
/** | ||
* Integration name and version e.g react/version | ||
*/ | ||
integration?: string | ||
|
||
feature?: string | ||
} | ||
|
||
export type ClientOptions = UserAgentParams & XOR<RestAdapterParams, AdapterParams> | ||
|
||
declare global { | ||
const __VERSION__: string | ||
} | ||
|
||
/** | ||
* Create a plain client instance | ||
* | ||
* @param clientOptions | ||
* @param opts | ||
* | ||
* @example Plain Client | ||
* ```javascript | ||
* const client = contentfulManagement.createClient({ | ||
* accessToken: 'myAccessToken', | ||
* opts: { | ||
* type: 'plain' | ||
* } | ||
* }) | ||
* ``` | ||
* @example Plain Client with defaults | ||
* ```javascript | ||
* const client = contentfulManagement.createClient({ | ||
* accessToken: 'myAccessToken', | ||
* opts: { | ||
* type: 'plain', | ||
* defaults: { | ||
* ... | ||
* } | ||
* } | ||
* }) | ||
* ``` | ||
*/ | ||
export function createClient( | ||
clientOptions: ClientOptions, | ||
opts: { | ||
type: 'plain' | ||
defaults?: PlainClientDefaultParams | ||
} | ||
): PlainClientAPI | ||
/** | ||
* Create a legacy, chainable client instance | ||
* @param clientOptions | ||
* | ||
* @example Legacy Chainable Client | ||
* ```javascript | ||
* const client = contentfulManagement.createClient({ | ||
* accessToken: 'myAccessToken' | ||
* }) | ||
* ``` | ||
*/ | ||
export function createClient(clientOptions: ClientOptions): ClientAPI | ||
/** | ||
* Create a legacy or plain client instance | ||
* | ||
* Please check the corresponding section below: | ||
* | ||
* * [Plain Client](#createclient) | ||
* * [Legacy Chainable Client](#createclient-1) | ||
*/ | ||
export function createClient( | ||
clientOptions: ClientOptions, | ||
opts?: { | ||
type?: string | ||
defaults?: PlainClientDefaultParams | ||
} | ||
): ClientAPI | PlainClientAPI { | ||
const sdkMain = | ||
opts && opts.type === 'plain' ? 'contentful-management-plain.js' : 'contentful-management.js' | ||
const userAgent = getUserAgentHeader( | ||
`${sdkMain}/${__VERSION__}`, | ||
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: MakeRequest = (options: Parameters<MakeRequest>[0]): ReturnType<MakeRequest> => | ||
adapter.makeRequest({ ...options, userAgent }) | ||
|
||
if (opts && opts.type === 'plain') { | ||
return createPlainClient(makeRequest, opts.defaults) | ||
} else { | ||
return createClientApi(makeRequest) as ClientAPI | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is already labeled as deprecated, do you think this is safe to remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, as these are used by the legacy client.
The whole legacy vs plain client situation should be adressed by us soon IMHO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@whitelisab so i checked, this is a left over from ages ago and just confuses people. so lets get rid of it! The real config types for plain and legacy client are available for our users