Skip to content

Commit

Permalink
feat: adds support for 'modifyPreviewConfiguration' query (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
Enngage committed Jul 31, 2023
1 parent 6f8c7a5 commit 2baa8ff
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 20 deletions.
31 changes: 18 additions & 13 deletions lib/client/imanagement-client.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ContentTypeSnippetModels,
LanguageModels,
LanguageVariantElementsBuilder,
PreviewModels,
ProjectUserModels,
SpaceModels,
TaxonomyModels,
Expand Down Expand Up @@ -129,7 +130,8 @@ import {
TaskIdentifierQuery,
CheckEnvironmentValidationQuery,
ListEnvironmentValidationIssuesQuery,
GetPreviewConfigurationQuery
GetPreviewConfigurationQuery,
ModifyPreviewConfigurationQuery
} from '../queries';
import { IMappingService } from '../services';
import { GetEnvironmentCloningStateQuery } from '../queries/environments';
Expand Down Expand Up @@ -308,7 +310,6 @@ export interface IManagementClient<TCancelToken> {
DataQuery<
UpsertLanguageVariantQuery,
(builder: LanguageVariantElementsBuilder) => LanguageVariantContracts.IUpsertLanguageVariantPostContract

>
>
>;
Expand All @@ -322,12 +323,12 @@ export interface IManagementClient<TCancelToken> {

/**
* Starts validating the specified environment to check for issues such as:
* - Nonexistent objects referenced in content items.
* - Content element values don't meet the limitations configured in content types.
* - Content types referencing nonexistent taxonomy groups.
* Depending on the size of your environment, the validation might take several minutes.
* After you start the environment validation, you get a validation task.
* With the validation task, you can check validation progress and list validation results once the validation is finished.
* - Nonexistent objects referenced in content items.
* - Content element values don't meet the limitations configured in content types.
* - Content types referencing nonexistent taxonomy groups.
* Depending on the size of your environment, the validation might take several minutes.
* After you start the environment validation, you get a validation task.
* With the validation task, you can check validation progress and list validation results once the validation is finished.
*/
startEnvironmentValidation(): StartEnvironmentValidationQuery;

Expand Down Expand Up @@ -678,19 +679,15 @@ export interface IManagementClient<TCancelToken> {
*/
deleteSpace(): SpaceIdentifierQuery<DeleteSpaceQuery>;


/**
* Lists all spaces
*/
listSpaces(): ListSpacesQuery;


/**
* Modifies a space
*/
modifySpace(): SpaceIdentifierQuery<
DataQuery<ModifySpaceQuery, SpaceModels.IModifySpaceData[]>
>;
modifySpace(): SpaceIdentifierQuery<DataQuery<ModifySpaceQuery, SpaceModels.IModifySpaceData[]>>;

/**
* Views a space
Expand All @@ -701,4 +698,12 @@ export interface IManagementClient<TCancelToken> {
* Gets preview configuration
*/
getPreviewConfiguration(): GetPreviewConfigurationQuery;

/**
* Adjusts the preview URLs configured for your environment
*/
modifyPreviewConfiguration(): DataQuery<
ModifyPreviewConfigurationQuery,
PreviewModels.IModifyPreviewConfigurationData
>;
}
15 changes: 14 additions & 1 deletion lib/client/management-client.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
AssetRenditionModels,
CollectionModels,
LanguageVariantElementsBuilder,
PreviewModels,
ProjectUserModels,
SpaceModels
} from '../models';
Expand Down Expand Up @@ -133,7 +134,8 @@ import {
ModifySpaceQuery,
ViewSpaceQuery,
SpaceIdentifierQuery,
GetPreviewConfigurationQuery
GetPreviewConfigurationQuery,
ModifyPreviewConfigurationQuery
} from '../queries';
import { sdkInfo } from '../sdk-info.generated';
import { ManagementQueryService, IMappingService, MappingService } from '../services';
Expand Down Expand Up @@ -1149,6 +1151,17 @@ export class ManagementClient implements IManagementClient<CancelToken> {
return new GetPreviewConfigurationQuery(this.config, this.queryService);
}

modifyPreviewConfiguration(): DataQuery<
ModifyPreviewConfigurationQuery,
PreviewModels.IModifyPreviewConfigurationData
> {
return new DataQuery<ModifyPreviewConfigurationQuery, PreviewModels.IModifyPreviewConfigurationData>(
this.config,
this.queryService,
(config, queryService, data) => new ModifyPreviewConfigurationQuery(config, queryService, data)
);
}

inviteUser(): DataQuery<InviteProjectUserQuery, ProjectUserModels.IInviteUserData> {
return new DataQuery<InviteProjectUserQuery, ProjectUserModels.IInviteUserData>(
this.config,
Expand Down
10 changes: 10 additions & 0 deletions lib/mappers/preview-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ export class PreviewMapper extends BaseMapper {
);
}

mapModifyConfigurationResponse(
response: IResponse<PreviewContracts.IPreviewConfigurationContract>
): PreviewResponses.ModifyConfigurationResponse {
return new PreviewResponses.ModifyConfigurationResponse(
super.mapResponseDebug(response),
response.data,
this.mapPreviewConfiguration(response.data)
);
}

private mapPreviewConfiguration(
rawItem: PreviewContracts.IPreviewConfigurationContract
): PreviewModels.PreviewConfiguration {
Expand Down
4 changes: 4 additions & 0 deletions lib/models/content-management-api-endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ export class ContentManagementApiEndpoints {
return `${this.getEnvironmentsPath()}/preview-configuration`;
}

modifyPreviewConfigruation(): string {
return `${this.getEnvironmentsPath()}/preview-configuration`;
}

inviteProjectUser(): string {
return `${this.getEnvironmentsPath()}/users`;
}
Expand Down
24 changes: 24 additions & 0 deletions lib/models/preview/preview.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,28 @@ export namespace PreviewModels {
this._raw = data._raw;
}
}

export interface IModifyPreviewConfigurationData {
space_domains: {
space: {
id?: string;
codename?: string;
};
domain: string;
}[];
preview_url_patterns: {
content_type: {
id?: string;
codename?: string;
external_id?: string;
};
url_patterns: {
space: null | {
id?: string;
codename?: string;
};
url_pattern: string;
}[];
}[];
}
}
16 changes: 11 additions & 5 deletions lib/queries/preview/modify-preview-configuration-query.class.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { PreviewResponses } from '../../responses';
import { IManagementClientConfig } from '../../config';
import { ManagementQueryService } from '../../services';
import { BaseQuery } from '../base-query';
import { PreviewModels } from '../../models';

export class ModifyPreviewConfigurationQuery extends BaseQuery<any> {
constructor(protected config: IManagementClientConfig, protected queryService: ManagementQueryService) {
export class ModifyPreviewConfigurationQuery extends BaseQuery<PreviewResponses.ModifyConfigurationResponse> {
constructor(
protected config: IManagementClientConfig,
protected queryService: ManagementQueryService,
private data: PreviewModels.IModifyPreviewConfigurationData
) {
super(config, queryService);
}

toPromise(): Promise<any> {
return this.queryService.getPreviewConfigurationAsync(this.getUrl(), this.queryConfig);
toPromise(): Promise<PreviewResponses.ModifyConfigurationResponse> {
return this.queryService.modifyPreviewConfigurationAsync(this.getUrl(), this.queryConfig, this.data);
}

protected getAction(): string {
return this.apiEndpoints.getPreviewConfigruation();
return this.apiEndpoints.modifyPreviewConfigruation();
}
}
13 changes: 13 additions & 0 deletions lib/responses/preview/preview-responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,17 @@ export namespace PreviewResponses {
super(debug, rawData, data);
}
}

export class ModifyConfigurationResponse extends BaseResponses.BaseContentManagementResponse<
PreviewContracts.IPreviewConfigurationContract,
PreviewModels.PreviewConfiguration
> {
constructor(
debug: BaseResponses.IContentManagementResponseDebug,
rawData: PreviewContracts.IPreviewConfigurationContract,
data: PreviewModels.PreviewConfiguration
) {
super(debug, rawData, data);
}
}
}
13 changes: 12 additions & 1 deletion lib/services/management-query-service.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ import {
CollectionModels,
ProjectUserModels,
AssetRenditionModels,
SpaceModels
SpaceModels,
PreviewModels
} from '../models';
import {
AssetFolderResponses,
Expand Down Expand Up @@ -998,6 +999,16 @@ export class ManagementQueryService extends BaseManagementQueryService<any> {
);
}

async modifyPreviewConfigurationAsync(
url: string,
config: IContentManagementQueryConfig,
data: PreviewModels.IModifyPreviewConfigurationData
): Promise<PreviewResponses.ModifyConfigurationResponse> {
return previewMapper.mapModifyConfigurationResponse(
await this.putResponseAsync<PreviewContracts.IPreviewConfigurationContract>(url, data, {}, config)
);
}

async setCollectionsAsync(
url: string,
config: IContentManagementQueryConfig,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"space_domains": [
{
"space": {
"id": "fb2c6c2b-fb79-4d1b-856a-b59762e304b0"
},
"domain": "www.mysite1.com"
},
{
"space": {
"id": "24dace50-3cf6-4378-8704-453af9cdb60c"
},
"domain": "www.mysite2.com"
}
],
"preview_url_patterns": [
{
"content_type": {
"id": "cf75f19d-6ed4-4820-a541-cde50dd79054"
},
"url_patterns": [
{
"space": {
"id": "24dace50-3cf6-4378-8704-453af9cdb60c"
},
"url_pattern": "https://{Space}/{Lang}/articles/history/"
}
]
},
{
"content_type": {
"id": "f21f6c3b-f63e-4aa1-866f-55fd85ad262e"
},
"url_patterns": [
{
"space": null,
"url_pattern": "https://www.mysite1.com/{Lang}/articles/"
}
]
}
]
}
60 changes: 60 additions & 0 deletions test/browser/preview/modify-preview-configuration.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { PreviewModels, PreviewResponses } from '../../../lib';
import * as responseJson from '../fake-responses/preview/fake-modify-preview-configuration.json';
import { cmLiveClient, getTestClientWithJson, testEnvironmentId } from '../setup';

describe('Modify preview configuration', () => {
let response: PreviewResponses.ModifyConfigurationResponse;

beforeAll(async () => {
response = await getTestClientWithJson(responseJson)
.modifyPreviewConfiguration()
.withData({
space_domains: [
{
domain: 'z.com',
space: {
codename: 'spaceCodename'
}
}
],
preview_url_patterns: [
{
content_type: {
codename: 'contentTypeCodename'
},
url_patterns: [
{
space: {
codename: 'spaceCodename'
},
url_pattern: 'https://{Space}/{Lang}/articles/history/'
}
]
}
]
})
.toPromise();
});

it(`url should be correct`, () => {
const url = cmLiveClient
.modifyPreviewConfiguration()
.withData({} as any)
.getUrl();

expect(url).toEqual(`https://manage.kontent.ai/v2/projects/${testEnvironmentId}/preview-configuration`);
});

it(`response should be instance of PreviewResponses.ModifyConfigurationResponse class`, () => {
expect(response).toEqual(jasmine.any(PreviewResponses.ModifyConfigurationResponse));
});

it(`response should contain debug data`, () => {
expect(response.debug).toBeDefined();
});

it(`response should contain data`, () => {
expect(response.data).toBeDefined();
expect(response.data).toEqual(jasmine.any(PreviewModels.PreviewConfiguration));
});
});

0 comments on commit 2baa8ff

Please sign in to comment.