Skip to content
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
19 changes: 18 additions & 1 deletion lib/adapters/REST/endpoints/component-type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import type { RawAxiosRequestHeaders } from 'axios'
import type { AxiosInstance } from 'contentful-sdk-core'
import type { CollectionProp, GetSpaceEnvironmentParams } from '../../../common-types'
import type {
CollectionProp,
GetComponentTypeParams,
GetSpaceEnvironmentParams,
} from '../../../common-types'
import type {
ComponentTypeProps,
ComponentTypeQueryOptions,
Expand Down Expand Up @@ -31,3 +35,16 @@ export const get: RestEndpoint<'ComponentType', 'get'> = (
headers,
})
}

export const unpublish: RestEndpoint<'ComponentType', 'unpublish'> = (
http: AxiosInstance,
params: GetComponentTypeParams & { version: number },
headers?: RawAxiosRequestHeaders,
) => {
return raw.del(http, `${getBaseUrl(params)}/${params.componentTypeId}/published`, {
headers: {
'X-Contentful-Version': params.version,
...headers,
},
})
}
6 changes: 6 additions & 0 deletions lib/common-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ type MRInternal<UA extends boolean> = {

(opts: MROpts<'ComponentType', 'getMany', UA>): MRReturn<'ComponentType', 'getMany'>
(opts: MROpts<'ComponentType', 'get', UA>): MRReturn<'ComponentType', 'get'>
(opts: MROpts<'ComponentType', 'unpublish', UA>): MRReturn<'ComponentType', 'unpublish'>

(opts: MROpts<'Concept', 'get', UA>): MRReturn<'Concept', 'get'>
(opts: MROpts<'Concept', 'getMany', UA>): MRReturn<'Concept', 'getMany'>
Expand Down Expand Up @@ -1478,6 +1479,10 @@ export type MRActions = {
params: GetSpaceEnvironmentParams & { componentId: string }
return: ComponentTypeProps
}
unpublish: {
params: GetComponentTypeParams & { version: number }
return: ComponentTypeProps
}
}
Concept: {
create: {
Expand Down Expand Up @@ -2610,6 +2615,7 @@ export type GetBulkActionParams = GetSpaceEnvironmentParams & { bulkActionId: st
export type GetCommentParams = (GetEntryParams | GetCommentParentEntityParams) & {
commentId: string
}
export type GetComponentTypeParams = GetSpaceEnvironmentParams & { componentTypeId: string }
export type GetContentTypeParams = GetSpaceEnvironmentParams & { contentTypeId: string }
export type GetEditorInterfaceParams = GetSpaceEnvironmentParams & { contentTypeId: string }
export type GetEntryParams = GetSpaceEnvironmentParams & { entryId: string }
Expand Down
25 changes: 24 additions & 1 deletion lib/plain/entities/component-type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { GetSpaceEnvironmentParams, CollectionProp } from '../../common-types'
import type {
GetSpaceEnvironmentParams,
GetComponentTypeParams,
CollectionProp,
} from '../../common-types'
import type { ComponentTypeQueryOptions, ComponentTypeProps } from '../../entities/component-type'
import type { OptionalDefaults } from '../wrappers/wrap'

Expand Down Expand Up @@ -48,4 +52,23 @@ export type ComponentTypePlainClientAPI = {
get(
params: OptionalDefaults<GetSpaceEnvironmentParams & { componentId: string }>,
): Promise<ComponentTypeProps>

/**
* Unpublishes a component type
* @param params the space, environment, and component type IDs
* @returns the unpublished component type
* @throws if the request fails, or the component type is not found
* @internal - Experimental endpoint, subject to breaking changes without notice
* @example
* ```javascript
* const componentType = await client.componentType.unpublish({
* spaceId: '<space_id>',
* environmentId: '<environment_id>',
* componentTypeId: '<component_type_id>',
* });
* ```
*/
unpublish(
params: OptionalDefaults<GetComponentTypeParams & { version: number }>,
): Promise<ComponentTypeProps>
}
1 change: 1 addition & 0 deletions lib/plain/plain-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export const createPlainClient = (
componentType: {
getMany: wrap(wrapParams, 'ComponentType', 'getMany'),
get: wrap(wrapParams, 'ComponentType', 'get'),
unpublish: wrap(wrapParams, 'ComponentType', 'unpublish'),
},
contentType: {
get: wrap(wrapParams, 'ContentType', 'get'),
Expand Down
38 changes: 38 additions & 0 deletions test/unit/adapters/REST/endpoints/component-type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,42 @@ describe('Rest ComponentType', { concurrent: true }, () => {
)
})
})

test('unpublish calls correct URL with DELETE method', async () => {
const mockResponse = {
sys: {
id: 'ct123',
type: 'ComponentType',
version: 2,
space: { sys: { type: 'Link', linkType: 'Space', id: 'space123' } },
environment: { sys: { type: 'Link', linkType: 'Environment', id: 'master' } },
},
name: 'Test Component',
description: 'A test component type',
viewports: [],
contentProperties: [],
designProperties: [],
dimensionKeyMap: { designProperties: {} },
}

const { httpMock, adapterMock } = setupRestAdapter(Promise.resolve({ data: mockResponse }))

return adapterMock
.makeRequest({
entityType: 'ComponentType',
action: 'unpublish',
userAgent: 'mocked',
params: {
spaceId: 'space123',
environmentId: 'master',
componentTypeId: 'ct123',
},
})
.then((r) => {
expect(r).to.eql(mockResponse)
expect(httpMock.delete.mock.calls[0][0]).to.eql(
'/spaces/space123/environments/master/component_types/ct123/published',
)
})
})
})