Skip to content
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

feat: [GROOT-1550] introduce proposal for fixing update behavior in taxonomy #2469

Merged
merged 2 commits into from
Nov 19, 2024
Merged
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
40 changes: 40 additions & 0 deletions lib/adapters/REST/endpoints/concept-scheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@ export const createWithId: RestEndpoint<'ConceptScheme', 'createWithId'> = (
)
}

export const patch: RestEndpoint<'ConceptScheme', 'patch'> = (
http: AxiosInstance,
params: UpdateConceptSchemeParams,
data: OpPatch[],
headers?: RawAxiosRequestHeaders
) => {
return raw.patch<ConceptSchemeProps>(
http,
`${basePath(params.organizationId)}/${params.conceptSchemeId}`,
data,
{
headers: {
'X-Contentful-Version': params.version,
'Content-Type': 'application/json-patch+json',
...headers,
},
}
)
}

export const update: RestEndpoint<'ConceptScheme', 'update'> = (
http: AxiosInstance,
params: UpdateConceptSchemeParams,
Expand All @@ -89,3 +109,23 @@ export const update: RestEndpoint<'ConceptScheme', 'update'> = (
}
)
}

export const updatePut: RestEndpoint<'ConceptScheme', 'updatePut'> = (
http: AxiosInstance,
params: UpdateConceptSchemeParams,
data: CreateConceptSchemeProps,
headers?: RawAxiosRequestHeaders
) => {
return raw.put<ConceptSchemeProps>(
http,
`${basePath(params.organizationId)}/${params.conceptSchemeId}`,
data,
{
headers: {
'X-Contentful-Version': params.version,
'Content-Type': 'application/json-patch+json',
...headers,
},
}
)
}
42 changes: 41 additions & 1 deletion lib/adapters/REST/endpoints/concept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ export const createWithId: RestEndpoint<'Concept', 'createWithId'> = (
return raw.put<ConceptProps>(http, `${basePath(params.organizationId)}/${params.conceptId}`, data)
}

export const patch: RestEndpoint<'Concept', 'patch'> = (
http: AxiosInstance,
params: UpdateConceptParams,
data: OpPatch[],
headers?: RawAxiosRequestHeaders
) => {
return raw.patch<ConceptProps>(
http,
`${basePath(params.organizationId)}/${params.conceptId}`,
data,
{
headers: {
'X-Contentful-Version': params.version,
'Content-Type': 'application/json-patch+json',
...headers,
},
}
)
}

export const update: RestEndpoint<'Concept', 'update'> = (
http: AxiosInstance,
params: UpdateConceptParams,
Expand All @@ -46,7 +66,27 @@ export const update: RestEndpoint<'Concept', 'update'> = (
data,
{
headers: {
'X-Contentful-Version': params.version ?? 0,
'X-Contentful-Version': params.version,
'Content-Type': 'application/json-patch+json',
...headers,
},
}
)
}

export const updatePut: RestEndpoint<'Concept', 'updatePut'> = (
http: AxiosInstance,
params: UpdateConceptParams,
data: CreateConceptProps,
headers?: RawAxiosRequestHeaders
) => {
return raw.put<ConceptProps>(
http,
`${basePath(params.organizationId)}/${params.conceptId}`,
data,
{
headers: {
'X-Contentful-Version': params.version,
'Content-Type': 'application/json-patch+json',
...headers,
},
Expand Down
24 changes: 24 additions & 0 deletions lib/common-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,15 +458,19 @@ type MRInternal<UA extends boolean> = {
(opts: MROpts<'Concept', 'getDescendants', UA>): MRReturn<'Concept', 'getDescendants'>
(opts: MROpts<'Concept', 'create', UA>): MRReturn<'Concept', 'create'>
(opts: MROpts<'Concept', 'createWithId', UA>): MRReturn<'Concept', 'createWithId'>
(opts: MROpts<'Concept', 'patch', UA>): MRReturn<'Concept', 'patch'>
(opts: MROpts<'Concept', 'update', UA>): MRReturn<'Concept', 'update'>
(opts: MROpts<'Concept', 'updatePut', UA>): MRReturn<'Concept', 'updatePut'>
(opts: MROpts<'Concept', 'delete', UA>): MRReturn<'Concept', 'delete'>

(opts: MROpts<'ConceptScheme', 'get', UA>): MRReturn<'ConceptScheme', 'get'>
(opts: MROpts<'ConceptScheme', 'getMany', UA>): MRReturn<'ConceptScheme', 'getMany'>
(opts: MROpts<'ConceptScheme', 'getTotal', UA>): MRReturn<'ConceptScheme', 'getTotal'>
(opts: MROpts<'ConceptScheme', 'create', UA>): MRReturn<'ConceptScheme', 'create'>
(opts: MROpts<'ConceptScheme', 'createWithId', UA>): MRReturn<'ConceptScheme', 'createWithId'>
(opts: MROpts<'ConceptScheme', 'patch', UA>): MRReturn<'ConceptScheme', 'patch'>
(opts: MROpts<'ConceptScheme', 'update', UA>): MRReturn<'ConceptScheme', 'update'>
(opts: MROpts<'ConceptScheme', 'updatePut', UA>): MRReturn<'ConceptScheme', 'updatePut'>
(opts: MROpts<'ConceptScheme', 'delete', UA>): MRReturn<'ConceptScheme', 'delete'>

(opts: MROpts<'ContentType', 'get', UA>): MRReturn<'ContentType', 'get'>
Expand Down Expand Up @@ -1196,11 +1200,21 @@ export type MRActions = {
payload: CreateConceptProps
return: ConceptProps
}
patch: {
params: UpdateConceptParams
payload: OpPatch[]
return: ConceptProps
}
update: {
params: UpdateConceptParams
payload: OpPatch[]
return: ConceptProps
}
updatePut: {
params: UpdateConceptParams
payload: CreateConceptProps
return: ConceptProps
}
delete: {
params: DeleteConceptParams
return: void
Expand Down Expand Up @@ -1237,11 +1251,21 @@ export type MRActions = {
payload: CreateConceptSchemeProps
return: ConceptSchemeProps
}
patch: {
params: UpdateConceptSchemeParams
payload: OpPatch[]
return: ConceptSchemeProps
}
update: {
params: UpdateConceptSchemeParams
payload: OpPatch[]
return: ConceptSchemeProps
}
updatePut: {
params: UpdateConceptSchemeParams
payload: CreateConceptSchemeProps
return: ConceptSchemeProps
}
get: {
params: GetConceptSchemeParams
return: ConceptSchemeProps
Expand Down
42 changes: 42 additions & 0 deletions lib/plain/entities/concept-scheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@ export type ConceptSchemePlainClientAPI = {
* @returns the updated Concept Scheme
* @throws if the request fails
* @see {@link https://www.contentful.com/developers/docs/references/content-management-api/#/reference/taxonomy/concept-scheme}
* @deprecated The behavior of this method as a PATCH is being deprecated, and will be replaced with a PUT in the next major version. Use the `patch` method instead.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the next major version

how can we make sure we don't forget to update it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw the last time we updated the major version was more than a year ago. long process

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point, but the impression I get from Tundra from our slack thread is that they'll work with us on this as planning for the next version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what just if...

import * as package from 'package.json'

it('should not pass if major version is updated', () => {
  if (package.version.split('.')[0] === 12) {
    expect('updatePut' in sdk).to.be(false)
  }
})

* @example
* ```javascript
* const updatedConcept = await client.conceptScheme.update({
* organizationId: '<organization_id>',
* conceptSchemeId: '<concept_scheme_id>',
* version: 1,
* }, conceptSchemePatch);
* ```
*/
Expand All @@ -63,6 +66,45 @@ export type ConceptSchemePlainClientAPI = {
payload: OpPatch[]
): Promise<ConceptSchemeProps>

/**
* Update Concept Scheme with PUT
* @returns the updated Concept Scheme
* @throws if the request fails
* @see {@link https://www.contentful.com/developers/docs/references/content-management-api/#/reference/taxonomy/concept-scheme}
* @deprecated In the next major version, this method will be replaced with the standard `update` method which will be updated to use PUT instead of PATCH.
* @example
* ```javascript
* const updatedConcept = await client.conceptScheme.update({
* organizationId: '<organization_id>',
* conceptSchemeId: '<concept_scheme_id>',
* version: 1,
* }, CreateConceptSchemeProps);
* ```
*/
updatePut(
params: SetOptional<UpdateConceptSchemeParams, 'organizationId'>,
payload: CreateConceptSchemeProps
): Promise<ConceptSchemeProps>

/**
* Update Concept Scheme
* @returns the updated Concept Scheme
* @throws if the request fails
* @see {@link https://www.contentful.com/developers/docs/references/content-management-api/#/reference/taxonomy/concept-scheme}
* @example
* ```javascript
* const updatedConcept = await client.conceptScheme.patch({
* organizationId: '<organization_id>',
* conceptSchemeId: '<concept_scheme_id>',
* version: 1,
* }, conceptSchemePatch);
* ```
*/
patch(
params: SetOptional<UpdateConceptSchemeParams, 'organizationId'>,
payload: OpPatch[]
): Promise<ConceptSchemeProps>

/**
* Get Concept Scheme
* @returns the Concept Scheme
Expand Down
42 changes: 42 additions & 0 deletions lib/plain/entities/concept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@ export type ConceptPlainClientAPI = {
* @returns the updated Concept
* @throws if the request fails
* @see {@link https://www.contentful.com/developers/docs/references/content-management-api/#/reference/taxonomy/concept}
* @deprecated The behavior of this method as a PATCH is being deprecated, and will be replaced with a PUT in the next major version. Use the `patch` method instead.
* @example
* ```javascript
* const updatedConcept = await client.concept.update({
* organizationId: '<organization_id>',
* conceptId: '<concept_id>',
* version: 1,
* }, patch);
* ```
*/
Expand All @@ -64,6 +67,45 @@ export type ConceptPlainClientAPI = {
payload: OpPatch[]
): Promise<ConceptProps>

/**
* Update Concept with PUT
* @returns the updated Concept
* @throws if the request fails
* @see {@link https://www.contentful.com/developers/docs/references/content-management-api/#/reference/taxonomy/concept}
* @deprecated In the next major version, this method will be replaced with the standard `update` method which will be updated to use PUT instead of PATCH.
* @example
* ```javascript
* const updatedConcept = await client.concept.updatePut({
* organizationId: '<organization_id>',
* conceptId: '<concept_id>',
* version: 1,
* }, patch);
* ```
*/
updatePut(
params: SetOptional<UpdateConceptParams, 'organizationId'>,
payload: CreateConceptProps
): Promise<ConceptProps>

/**
* Update Concept
* @returns the updated Concept
* @throws if the request fails
* @see {@link https://www.contentful.com/developers/docs/references/content-management-api/#/reference/taxonomy/concept}
* @example
* ```javascript
* const updatedConcept = await client.concept.patch({
* organizationId: '<organization_id>',
* conceptId: '<concept_id>',
* version: 1,
* }, patch);
* ```
*/
patch(
params: SetOptional<UpdateConceptParams, 'organizationId'>,
payload: OpPatch[]
): Promise<ConceptProps>

/**
* Get Concept
* @returns the Concept
Expand Down
4 changes: 4 additions & 0 deletions lib/plain/plain-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ export const createPlainClient = (
createWithId: wrap(wrapParams, 'Concept', 'createWithId'),
get: wrap(wrapParams, 'Concept', 'get'),
delete: wrap(wrapParams, 'Concept', 'delete'),
patch: wrap(wrapParams, 'Concept', 'patch'),
update: wrap(wrapParams, 'Concept', 'update'),
updatePut: wrap(wrapParams, 'Concept', 'updatePut'),
getMany: wrap(wrapParams, 'Concept', 'getMany'),
getDescendants: wrap(wrapParams, 'Concept', 'getDescendants'),
getAncestors: wrap(wrapParams, 'Concept', 'getAncestors'),
Expand All @@ -122,7 +124,9 @@ export const createPlainClient = (
delete: wrap(wrapParams, 'ConceptScheme', 'delete'),
create: wrap(wrapParams, 'ConceptScheme', 'create'),
createWithId: wrap(wrapParams, 'ConceptScheme', 'createWithId'),
patch: wrap(wrapParams, 'ConceptScheme', 'patch'),
update: wrap(wrapParams, 'ConceptScheme', 'update'),
updatePut: wrap(wrapParams, 'ConceptScheme', 'updatePut'),
},
function: {
getMany: wrap(wrapParams, 'Function', 'getMany'),
Expand Down
Loading