Skip to content

Commit

Permalink
feat: Add support for collections in spaces (#141)
Browse files Browse the repository at this point in the history
* added display_timezone to workflow model

* added IListLanguageVariantsBySpaceResponseContract

* added ListLanguageVariantsByCollectionResponse

* added listLanguageVariantsBySpaceAsync to query service

* added mapLanguageVariantsByCollectionResponse to mapper

* added listLanguageVariantsBySpace to api-endpoints. Added list-language-variants-by-space to language variant queries. Added ListAllLanguageVariantsBySpaceResponse to language variant responses

* added fake-list-language-variants-by-space

* added list-language-variants-by-space.spec

* added listLanguageVariantsByCollection() to imanagement-client.interface.ts

* local tests successful, final changes

* updated space.models.ts with collections property

* updated space-contract.ts with collections property

* updated space fake responses with collections property

* updated space tests to validate collections property

* added collection property to mapSpace, updated test cases. All tests passing

* renames file

---------

Co-authored-by: Richard Sustek <[email protected]>
  • Loading branch information
Nickm615 and Enngage authored Feb 29, 2024
1 parent 333db01 commit db09550
Show file tree
Hide file tree
Showing 27 changed files with 308 additions and 13 deletions.
6 changes: 6 additions & 0 deletions lib/client/imanagement-client.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import {
ListLanguageVariantsOfContentTypeQuery,
ListLanguageVariantsOfContentTypeWithComponentsQuery,
ListLanguageVariantsOfItemQuery,
ListLanguageVariantsBySpaceQuery,
ListSpacesQuery,
ListTaxonomiesQuery,
ListLegacyWebhooksQuery,
Expand Down Expand Up @@ -582,6 +583,11 @@ export interface IManagementClient<TCancelToken> {
*/
listLanguageVariantsByCollection(): CollectionIdentifierQuery<ListLanguageVariantsByCollectionQuery>;

/**
* Query to list language variants of given space
*/
listLanguageVariantsBySpace(): SpaceIdentifierQuery<ListLanguageVariantsBySpaceQuery>;

/**
* Query to set collections
*/
Expand Down
11 changes: 11 additions & 0 deletions lib/client/management-client.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import {
ListLanguageVariantsOfContentTypeQuery,
ListLanguageVariantsOfContentTypeWithComponentsQuery,
ListLanguageVariantsOfItemQuery,
ListLanguageVariantsBySpaceQuery,
ListTaxonomiesQuery,
ListWebhooksQuery,
ListLegacyWebhooksQuery,
Expand Down Expand Up @@ -955,6 +956,16 @@ export class ManagementClient implements IManagementClient<CancelToken> {
);
}

listLanguageVariantsBySpace(): SpaceIdentifierQuery<ListLanguageVariantsBySpaceQuery> {
return new SpaceIdentifierQuery<ListLanguageVariantsBySpaceQuery>(
this.config,
this.queryService,
(config, queryService, identifier) =>
new ListLanguageVariantsBySpaceQuery(config, queryService, identifier)
);
}


listLanguageVariantsOfContentTypeWithComponents(): ContentTypeCodenameAndIdIdentifierQuery<ListLanguageVariantsOfContentTypeWithComponentsQuery> {
return new ContentTypeCodenameAndIdIdentifierQuery<ListLanguageVariantsOfContentTypeWithComponentsQuery>(
this.config,
Expand Down
5 changes: 5 additions & 0 deletions lib/contracts/language-variant-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export namespace LanguageVariantContracts {
pagination: SharedContracts.IPaginationModelContract;
}

export interface IListLanguageVariantsBySpaceResponseContract {
variants: ILanguageVariantModelContract[];
pagination: SharedContracts.IPaginationModelContract;
}

export interface IListLanguageVariantsOfContentTypeResponseContract {
variants: ILanguageVariantModelContract[];
pagination: SharedContracts.IPaginationModelContract;
Expand Down
2 changes: 2 additions & 0 deletions lib/contracts/space-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export namespace SpaceContracts {
name: string;
codename: string;
web_spotlight_root_item?: SharedContracts.IReferenceObjectContract;
collections?: SharedContracts.IReferenceObjectContract[];
}

export type ISpacesListingResponseContract = ISpaceContract[];
Expand All @@ -27,5 +28,6 @@ export namespace SpaceContracts {
name: string;
codename: string;
webSpotlightRootItem?: SharedContracts.IReferenceObjectContract;
collections?: SharedContracts.IReferenceObjectContract;
}
}
17 changes: 17 additions & 0 deletions lib/mappers/language-variant-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ export class LanguageVariantMapper extends BaseMapper {
);
}

mapLanguageVariantsBySpaceResponse(
response: IResponse<LanguageVariantContracts.IListLanguageVariantsBySpaceResponseContract>
): LanguageVariantResponses.ListLanguageVariantsBySpaceResponse {
const variants = response.data.variants.map((m) => this.mapLanguageVariant(m));
return new LanguageVariantResponses.ListLanguageVariantsBySpaceResponse(
super.mapResponseDebug(response),
response.data,
{
items: variants,
pagination: super.mapPagination(response.data.pagination)
}
);
}


mapLanguageVariantsOfContentTypeResponse(
response: IResponse<LanguageVariantContracts.IListLanguageVariantsOfContentTypeResponseContract>
): LanguageVariantResponses.ListLanguageVariantsOfContentTypeResponse {
Expand All @@ -70,6 +85,8 @@ export class LanguageVariantMapper extends BaseMapper {
);
}



mapLanguageVariantsOfContentTypeWithComponentsResponse(
response: IResponse<LanguageVariantContracts.IListLanguageVariantsOfContentTypeWithComponentsResponseContract>
): LanguageVariantResponses.ListLanguageVariantsOfContentTypeWithComponentsResponse {
Expand Down
1 change: 1 addition & 0 deletions lib/mappers/space-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class SpacesMapper extends BaseMapper {
id: rawItem.id,
name: rawItem.name,
webSpotlightRootItem: rawItem.web_spotlight_root_item,
collections: rawItem.collections,
_raw: rawItem
});
}
Expand Down
5 changes: 5 additions & 0 deletions lib/models/content-management-api-endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ export class ContentManagementApiEndpoints {
listLanguageVariantsByCollection(identifier: Identifiers.CollectionIdentifier): string {
return `${this.getEnvironmentsPath()}/collections/${identifier.getParamValue()}/variants`;
}

listLanguageVariantsBySpace(identifier: Identifiers.SpaceIdentifier): string {
return `${this.getEnvironmentsPath()}/spaces/${identifier.getParamValue()}/variants`;
}


listLanguageVariantsOfContentTypeWithComponents(identifier: Identifiers.ContentTypeIdentifier): string {
return `${this.getEnvironmentsPath()}/types/${identifier.getParamValue()}/components`;
Expand Down
3 changes: 3 additions & 0 deletions lib/models/spaces/space.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@ export namespace SpaceModels {
name: string;
codename?: string;
web_spotlight_root_item?: SharedContracts.IReferenceObjectContract;
collections?: SharedContracts.IReferenceObjectContract[];
}

export class Space implements SharedModels.IBaseModel<SpaceContracts.ISpaceContract> {
public id!: string;
public name!: string;
public codename!: string;
public webSpotlightRootItem?: SharedModels.ReferenceObject;
public collections?: SharedModels.ReferenceObject[];
public _raw!: SpaceContracts.ISpaceContract;

constructor(data: {
id: string;
name: string;
codename: string;
webSpotlightRootItem?: SharedModels.ReferenceObject;
collections?: SharedModels.ReferenceObject[];
_raw: SpaceContracts.ISpaceContract;
}) {
Object.assign(this, data);
Expand Down
2 changes: 2 additions & 0 deletions lib/models/workflow/workflow.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export namespace WorkflowModels {
* If you do not provide this property, the specified language variant is published immediately.
*/
scheduled_to?: string;
display_timezone?: string;
}

export interface IUnpublishLanguageVarianthData {
Expand All @@ -66,6 +67,7 @@ export namespace WorkflowModels {
* If you do not provide this property, the specified language variant is published immediately.
*/
scheduled_to?: string;
display_timezone?: string;
}

export interface IChangeWorkflowOfLanguageVariantData {
Expand Down
1 change: 1 addition & 0 deletions lib/queries/language-variants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './upsert-language-variant-query.class';
export * from './view-language-variant-query.class';
export * from './delete-language-variant-query.class';
export * from './list-language-variants-by-collection-query.class';
export * from './list-language-variants-by-space-query.class';
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { IManagementClientConfig } from '../../config';
import { Identifiers } from '../../models';
import { LanguageVariantResponses } from '../../responses';
import { ManagementQueryService } from '../../services';
import { BaseListingQuery } from '../base-listing-query';

export class ListLanguageVariantsBySpaceQuery extends BaseListingQuery<
LanguageVariantResponses.ListLanguageVariantsBySpaceResponse,
LanguageVariantResponses.ListAllLanguageVariantsBySpaceResponse
> {
constructor(
protected config: IManagementClientConfig,
protected queryService: ManagementQueryService,
protected identifier: Identifiers.SpaceIdentifier
) {
super(config, queryService);
}

toPromise(): Promise<LanguageVariantResponses.ListLanguageVariantsBySpaceResponse> {
return this.queryService.listLanguageVariantsBySpaceAsync(this.getUrl(), this.queryConfig);
}

protected getAction(): string {
return this.apiEndpoints.listLanguageVariantsBySpace(this.identifier);
}

protected allResponseFactory(
items: any[],
responses: LanguageVariantResponses.ListLanguageVariantsBySpaceResponse[]
): LanguageVariantResponses.ListAllLanguageVariantsBySpaceResponse {
return new LanguageVariantResponses.ListAllLanguageVariantsBySpaceResponse({
items: items,
responses: responses
});
}
}
29 changes: 29 additions & 0 deletions lib/responses/language-variants/language-variant-responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ export namespace LanguageVariantResponses {
}
}

export class ListLanguageVariantsBySpaceResponse extends BaseResponses.BaseContentManagementListResponse<
LanguageVariantContracts.IListLanguageVariantsBySpaceResponseContract,
LanguageVariantModels.ContentItemLanguageVariant
> {
constructor(
debug: BaseResponses.IContentManagementResponseDebug,
rawData: LanguageVariantContracts.IListLanguageVariantsBySpaceResponseContract,
data: {
items: LanguageVariantModels.ContentItemLanguageVariant[];
pagination: SharedModels.Pagination;
}
) {
super(debug, rawData, data);
}
}


export class ListAllLanguageVariantsOfContentTypeResponse extends BaseResponses.ContentManagementListAllResponse<ListLanguageVariantsOfContentTypeResponse, LanguageVariantModels.ContentItemLanguageVariant> {
constructor(
data: {
Expand All @@ -101,6 +118,18 @@ export namespace LanguageVariantResponses {
}
}

export class ListAllLanguageVariantsBySpaceResponse extends BaseResponses.ContentManagementListAllResponse<ListLanguageVariantsBySpaceResponse, LanguageVariantModels.ContentItemLanguageVariant> {
constructor(
data: {
items: LanguageVariantModels.ContentItemLanguageVariant[],
responses: ListLanguageVariantsBySpaceResponse[]
}
) {
super(data);
}
}


export class UpsertLanguageVariantResponse extends BaseResponses.BaseContentManagementResponse<
LanguageVariantContracts.IUpsertLanguageVariantResponseContract,
LanguageVariantModels.ContentItemLanguageVariant
Expand Down
18 changes: 17 additions & 1 deletion lib/services/management-query-service.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,23 @@ export class ManagementQueryService extends BaseManagementQueryService<any> {
config
)
);
}
}

async listLanguageVariantsBySpaceAsync(
url: string,
config: IContentManagementQueryConfig
): Promise<LanguageVariantResponses.ListLanguageVariantsBySpaceResponse> {
return languageVariantMapper.mapLanguageVariantsBySpaceResponse(
await this.getResponseAsync<LanguageVariantContracts.IListLanguageVariantsBySpaceResponseContract>(
url,
{},
config
)
);
}




async listLanguagesAsync(
url: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"variants": [
{
"elements": [
{
"element": {
"id": "c7c3b834-2222-5677-89c4-b46f04489109"
},
"value": "Text element value"
},
{
"mode": "custom",
"element": {
"id": "53a5eecb-f295-59b4-a07d-19655b6ad860"
},
"value": "custom-url-slug-value"
}
],
"workflow": {
"workflow_identifier": {
"id": "06ea628e-4ec7-4991-91e4-1412995151ee"
},
"step_identifier": {
"id": "dc87d7cf-424b-4b89-9519-c9f79a3458b7"
}
},
"workflow_step": {
"id": "dc87d7cf-424b-4b89-9519-c9f79a3458b7"
},
"item": {
"id": "82ef61f4-ccee-42ac-95e2-1a44beda9625"
},
"language": {
"id": "00000000-0000-0000-0000-000000000000"
},
"last_modified": "2020-02-27T19:08:25.404Z"
}
],
"pagination": {
"continuation_token": "W3sidG9rZW4iOiIrUklEOn...",
"next_page": "https://manage.kontent.ai/v2/your/chosen/list/endpoint"
}
}
7 changes: 6 additions & 1 deletion test/browser/fake-responses/spaces/fake-add-space.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"codename": "space_1",
"web_spotlight_root_item": {
"id": "09d5a63a-49a9-4b77-9e18-54a05441483e"
}
},
"collections": [
{
"id":"00000000-0000-0000-0000-000000000000"
}
]

}
9 changes: 8 additions & 1 deletion test/browser/fake-responses/spaces/fake-list-spaces.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
"codename": "space_1",
"web_spotlight_root_item": {
"id": "09d5a63a-49a9-4b77-9e18-54a05441483e"
}
},
"collections": [
{
"id":"00000000-0000-0000-0000-000000000000"
}
]


}
]
8 changes: 7 additions & 1 deletion test/browser/fake-responses/spaces/fake-modify-space.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
"codename": "space_1",
"web_spotlight_root_item": {
"id":"09d5a63a-49a9-4b77-9e18-54a05441483e"
}
},
"collections": [
{
"id":"00000000-0000-0000-0000-000000000000"
}
]


}
8 changes: 7 additions & 1 deletion test/browser/fake-responses/spaces/fake-view-space.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
"codename": "space_1",
"web_spotlight_root_item": {
"id": "09d5a63a-49a9-4b77-9e18-54a05441483e"
}
},
"collections": [
{
"id":"00000000-0000-0000-0000-000000000000"
}
]


}
Loading

0 comments on commit db09550

Please sign in to comment.