Skip to content

feat!: deprecate legacy client [NONE] #2317

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 7 additions & 18 deletions lib/contentful-management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,20 @@ function createClient(params: ClientOptions): ClientAPI
function createClient(
params: ClientOptions,
opts: {
type: 'plain'
// type: 'plain'
defaults?: DefaultParams
}
): PlainClientAPI
// 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: ClientOptions,
opts: {
type?: 'plain'
alphaFeatures: string[]
defaults?: DefaultParams
}
): ClientAPI | PlainClientAPI

function createClient(
params: ClientOptions,
opts: {
type?: 'plain'
type?: 'legacy'
defaults?: DefaultParams
} = {}
): ClientAPI | PlainClientAPI {
const sdkMain =
opts.type === 'plain' ? 'contentful-management-plain.js' : 'contentful-management.js'
opts.type === 'legacy' ? 'contentful-management.js' : 'contentful-management-plain.js'
const userAgent = getUserAgentHeader(
// @ts-expect-error
`${sdkMain}/${__VERSION__}`,
Expand All @@ -98,9 +87,9 @@ function createClient(
const makeRequest: MakeRequest = (options: Parameters<MakeRequest>[0]): ReturnType<MakeRequest> =>
adapter.makeRequest({ ...options, userAgent })

if (opts.type === 'plain') {
return createPlainClient(makeRequest, opts.defaults)
} else {
if (opts.type === 'legacy') {
return createContentfulApi(makeRequest) as ClientAPI
} else {
return createPlainClient(makeRequest, opts.defaults)
}
}
6 changes: 6 additions & 0 deletions lib/create-app-definition-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default function createAppDefinitionApi(makeRequest: MakeRequest) {
* .then((appDefinition) => console.log(`App Definition ${appDefinition.sys.id} updated.`))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
update: function update() {
const data = this.toPlainObject() as AppDefinitionProps
Expand Down Expand Up @@ -67,6 +68,7 @@ export default function createAppDefinitionApi(makeRequest: MakeRequest) {
* .then(() => console.log(`App Definition deleted.`))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
delete: function del() {
const data = this.toPlainObject() as AppDefinitionProps
Expand All @@ -93,6 +95,7 @@ export default function createAppDefinitionApi(makeRequest: MakeRequest) {
* .then((appBundle) => console.log(appBundle))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
getAppBundle(id: string) {
const raw = this.toPlainObject() as AppDefinitionProps
Expand Down Expand Up @@ -122,6 +125,7 @@ export default function createAppDefinitionApi(makeRequest: MakeRequest) {
* .then((response) => console.log(response.items))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
getAppBundles(query: QueryOptions = {}) {
const raw = this.toPlainObject() as AppDefinitionProps
Expand All @@ -147,6 +151,7 @@ export default function createAppDefinitionApi(makeRequest: MakeRequest) {
* .then((appBundle) => console.log(appBundle))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
createAppBundle(data: CreateAppBundleProps) {
const raw = this.toPlainObject() as AppDefinitionProps
Expand Down Expand Up @@ -177,6 +182,7 @@ export default function createAppDefinitionApi(makeRequest: MakeRequest) {
* .then((appInstallationsForOrg) => console.log(appInstallationsForOrg.items))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
getInstallationsForOrg(query: SpaceQueryOptions = {}) {
const raw = this.toPlainObject() as AppDefinitionProps
Expand Down
23 changes: 22 additions & 1 deletion lib/create-contentful-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import {
} from './entities/environment-template'
import { RawAxiosRequestConfig } from 'axios'

/**
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
export type ClientAPI = ReturnType<typeof createClientApi>
type CreateSpaceProps = Omit<SpaceProps, 'sys'> & { defaultLocale?: string }

Expand Down Expand Up @@ -58,6 +61,7 @@ export default function createClientApi(makeRequest: MakeRequest) {
* .then((response) => console.log(response.items))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
getEnvironmentTemplates: function getEnvironmentTemplates(
organizationId: string,
Expand Down Expand Up @@ -90,6 +94,7 @@ export default function createClientApi(makeRequest: MakeRequest) {
* .then((space) => console.log(space))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
getEnvironmentTemplate: function getEnvironmentTemplate({
organizationId,
Expand Down Expand Up @@ -127,6 +132,7 @@ export default function createClientApi(makeRequest: MakeRequest) {
* .then((environmentTemplate) => console.log(environmentTemplate))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
createEnvironmentTemplate: function createEnvironmentTemplate(
organizationId: string,
Expand All @@ -153,6 +159,7 @@ export default function createClientApi(makeRequest: MakeRequest) {
* .then((response) => console.log(response.items))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
getSpaces: function getSpaces(
query: QueryOptions = {}
Expand All @@ -179,6 +186,7 @@ export default function createClientApi(makeRequest: MakeRequest) {
* .then((space) => console.log(space))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
getSpace: function getSpace(spaceId: string): Promise<Space> {
return makeRequest({
Expand Down Expand Up @@ -206,6 +214,7 @@ export default function createClientApi(makeRequest: MakeRequest) {
* .then((space) => console.log(space))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
createSpace: function createSpace(
spaceData: CreateSpaceProps,
Expand Down Expand Up @@ -234,6 +243,7 @@ export default function createClientApi(makeRequest: MakeRequest) {
* .then((org) => console.log(org))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
getOrganization: function getOrganization(id: string): Promise<Organization> {
return makeRequest({
Expand All @@ -257,6 +267,7 @@ export default function createClientApi(makeRequest: MakeRequest) {
* .then(result => console.log(result.items))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
getOrganizations: function getOrganizations(
query: PaginationQueryParams['query'] = {}
Expand All @@ -282,6 +293,7 @@ export default function createClientApi(makeRequest: MakeRequest) {
* .then(user => console.log(user.firstName))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
getCurrentUser: function getCurrentUser<T = UserProps>(params?: QueryParams): Promise<T> {
return makeRequest({
Expand All @@ -307,8 +319,8 @@ export default function createClientApi(makeRequest: MakeRequest) {
* .then(appDefinition => console.log(appDefinition.name))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/

getAppDefinition: function getAppDefinition(
params: GetAppDefinitionParams
): Promise<AppDefinition> {
Expand Down Expand Up @@ -341,6 +353,7 @@ export default function createClientApi(makeRequest: MakeRequest) {
* .then(personalAccessToken => console.log(personalAccessToken.token))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
createPersonalAccessToken: function createPersonalAccessToken(
data: CreatePersonalAccessTokenProps
Expand Down Expand Up @@ -374,6 +387,7 @@ export default function createClientApi(makeRequest: MakeRequest) {
* .then(token => console.log(token.token))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
getPersonalAccessToken: function getPersonalAccessToken(tokenId: string) {
return makeRequest({
Expand All @@ -399,6 +413,7 @@ export default function createClientApi(makeRequest: MakeRequest) {
* .then(response => console.log(reponse.items))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
getPersonalAccessTokens: function getPersonalAccessTokens() {
return makeRequest({
Expand All @@ -423,6 +438,7 @@ export default function createClientApi(makeRequest: MakeRequest) {
* .then(token => console.log(token.token))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
getAccessToken: function getAccessToken(tokenId: string) {
return makeRequest({
Expand All @@ -446,6 +462,7 @@ export default function createClientApi(makeRequest: MakeRequest) {
* .then(response => console.log(reponse.items))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
getAccessTokens: function getAccessTokens() {
return makeRequest({
Expand All @@ -470,6 +487,7 @@ export default function createClientApi(makeRequest: MakeRequest) {
* .then(response => console.log(reponse.items))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
getOrganizationAccessTokens: function getOrganizationAccessTokens(
organizationId: string,
Expand Down Expand Up @@ -505,6 +523,7 @@ export default function createClientApi(makeRequest: MakeRequest) {
* .then(result => console.log(result.items))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
getOrganizationUsage: function getOrganizationUsage(
organizationId: string,
Expand Down Expand Up @@ -541,6 +560,7 @@ export default function createClientApi(makeRequest: MakeRequest) {
* .then(result => console.log(result.items))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
getSpaceUsage: function getSpaceUsage(organizationId: string, query: UsageQuery = {}) {
return makeRequest({
Expand Down Expand Up @@ -571,6 +591,7 @@ export default function createClientApi(makeRequest: MakeRequest) {
* .then((responseData) => console.log(responseData))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
rawRequest: function rawRequest({ url, ...config }: RawAxiosRequestConfig & { url: string }) {
return makeRequest({
Expand Down
14 changes: 14 additions & 0 deletions lib/create-entry-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default function createEntryApi(makeRequest: MakeRequest) {
* .then((entry) => console.log(`Entry ${entry.sys.id} updated.`))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
update: function update() {
const { raw, params } = getParams(this)
Expand Down Expand Up @@ -89,6 +90,7 @@ export default function createEntryApi(makeRequest: MakeRequest) {
* .then((entry) => console.log(`Entry ${entry.sys.id} updated.`))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
patch: function patch(ops: OpPatch[]) {
const { raw, params } = getParams(this)
Expand Down Expand Up @@ -145,6 +147,7 @@ export default function createEntryApi(makeRequest: MakeRequest) {
* .then((entry) => console.log(`Entry ${entry.sys.id} published.`))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
publish: function publish() {
const { raw, params } = getParams(this)
Expand Down Expand Up @@ -174,6 +177,7 @@ export default function createEntryApi(makeRequest: MakeRequest) {
* .then((entry) => console.log(`Entry ${entry.sys.id} unpublished.`))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/

unpublish: function unpublish() {
Expand Down Expand Up @@ -203,6 +207,7 @@ export default function createEntryApi(makeRequest: MakeRequest) {
* .then((entry) => console.log(`Entry ${entry.sys.id} archived.`))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
archive: function archive() {
const { params } = getParams(this)
Expand Down Expand Up @@ -231,6 +236,7 @@ export default function createEntryApi(makeRequest: MakeRequest) {
* .then((entry) => console.log(`Entry ${entry.sys.id} unarchived.`))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
unarchive: function unarchive() {
const { params } = getParams(this)
Expand Down Expand Up @@ -258,6 +264,7 @@ export default function createEntryApi(makeRequest: MakeRequest) {
* .then((snapshots) => console.log(snapshots.items))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
getSnapshots: function (query = {}) {
const { params } = getParams(this)
Expand Down Expand Up @@ -286,6 +293,7 @@ export default function createEntryApi(makeRequest: MakeRequest) {
* .then((snapshot) => console.log(snapshot))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
getSnapshot: function (snapshotId: string) {
const { params } = getParams(this)
Expand Down Expand Up @@ -317,6 +325,7 @@ export default function createEntryApi(makeRequest: MakeRequest) {
* .then((comment) => console.log(comment))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
createComment: function (data: CreateCommentProps) {
const { params } = getParams(this)
Expand Down Expand Up @@ -349,6 +358,7 @@ export default function createEntryApi(makeRequest: MakeRequest) {
* .then((comments) => console.log(comments))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
getComments: function () {
const { params } = getParams(this)
Expand All @@ -375,6 +385,7 @@ export default function createEntryApi(makeRequest: MakeRequest) {
* .then((comment) => console.log(comment))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
getComment: function (id: string) {
const { params } = getParams(this)
Expand Down Expand Up @@ -410,6 +421,7 @@ export default function createEntryApi(makeRequest: MakeRequest) {
* .then((task) => console.log(task))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
createTask: function (data: CreateTaskProps) {
const { params } = getParams(this)
Expand Down Expand Up @@ -437,6 +449,7 @@ export default function createEntryApi(makeRequest: MakeRequest) {
* .then((tasks) => console.log(tasks))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
getTasks: function (query = {}) {
const { params } = getParams(this)
Expand All @@ -463,6 +476,7 @@ export default function createEntryApi(makeRequest: MakeRequest) {
* .then((task) => console.log(task))
* .catch(console.error)
* ```
* @deprecated The `old` client is deprecated in favor of the `plain` client since version 12.0.0.
*/
getTask: function (id: string) {
const { params } = getParams(this)
Expand Down
Loading