Skip to content

Commit

Permalink
feat: [GROOT-1550] add support for taxonomy PUT methods (#2464)
Browse files Browse the repository at this point in the history
* feat: [GROOT-1550] add support for taxonomy PUT methods

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

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

* chore: [GROOT-1550] remove default version for taxonomy updates

* fix: [GROOT-1550] remove patch header from taxonomy put method
  • Loading branch information
LiamStokingerContentful authored Nov 21, 2024
1 parent 3e51f79 commit da65d62
Show file tree
Hide file tree
Showing 9 changed files with 536 additions and 1 deletion.
51 changes: 51 additions & 0 deletions lib/adapters/REST/endpoints/concept-scheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,38 @@ export const create: RestEndpoint<'ConceptScheme', 'create'> = (
return raw.post<ConceptSchemeProps>(http, basePath(params.organizationId), data)
}

export const createWithId: RestEndpoint<'ConceptScheme', 'createWithId'> = (
http: AxiosInstance,
params: GetConceptSchemeParams,
data: CreateConceptSchemeProps
) => {
return raw.put<ConceptSchemeProps>(
http,
`${basePath(params.organizationId)}/${params.conceptSchemeId}`,
data
)
}

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 @@ -77,3 +109,22 @@ 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,
...headers,
},
}
)
}
49 changes: 48 additions & 1 deletion lib/adapters/REST/endpoints/concept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,34 @@ export const create: RestEndpoint<'Concept', 'create'> = (
return raw.post<ConceptProps>(http, basePath(params.organizationId), data)
}

export const createWithId: RestEndpoint<'Concept', 'createWithId'> = (
http: AxiosInstance,
params: GetConceptParams,
data: CreateConceptProps
) => {
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 @@ -38,14 +66,33 @@ 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,
...headers,
},
}
)
}

export const get: RestEndpoint<'Concept', 'get'> = (
http: AxiosInstance,
params: GetConceptParams
Expand Down
36 changes: 36 additions & 0 deletions lib/common-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,20 @@ type MRInternal<UA extends boolean> = {
(opts: MROpts<'Concept', 'getTotal', UA>): MRReturn<'Concept', 'getTotal'>
(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 @@ -1194,11 +1200,26 @@ export type MRActions = {
payload: CreateConceptProps
return: ConceptProps
}
createWithId: {
params: GetConceptParams
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 @@ -1230,11 +1251,26 @@ export type MRActions = {
payload: CreateConceptSchemeProps
return: ConceptSchemeProps
}
createWithId: {
params: GetConceptSchemeParams
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
60 changes: 60 additions & 0 deletions lib/plain/entities/concept-scheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,36 @@ export type ConceptSchemePlainClientAPI = {
payload: CreateConceptSchemeProps
): Promise<ConceptSchemeProps>

/**
* Create Concept Scheme With Id
* @returns the created Concept Scheme
* @throws if the request fails
* @see {@link https://www.contentful.com/developers/docs/references/content-management-api/#/reference/taxonomy/create-a-concept-scheme-with-user-defined-id}
* @example
* ```javascript
* const concept = await client.conceptScheme.createWithId({
* organizationId: '<organization_id>',
* conceptSchemeId: '<concept_scheme_id>',
* }, conceptSchemeProps);
* ```
*/
createWithId(
params: SetOptional<GetConceptSchemeParams, '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}
* @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.conceptScheme.update({
* organizationId: '<organization_id>',
* conceptSchemeId: '<concept_scheme_id>',
* version: 1,
* }, conceptSchemePatch);
* ```
*/
Expand All @@ -45,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
60 changes: 60 additions & 0 deletions lib/plain/entities/concept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,36 @@ export type ConceptPlainClientAPI = {
payload: CreateConceptProps
): Promise<ConceptProps>

/**
* Create Concept With Id
* @returns ConceptProps
* @throws if the request fails
* @see {@link https://www.contentful.com/developers/docs/references/content-management-api/#/reference/taxonomy/create-a-concept-with-user-defined-id}
* @example
* ```javascript
* const concept = await client.concept.createWithId({
* organizationId: '<organization_id>',
* conceptId: '<concept_id>',
* }, conceptProps);
* ```
*/
createWithId(
params: SetOptional<GetConceptParams, '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}
* @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 @@ -46,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
6 changes: 6 additions & 0 deletions lib/plain/plain-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@ export const createPlainClient = (
},
concept: {
create: wrap(wrapParams, 'Concept', 'create'),
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 @@ -120,7 +123,10 @@ export const createPlainClient = (
getTotal: wrap(wrapParams, 'ConceptScheme', 'getTotal'),
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

0 comments on commit da65d62

Please sign in to comment.