diff --git a/lib/adapters/REST/endpoints/asset.ts b/lib/adapters/REST/endpoints/asset.ts index 4c571f2aa..ee6f4e926 100644 --- a/lib/adapters/REST/endpoints/asset.ts +++ b/lib/adapters/REST/endpoints/asset.ts @@ -97,13 +97,15 @@ export const del: RestEndpoint<'Asset', 'delete'> = ( export const publish: RestEndpoint<'Asset', 'publish'> = ( http: AxiosInstance, - params: GetSpaceEnvironmentParams & { assetId: string }, + params: GetSpaceEnvironmentParams & { assetId: string; locales?: string[] }, rawData: AssetProps ) => { + const payload = params.locales?.length ? { add: { fields: { '*': params.locales } } } : null + return raw.put( http, `/spaces/${params.spaceId}/environments/${params.environmentId}/assets/${params.assetId}/published`, - null, + payload, { headers: { 'X-Contentful-Version': rawData.sys.version ?? 0, @@ -114,12 +116,27 @@ export const publish: RestEndpoint<'Asset', 'publish'> = ( export const unpublish: RestEndpoint<'Asset', 'unpublish'> = ( http: AxiosInstance, - params: GetSpaceEnvironmentParams & { assetId: string } + params: GetSpaceEnvironmentParams & { assetId: string; locales?: string[] }, + rawData?: AssetProps ) => { - return raw.del( - http, - `/spaces/${params.spaceId}/environments/${params.environmentId}/assets/${params.assetId}/published` - ) + if (params.locales?.length) { + const payload = { remove: { fields: { '*': params.locales } } } + return raw.put( + http, + `/spaces/${params.spaceId}/environments/${params.environmentId}/assets/${params.assetId}/published`, + payload, + { + headers: { + 'X-Contentful-Version': rawData?.sys.version, + }, + } + ) + } else { + return raw.del( + http, + `/spaces/${params.spaceId}/environments/${params.environmentId}/assets/${params.assetId}/published` + ) + } } export const archive: RestEndpoint<'Asset', 'archive'> = ( diff --git a/lib/adapters/REST/endpoints/entry.ts b/lib/adapters/REST/endpoints/entry.ts index af0336000..70fae2995 100644 --- a/lib/adapters/REST/endpoints/entry.ts +++ b/lib/adapters/REST/endpoints/entry.ts @@ -117,13 +117,15 @@ export const del: RestEndpoint<'Entry', 'delete'> = ( export const publish: RestEndpoint<'Entry', 'publish'> = ( http: AxiosInstance, - params: GetSpaceEnvironmentParams & { entryId: string }, + params: GetSpaceEnvironmentParams & { entryId: string; locales?: string[] }, rawData: EntryProps ) => { + const payload = params.locales?.length ? { add: { fields: { '*': params.locales } } } : null + return raw.put>( http, `/spaces/${params.spaceId}/environments/${params.environmentId}/entries/${params.entryId}/published`, - null, + payload, { headers: { 'X-Contentful-Version': rawData.sys.version, @@ -134,12 +136,27 @@ export const publish: RestEndpoint<'Entry', 'publish'> = = ( http: AxiosInstance, - params: GetSpaceEnvironmentParams & { entryId: string } + params: GetSpaceEnvironmentParams & { entryId: string; locales?: string[] }, + rawData?: EntryProps ) => { - return raw.del>( - http, - `/spaces/${params.spaceId}/environments/${params.environmentId}/entries/${params.entryId}/published` - ) + if (params.locales?.length) { + const payload = { remove: { fields: { '*': params.locales } } } + return raw.put>( + http, + `/spaces/${params.spaceId}/environments/${params.environmentId}/entries/${params.entryId}/published`, + payload, + { + headers: { + 'X-Contentful-Version': rawData?.sys.version, + }, + } + ) + } else { + return raw.del>( + http, + `/spaces/${params.spaceId}/environments/${params.environmentId}/entries/${params.entryId}/published` + ) + } } export const archive: RestEndpoint<'Entry', 'archive'> = ( diff --git a/lib/common-types.ts b/lib/common-types.ts index 3491135ae..66878f8ca 100644 --- a/lib/common-types.ts +++ b/lib/common-types.ts @@ -277,6 +277,7 @@ export interface EntityMetaSysProps extends MetaSysProps { firstPublishedAt?: string publishedCounter?: number locale?: string + fieldStatus: { '*': Record } } export interface EntryMetaSysProps extends EntityMetaSysProps { diff --git a/lib/plain/common-types.ts b/lib/plain/common-types.ts index eb2d07801..715b920a1 100644 --- a/lib/plain/common-types.ts +++ b/lib/plain/common-types.ts @@ -291,11 +291,11 @@ export type PlainClientAPI = { ): Promise> delete(params: OptionalDefaults): Promise publish( - params: OptionalDefaults, + params: OptionalDefaults, rawData: EntryProps ): Promise> unpublish( - params: OptionalDefaults + params: OptionalDefaults ): Promise> archive( params: OptionalDefaults @@ -345,11 +345,11 @@ export type PlainClientAPI = { ): Promise delete(params: OptionalDefaults): Promise publish( - params: OptionalDefaults, + params: OptionalDefaults, rawData: AssetProps ): Promise unpublish( - params: OptionalDefaults + params: OptionalDefaults ): Promise archive( params: OptionalDefaults