Skip to content

Commit

Permalink
feat: adds support for 'getPreviewConfiguration' API endpoint (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
Enngage committed Jul 31, 2023
1 parent 2d9143b commit 6f8c7a5
Show file tree
Hide file tree
Showing 19 changed files with 291 additions and 19 deletions.
7 changes: 6 additions & 1 deletion lib/client/imanagement-client.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ import {
StartEnvironmentValidationQuery,
TaskIdentifierQuery,
CheckEnvironmentValidationQuery,
ListEnvironmentValidationIssuesQuery
ListEnvironmentValidationIssuesQuery,
GetPreviewConfigurationQuery
} from '../queries';
import { IMappingService } from '../services';
import { GetEnvironmentCloningStateQuery } from '../queries/environments';
Expand Down Expand Up @@ -696,4 +697,8 @@ export interface IManagementClient<TCancelToken> {
*/
viewSpace(): SpaceIdentifierQuery<ViewSpaceQuery>;

/**
* Gets preview configuration
*/
getPreviewConfiguration(): GetPreviewConfigurationQuery;
}
28 changes: 14 additions & 14 deletions lib/client/management-client.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '../models';

import { IManagementClientConfig } from '../config';
import { ContentItemContracts, LanguageVariantContracts} from '../contracts';
import { ContentItemContracts, LanguageVariantContracts } from '../contracts';
import {
AssetFolderModels,
AssetModels,
Expand Down Expand Up @@ -132,7 +132,8 @@ import {
ListSpacesQuery,
ModifySpaceQuery,
ViewSpaceQuery,
SpaceIdentifierQuery
SpaceIdentifierQuery,
GetPreviewConfigurationQuery
} from '../queries';
import { sdkInfo } from '../sdk-info.generated';
import { ManagementQueryService, IMappingService, MappingService } from '../services';
Expand Down Expand Up @@ -525,17 +526,16 @@ export class ManagementClient implements IManagementClient<CancelToken> {
DataQuery<
UpsertLanguageVariantQuery,
(builder: LanguageVariantElementsBuilder) => LanguageVariantContracts.IUpsertLanguageVariantPostContract

>
>
> {
return new ContentItemIdentifierQuery<
LanguageIdAndCodenameIdentifierQuery<
DataQuery<
UpsertLanguageVariantQuery,
(builder: LanguageVariantElementsBuilder) => LanguageVariantContracts.IUpsertLanguageVariantPostContract


(
builder: LanguageVariantElementsBuilder
) => LanguageVariantContracts.IUpsertLanguageVariantPostContract
>
>
>(
Expand All @@ -548,7 +548,6 @@ export class ManagementClient implements IManagementClient<CancelToken> {
(
builder: LanguageVariantElementsBuilder
) => LanguageVariantContracts.IUpsertLanguageVariantPostContract

>
>(
config,
Expand All @@ -559,7 +558,6 @@ export class ManagementClient implements IManagementClient<CancelToken> {
(
builder: LanguageVariantElementsBuilder
) => LanguageVariantContracts.IUpsertLanguageVariantPostContract

>(
nConfig,
nQueryService,
Expand Down Expand Up @@ -613,7 +611,8 @@ export class ManagementClient implements IManagementClient<CancelToken> {
return new TaskIdentifierQuery<ListEnvironmentValidationIssuesQuery>(
this.config,
this.queryService,
(config, queryService, identifier) => new ListEnvironmentValidationIssuesQuery(config, queryService, identifier)
(config, queryService, identifier) =>
new ListEnvironmentValidationIssuesQuery(config, queryService, identifier)
);
}

Expand Down Expand Up @@ -1146,6 +1145,10 @@ export class ManagementClient implements IManagementClient<CancelToken> {
);
}

getPreviewConfiguration(): GetPreviewConfigurationQuery {
return new GetPreviewConfigurationQuery(this.config, this.queryService);
}

inviteUser(): DataQuery<InviteProjectUserQuery, ProjectUserModels.IInviteUserData> {
return new DataQuery<InviteProjectUserQuery, ProjectUserModels.IInviteUserData>(
this.config,
Expand Down Expand Up @@ -1223,17 +1226,14 @@ export class ManagementClient implements IManagementClient<CancelToken> {
}

modifySpace(): SpaceIdentifierQuery<DataQuery<ModifySpaceQuery, SpaceModels.IModifySpaceData[]>> {
return new SpaceIdentifierQuery<
DataQuery<ModifySpaceQuery, SpaceModels.IModifySpaceData[]>
>(
return new SpaceIdentifierQuery<DataQuery<ModifySpaceQuery, SpaceModels.IModifySpaceData[]>>(
this.config,
this.queryService,
(config, queryService, identifier) =>
new DataQuery<ModifySpaceQuery, SpaceModels.IModifySpaceData[]>(
config,
queryService,
(nConfig, nQueryService, data) =>
new ModifySpaceQuery(nConfig, nQueryService, identifier, data)
(nConfig, nQueryService, data) => new ModifySpaceQuery(nConfig, nQueryService, identifier, data)
)
);
}
Expand Down
1 change: 1 addition & 0 deletions lib/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export * from './project-user-contracts';
export * from './environment-contracts';
export * from './asset-rendition-contracts';
export * from './space-contracts';
export * from './preview-contracts';
29 changes: 29 additions & 0 deletions lib/contracts/preview-contracts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export namespace PreviewContracts {
export interface IPreviewSpaceContract {
id: string;
}

export interface IPreviewContentTypeContract {
id: string;
}

export interface IPreviewUrlPatternContract {
space: IPreviewSpaceContract | null;
url_pattern: string;
}

export interface IPreviewUrlPatternsContract {
content_type: IPreviewContentTypeContract;
url_patterns: IPreviewUrlPatternContract[];
}

export interface IPreviewSpaceDomainContract {
space: IPreviewSpaceContract;
domain: string;
}

export interface IPreviewConfigurationContract {
space_domains: IPreviewSpaceDomainContract[];
preview_url_patterns: IPreviewUrlPatternsContract[];
}
}
1 change: 1 addition & 0 deletions lib/mappers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export * from './role-mapper';
export * from './project-user-mapper';
export * from './asset-rendition-mapper';
export * from './space-mapper';
export * from './preview-mapper';
44 changes: 44 additions & 0 deletions lib/mappers/preview-mapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { IResponse } from '@kontent-ai/core-sdk';

import { PreviewContracts } from '../contracts';
import { PreviewModels } from '../models';
import { BaseMapper } from './base-mapper';
import { PreviewResponses } from '../responses/preview/preview-responses';

export class PreviewMapper extends BaseMapper {
mapPreviewConfigurationResponse(
response: IResponse<PreviewContracts.IPreviewConfigurationContract>
): PreviewResponses.PreviewConfigurationResponse {
return new PreviewResponses.PreviewConfigurationResponse(
super.mapResponseDebug(response),
response.data,
this.mapPreviewConfiguration(response.data)
);
}

private mapPreviewConfiguration(
rawItem: PreviewContracts.IPreviewConfigurationContract
): PreviewModels.PreviewConfiguration {
return new PreviewModels.PreviewConfiguration({
_raw: rawItem,
previewUrlPatterns: rawItem.preview_url_patterns.map((urlPatternsContract) => {
const urlPatterns: PreviewModels.IPreviewUrlPatterns = {
contentType: urlPatternsContract.content_type,
urlPatterns: urlPatternsContract.url_patterns.map((urlPatternContract) => {
const urlPattern: PreviewModels.IPreviewUrlPattern = {
space: urlPatternContract.space,
urlPattern: urlPatternContract.url_pattern
};

return urlPattern;
})
};

return urlPatterns;
}),
spaceDomains: rawItem.space_domains
});
}
}

export const previewMapper = new PreviewMapper();
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 @@ -350,6 +350,10 @@ export class ContentManagementApiEndpoints {
return `${this.getEnvironmentsPath()}/roles/${identifier.getParamValue()}`;
}

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

inviteProjectUser(): string {
return `${this.getEnvironmentsPath()}/users`;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ export * from './project-users/project-users.models';
export * from './asset-renditions/asset-rendition.models';
export * from './environments/environment.models';
export * from './assets/asset-elements.builder';
export * from './spaces/space-models';
export * from './spaces/space.models';
export * from './preview/preview.models';
45 changes: 45 additions & 0 deletions lib/models/preview/preview.models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { SharedModels } from '../shared/shared-models';
import { PreviewContracts } from '../../contracts';

export namespace PreviewModels {
export interface IPreviewSpace {
id: string;
}

export interface IPreviewContentType {
id: string;
}

export interface IPreviewUrlPattern {
space: IPreviewSpace | null;
urlPattern: string;
}

export interface IPreviewUrlPatterns {
contentType: IPreviewContentType;
urlPatterns: IPreviewUrlPattern[];
}

export interface IPreviewSpaceDomain {
space: IPreviewSpace;
domain: string;
}

export class PreviewConfiguration
implements SharedModels.IBaseModel<PreviewContracts.IPreviewConfigurationContract>
{
public spaceDomains: IPreviewSpaceDomain[];
public previewUrlPatterns: IPreviewUrlPatterns[];
public _raw: PreviewContracts.IPreviewConfigurationContract;

constructor(data: {
spaceDomains: IPreviewSpaceDomain[];
previewUrlPatterns: IPreviewUrlPatterns[];
_raw: PreviewContracts.IPreviewConfigurationContract;
}) {
this.spaceDomains = data.spaceDomains;
this.previewUrlPatterns = data.previewUrlPatterns;
this._raw = data._raw;
}
}
}
File renamed without changes.
1 change: 1 addition & 0 deletions lib/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export * from './project-users';
export * from './asset-renditions';
export * from './spaces';
export * from './environments';
export * from './preview';
18 changes: 18 additions & 0 deletions lib/queries/preview/get-preview-configuration-query.class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { PreviewResponses } from '../../responses';
import { IManagementClientConfig } from '../../config';
import { ManagementQueryService } from '../../services';
import { BaseQuery } from '../base-query';

export class GetPreviewConfigurationQuery extends BaseQuery<PreviewResponses.PreviewConfigurationResponse> {
constructor(protected config: IManagementClientConfig, protected queryService: ManagementQueryService) {
super(config, queryService);
}

toPromise(): Promise<PreviewResponses.PreviewConfigurationResponse> {
return this.queryService.getPreviewConfigurationAsync(this.getUrl(), this.queryConfig);
}

protected getAction(): string {
return this.apiEndpoints.getPreviewConfigruation();
}
}
2 changes: 2 additions & 0 deletions lib/queries/preview/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './get-preview-configuration-query.class';
export * from './modify-preview-configuration-query.class';
17 changes: 17 additions & 0 deletions lib/queries/preview/modify-preview-configuration-query.class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { IManagementClientConfig } from '../../config';
import { ManagementQueryService } from '../../services';
import { BaseQuery } from '../base-query';

export class ModifyPreviewConfigurationQuery extends BaseQuery<any> {
constructor(protected config: IManagementClientConfig, protected queryService: ManagementQueryService) {
super(config, queryService);
}

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

protected getAction(): string {
return this.apiEndpoints.getPreviewConfigruation();
}
}
1 change: 1 addition & 0 deletions lib/responses/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export * from './project-users/project-users-responses';
export * from './asset-renditions/asset-rendition-responses';
export * from './spaces/space-responses';
export * from './environments/environment-responses';
export * from './preview/preview-responses';
18 changes: 18 additions & 0 deletions lib/responses/preview/preview-responses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { PreviewContracts } from '../../contracts';
import { PreviewModels } from '../../models';
import { BaseResponses } from '../base-responses';

export namespace PreviewResponses {
export class PreviewConfigurationResponse extends BaseResponses.BaseContentManagementResponse<
PreviewContracts.IPreviewConfigurationContract,
PreviewModels.PreviewConfiguration
> {
constructor(
debug: BaseResponses.IContentManagementResponseDebug,
rawData: PreviewContracts.IPreviewConfigurationContract,
data: PreviewModels.PreviewConfiguration
) {
super(debug, rawData, data);
}
}
}
18 changes: 15 additions & 3 deletions lib/services/management-query-service.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import {
SpaceContracts,
TaxonomyContracts,
WebhookContracts,
WorkflowContracts
WorkflowContracts,
PreviewContracts
} from '../contracts';
import {
assetFolderMapper,
Expand All @@ -37,7 +38,8 @@ import {
roleMapper,
projectUserMapper,
assetRenditionMapper,
spacesMapper
spacesMapper,
previewMapper
} from '../mappers';
import { webhookMapper } from '../mappers/webhook-mapper';
import {
Expand Down Expand Up @@ -74,7 +76,8 @@ import {
RoleResponses,
ProjectUsersResponses,
AssetRenditionResponses,
SpaceResponses
SpaceResponses,
PreviewResponses
} from '../responses';
import { BaseManagementQueryService } from './base-management-service.class';
import { EnvironmentResponses } from '../responses/environments/environment-responses';
Expand Down Expand Up @@ -986,6 +989,15 @@ export class ManagementQueryService extends BaseManagementQueryService<any> {
);
}

async getPreviewConfigurationAsync(
url: string,
config: IContentManagementQueryConfig
): Promise<PreviewResponses.PreviewConfigurationResponse> {
return previewMapper.mapPreviewConfigurationResponse(
await this.getResponseAsync<PreviewContracts.IPreviewConfigurationContract>(url, {}, config)
);
}

async setCollectionsAsync(
url: string,
config: IContentManagementQueryConfig,
Expand Down
Loading

0 comments on commit 6f8c7a5

Please sign in to comment.