Skip to content

Commit da65d62

Browse files
feat: [GROOT-1550] add support for taxonomy PUT methods (#2464)
* 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
1 parent 3e51f79 commit da65d62

File tree

9 files changed

+536
-1
lines changed

9 files changed

+536
-1
lines changed

lib/adapters/REST/endpoints/concept-scheme.ts

+51
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,38 @@ export const create: RestEndpoint<'ConceptScheme', 'create'> = (
5858
return raw.post<ConceptSchemeProps>(http, basePath(params.organizationId), data)
5959
}
6060

61+
export const createWithId: RestEndpoint<'ConceptScheme', 'createWithId'> = (
62+
http: AxiosInstance,
63+
params: GetConceptSchemeParams,
64+
data: CreateConceptSchemeProps
65+
) => {
66+
return raw.put<ConceptSchemeProps>(
67+
http,
68+
`${basePath(params.organizationId)}/${params.conceptSchemeId}`,
69+
data
70+
)
71+
}
72+
73+
export const patch: RestEndpoint<'ConceptScheme', 'patch'> = (
74+
http: AxiosInstance,
75+
params: UpdateConceptSchemeParams,
76+
data: OpPatch[],
77+
headers?: RawAxiosRequestHeaders
78+
) => {
79+
return raw.patch<ConceptSchemeProps>(
80+
http,
81+
`${basePath(params.organizationId)}/${params.conceptSchemeId}`,
82+
data,
83+
{
84+
headers: {
85+
'X-Contentful-Version': params.version,
86+
'Content-Type': 'application/json-patch+json',
87+
...headers,
88+
},
89+
}
90+
)
91+
}
92+
6193
export const update: RestEndpoint<'ConceptScheme', 'update'> = (
6294
http: AxiosInstance,
6395
params: UpdateConceptSchemeParams,
@@ -77,3 +109,22 @@ export const update: RestEndpoint<'ConceptScheme', 'update'> = (
77109
}
78110
)
79111
}
112+
113+
export const updatePut: RestEndpoint<'ConceptScheme', 'updatePut'> = (
114+
http: AxiosInstance,
115+
params: UpdateConceptSchemeParams,
116+
data: CreateConceptSchemeProps,
117+
headers?: RawAxiosRequestHeaders
118+
) => {
119+
return raw.put<ConceptSchemeProps>(
120+
http,
121+
`${basePath(params.organizationId)}/${params.conceptSchemeId}`,
122+
data,
123+
{
124+
headers: {
125+
'X-Contentful-Version': params.version,
126+
...headers,
127+
},
128+
}
129+
)
130+
}

lib/adapters/REST/endpoints/concept.ts

+48-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,34 @@ export const create: RestEndpoint<'Concept', 'create'> = (
2626
return raw.post<ConceptProps>(http, basePath(params.organizationId), data)
2727
}
2828

29+
export const createWithId: RestEndpoint<'Concept', 'createWithId'> = (
30+
http: AxiosInstance,
31+
params: GetConceptParams,
32+
data: CreateConceptProps
33+
) => {
34+
return raw.put<ConceptProps>(http, `${basePath(params.organizationId)}/${params.conceptId}`, data)
35+
}
36+
37+
export const patch: RestEndpoint<'Concept', 'patch'> = (
38+
http: AxiosInstance,
39+
params: UpdateConceptParams,
40+
data: OpPatch[],
41+
headers?: RawAxiosRequestHeaders
42+
) => {
43+
return raw.patch<ConceptProps>(
44+
http,
45+
`${basePath(params.organizationId)}/${params.conceptId}`,
46+
data,
47+
{
48+
headers: {
49+
'X-Contentful-Version': params.version,
50+
'Content-Type': 'application/json-patch+json',
51+
...headers,
52+
},
53+
}
54+
)
55+
}
56+
2957
export const update: RestEndpoint<'Concept', 'update'> = (
3058
http: AxiosInstance,
3159
params: UpdateConceptParams,
@@ -38,14 +66,33 @@ export const update: RestEndpoint<'Concept', 'update'> = (
3866
data,
3967
{
4068
headers: {
41-
'X-Contentful-Version': params.version ?? 0,
69+
'X-Contentful-Version': params.version,
4270
'Content-Type': 'application/json-patch+json',
4371
...headers,
4472
},
4573
}
4674
)
4775
}
4876

77+
export const updatePut: RestEndpoint<'Concept', 'updatePut'> = (
78+
http: AxiosInstance,
79+
params: UpdateConceptParams,
80+
data: CreateConceptProps,
81+
headers?: RawAxiosRequestHeaders
82+
) => {
83+
return raw.put<ConceptProps>(
84+
http,
85+
`${basePath(params.organizationId)}/${params.conceptId}`,
86+
data,
87+
{
88+
headers: {
89+
'X-Contentful-Version': params.version,
90+
...headers,
91+
},
92+
}
93+
)
94+
}
95+
4996
export const get: RestEndpoint<'Concept', 'get'> = (
5097
http: AxiosInstance,
5198
params: GetConceptParams

lib/common-types.ts

+36
Original file line numberDiff line numberDiff line change
@@ -460,14 +460,20 @@ type MRInternal<UA extends boolean> = {
460460
(opts: MROpts<'Concept', 'getTotal', UA>): MRReturn<'Concept', 'getTotal'>
461461
(opts: MROpts<'Concept', 'getDescendants', UA>): MRReturn<'Concept', 'getDescendants'>
462462
(opts: MROpts<'Concept', 'create', UA>): MRReturn<'Concept', 'create'>
463+
(opts: MROpts<'Concept', 'createWithId', UA>): MRReturn<'Concept', 'createWithId'>
464+
(opts: MROpts<'Concept', 'patch', UA>): MRReturn<'Concept', 'patch'>
463465
(opts: MROpts<'Concept', 'update', UA>): MRReturn<'Concept', 'update'>
466+
(opts: MROpts<'Concept', 'updatePut', UA>): MRReturn<'Concept', 'updatePut'>
464467
(opts: MROpts<'Concept', 'delete', UA>): MRReturn<'Concept', 'delete'>
465468

466469
(opts: MROpts<'ConceptScheme', 'get', UA>): MRReturn<'ConceptScheme', 'get'>
467470
(opts: MROpts<'ConceptScheme', 'getMany', UA>): MRReturn<'ConceptScheme', 'getMany'>
468471
(opts: MROpts<'ConceptScheme', 'getTotal', UA>): MRReturn<'ConceptScheme', 'getTotal'>
469472
(opts: MROpts<'ConceptScheme', 'create', UA>): MRReturn<'ConceptScheme', 'create'>
473+
(opts: MROpts<'ConceptScheme', 'createWithId', UA>): MRReturn<'ConceptScheme', 'createWithId'>
474+
(opts: MROpts<'ConceptScheme', 'patch', UA>): MRReturn<'ConceptScheme', 'patch'>
470475
(opts: MROpts<'ConceptScheme', 'update', UA>): MRReturn<'ConceptScheme', 'update'>
476+
(opts: MROpts<'ConceptScheme', 'updatePut', UA>): MRReturn<'ConceptScheme', 'updatePut'>
471477
(opts: MROpts<'ConceptScheme', 'delete', UA>): MRReturn<'ConceptScheme', 'delete'>
472478

473479
(opts: MROpts<'ContentType', 'get', UA>): MRReturn<'ContentType', 'get'>
@@ -1194,11 +1200,26 @@ export type MRActions = {
11941200
payload: CreateConceptProps
11951201
return: ConceptProps
11961202
}
1203+
createWithId: {
1204+
params: GetConceptParams
1205+
payload: CreateConceptProps
1206+
return: ConceptProps
1207+
}
1208+
patch: {
1209+
params: UpdateConceptParams
1210+
payload: OpPatch[]
1211+
return: ConceptProps
1212+
}
11971213
update: {
11981214
params: UpdateConceptParams
11991215
payload: OpPatch[]
12001216
return: ConceptProps
12011217
}
1218+
updatePut: {
1219+
params: UpdateConceptParams
1220+
payload: CreateConceptProps
1221+
return: ConceptProps
1222+
}
12021223
delete: {
12031224
params: DeleteConceptParams
12041225
return: void
@@ -1230,11 +1251,26 @@ export type MRActions = {
12301251
payload: CreateConceptSchemeProps
12311252
return: ConceptSchemeProps
12321253
}
1254+
createWithId: {
1255+
params: GetConceptSchemeParams
1256+
payload: CreateConceptSchemeProps
1257+
return: ConceptSchemeProps
1258+
}
1259+
patch: {
1260+
params: UpdateConceptSchemeParams
1261+
payload: OpPatch[]
1262+
return: ConceptSchemeProps
1263+
}
12331264
update: {
12341265
params: UpdateConceptSchemeParams
12351266
payload: OpPatch[]
12361267
return: ConceptSchemeProps
12371268
}
1269+
updatePut: {
1270+
params: UpdateConceptSchemeParams
1271+
payload: CreateConceptSchemeProps
1272+
return: ConceptSchemeProps
1273+
}
12381274
get: {
12391275
params: GetConceptSchemeParams
12401276
return: ConceptSchemeProps

lib/plain/entities/concept-scheme.ts

+60
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,36 @@ export type ConceptSchemePlainClientAPI = {
2828
payload: CreateConceptSchemeProps
2929
): Promise<ConceptSchemeProps>
3030

31+
/**
32+
* Create Concept Scheme With Id
33+
* @returns the created Concept Scheme
34+
* @throws if the request fails
35+
* @see {@link https://www.contentful.com/developers/docs/references/content-management-api/#/reference/taxonomy/create-a-concept-scheme-with-user-defined-id}
36+
* @example
37+
* ```javascript
38+
* const concept = await client.conceptScheme.createWithId({
39+
* organizationId: '<organization_id>',
40+
* conceptSchemeId: '<concept_scheme_id>',
41+
* }, conceptSchemeProps);
42+
* ```
43+
*/
44+
createWithId(
45+
params: SetOptional<GetConceptSchemeParams, 'organizationId'>,
46+
payload: CreateConceptSchemeProps
47+
): Promise<ConceptSchemeProps>
48+
3149
/**
3250
* Update Concept Scheme
3351
* @returns the updated Concept Scheme
3452
* @throws if the request fails
3553
* @see {@link https://www.contentful.com/developers/docs/references/content-management-api/#/reference/taxonomy/concept-scheme}
54+
* @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.
3655
* @example
3756
* ```javascript
3857
* const updatedConcept = await client.conceptScheme.update({
3958
* organizationId: '<organization_id>',
59+
* conceptSchemeId: '<concept_scheme_id>',
60+
* version: 1,
4061
* }, conceptSchemePatch);
4162
* ```
4263
*/
@@ -45,6 +66,45 @@ export type ConceptSchemePlainClientAPI = {
4566
payload: OpPatch[]
4667
): Promise<ConceptSchemeProps>
4768

69+
/**
70+
* Update Concept Scheme with PUT
71+
* @returns the updated Concept Scheme
72+
* @throws if the request fails
73+
* @see {@link https://www.contentful.com/developers/docs/references/content-management-api/#/reference/taxonomy/concept-scheme}
74+
* @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.
75+
* @example
76+
* ```javascript
77+
* const updatedConcept = await client.conceptScheme.update({
78+
* organizationId: '<organization_id>',
79+
* conceptSchemeId: '<concept_scheme_id>',
80+
* version: 1,
81+
* }, CreateConceptSchemeProps);
82+
* ```
83+
*/
84+
updatePut(
85+
params: SetOptional<UpdateConceptSchemeParams, 'organizationId'>,
86+
payload: CreateConceptSchemeProps
87+
): Promise<ConceptSchemeProps>
88+
89+
/**
90+
* Update Concept Scheme
91+
* @returns the updated Concept Scheme
92+
* @throws if the request fails
93+
* @see {@link https://www.contentful.com/developers/docs/references/content-management-api/#/reference/taxonomy/concept-scheme}
94+
* @example
95+
* ```javascript
96+
* const updatedConcept = await client.conceptScheme.patch({
97+
* organizationId: '<organization_id>',
98+
* conceptSchemeId: '<concept_scheme_id>',
99+
* version: 1,
100+
* }, conceptSchemePatch);
101+
* ```
102+
*/
103+
patch(
104+
params: SetOptional<UpdateConceptSchemeParams, 'organizationId'>,
105+
payload: OpPatch[]
106+
): Promise<ConceptSchemeProps>
107+
48108
/**
49109
* Get Concept Scheme
50110
* @returns the Concept Scheme

lib/plain/entities/concept.ts

+60
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,36 @@ export type ConceptPlainClientAPI = {
2929
payload: CreateConceptProps
3030
): Promise<ConceptProps>
3131

32+
/**
33+
* Create Concept With Id
34+
* @returns ConceptProps
35+
* @throws if the request fails
36+
* @see {@link https://www.contentful.com/developers/docs/references/content-management-api/#/reference/taxonomy/create-a-concept-with-user-defined-id}
37+
* @example
38+
* ```javascript
39+
* const concept = await client.concept.createWithId({
40+
* organizationId: '<organization_id>',
41+
* conceptId: '<concept_id>',
42+
* }, conceptProps);
43+
* ```
44+
*/
45+
createWithId(
46+
params: SetOptional<GetConceptParams, 'organizationId'>,
47+
payload: CreateConceptProps
48+
): Promise<ConceptProps>
49+
3250
/**
3351
* Update Concept
3452
* @returns the updated Concept
3553
* @throws if the request fails
3654
* @see {@link https://www.contentful.com/developers/docs/references/content-management-api/#/reference/taxonomy/concept}
55+
* @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.
3756
* @example
3857
* ```javascript
3958
* const updatedConcept = await client.concept.update({
4059
* organizationId: '<organization_id>',
60+
* conceptId: '<concept_id>',
61+
* version: 1,
4162
* }, patch);
4263
* ```
4364
*/
@@ -46,6 +67,45 @@ export type ConceptPlainClientAPI = {
4667
payload: OpPatch[]
4768
): Promise<ConceptProps>
4869

70+
/**
71+
* Update Concept with PUT
72+
* @returns the updated Concept
73+
* @throws if the request fails
74+
* @see {@link https://www.contentful.com/developers/docs/references/content-management-api/#/reference/taxonomy/concept}
75+
* @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.
76+
* @example
77+
* ```javascript
78+
* const updatedConcept = await client.concept.updatePut({
79+
* organizationId: '<organization_id>',
80+
* conceptId: '<concept_id>',
81+
* version: 1,
82+
* }, patch);
83+
* ```
84+
*/
85+
updatePut(
86+
params: SetOptional<UpdateConceptParams, 'organizationId'>,
87+
payload: CreateConceptProps
88+
): Promise<ConceptProps>
89+
90+
/**
91+
* Update Concept
92+
* @returns the updated Concept
93+
* @throws if the request fails
94+
* @see {@link https://www.contentful.com/developers/docs/references/content-management-api/#/reference/taxonomy/concept}
95+
* @example
96+
* ```javascript
97+
* const updatedConcept = await client.concept.patch({
98+
* organizationId: '<organization_id>',
99+
* conceptId: '<concept_id>',
100+
* version: 1,
101+
* }, patch);
102+
* ```
103+
*/
104+
patch(
105+
params: SetOptional<UpdateConceptParams, 'organizationId'>,
106+
payload: OpPatch[]
107+
): Promise<ConceptProps>
108+
49109
/**
50110
* Get Concept
51111
* @returns the Concept

lib/plain/plain-client.ts

+6
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,12 @@ export const createPlainClient = (
106106
},
107107
concept: {
108108
create: wrap(wrapParams, 'Concept', 'create'),
109+
createWithId: wrap(wrapParams, 'Concept', 'createWithId'),
109110
get: wrap(wrapParams, 'Concept', 'get'),
110111
delete: wrap(wrapParams, 'Concept', 'delete'),
112+
patch: wrap(wrapParams, 'Concept', 'patch'),
111113
update: wrap(wrapParams, 'Concept', 'update'),
114+
updatePut: wrap(wrapParams, 'Concept', 'updatePut'),
112115
getMany: wrap(wrapParams, 'Concept', 'getMany'),
113116
getDescendants: wrap(wrapParams, 'Concept', 'getDescendants'),
114117
getAncestors: wrap(wrapParams, 'Concept', 'getAncestors'),
@@ -120,7 +123,10 @@ export const createPlainClient = (
120123
getTotal: wrap(wrapParams, 'ConceptScheme', 'getTotal'),
121124
delete: wrap(wrapParams, 'ConceptScheme', 'delete'),
122125
create: wrap(wrapParams, 'ConceptScheme', 'create'),
126+
createWithId: wrap(wrapParams, 'ConceptScheme', 'createWithId'),
127+
patch: wrap(wrapParams, 'ConceptScheme', 'patch'),
123128
update: wrap(wrapParams, 'ConceptScheme', 'update'),
129+
updatePut: wrap(wrapParams, 'ConceptScheme', 'updatePut'),
124130
},
125131
function: {
126132
getMany: wrap(wrapParams, 'Function', 'getMany'),

0 commit comments

Comments
 (0)