Skip to content

Commit

Permalink
feat: Adds support for Web spotlight API endpoints (activate/deactiva…
Browse files Browse the repository at this point in the history
…te/get status)
  • Loading branch information
Enngage committed Jul 29, 2024
1 parent 98b0cc1 commit 4070892
Show file tree
Hide file tree
Showing 25 changed files with 407 additions and 41 deletions.
21 changes: 20 additions & 1 deletion lib/client/imanagement-client.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
SpaceModels,
TaxonomyModels,
WebhookModels,
WebSpotlightModels,
WorkflowModels
} from '../models';
import {
Expand Down Expand Up @@ -135,7 +136,10 @@ import {
CheckEnvironmentValidationQuery,
ListEnvironmentValidationIssuesQuery,
GetPreviewConfigurationQuery,
ModifyPreviewConfigurationQuery
ModifyPreviewConfigurationQuery,
ActivateWebSpotlightQuery,
DeactivateWebSpotlightQuery,
CheckWebSpotlightStatusQuery
} from '../queries';
import { IMappingService } from '../services';
import { GetEnvironmentCloningStateQuery } from '../queries/environments';
Expand Down Expand Up @@ -733,4 +737,19 @@ export interface IManagementClient<TCancelToken> {
ModifyPreviewConfigurationQuery,
PreviewModels.IModifyPreviewConfigurationData
>;

/**
* Activates Web Spotlight
*/
activateWebSpotlight(): DataQuery<ActivateWebSpotlightQuery, WebSpotlightModels.IActivateWebSpotlightData>;

/**
* Deactivates Web Spotlight
*/
deactivateWebSpotlight(): DeactivateWebSpotlightQuery;

/**
* Checks Web Spotlight status
*/
checkWebSpotlightStatus(): CheckWebSpotlightStatusQuery;
}
24 changes: 22 additions & 2 deletions lib/client/management-client.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
LanguageVariantElementsBuilder,
PreviewModels,
ProjectUserModels,
SpaceModels
SpaceModels,
WebSpotlightModels
} from '../models';

import { IManagementClientConfig } from '../config';
Expand Down Expand Up @@ -139,7 +140,10 @@ import {
ViewSpaceQuery,
SpaceIdentifierQuery,
GetPreviewConfigurationQuery,
ModifyPreviewConfigurationQuery
ModifyPreviewConfigurationQuery,
ActivateWebSpotlightQuery,
DeactivateWebSpotlightQuery,
CheckWebSpotlightStatusQuery
} from '../queries';
import { sdkInfo } from '../sdk-info.generated';
import { ManagementQueryService, IMappingService, MappingService } from '../services';
Expand Down Expand Up @@ -1276,4 +1280,20 @@ export class ManagementClient implements IManagementClient<CancelToken> {
(config, queryService, identifier) => new ViewSpaceQuery(config, queryService, identifier)
);
}

activateWebSpotlight(): DataQuery<ActivateWebSpotlightQuery, WebSpotlightModels.IActivateWebSpotlightData> {
return new DataQuery<ActivateWebSpotlightQuery, WebSpotlightModels.IActivateWebSpotlightData>(
this.config,
this.queryService,
(config, queryService, data) => new ActivateWebSpotlightQuery(config, queryService, data)
);
}

deactivateWebSpotlight(): DeactivateWebSpotlightQuery {
return new DeactivateWebSpotlightQuery(this.config, this.queryService);
}

checkWebSpotlightStatus(): CheckWebSpotlightStatusQuery {
return new CheckWebSpotlightStatusQuery(this.config, this.queryService);
}
}
1 change: 1 addition & 0 deletions lib/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export * from './environment-contracts';
export * from './asset-rendition-contracts';
export * from './space-contracts';
export * from './preview-contracts';
export * from './web-spotlight-contracts';
8 changes: 8 additions & 0 deletions lib/contracts/web-spotlight-contracts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { SharedContracts } from './shared-contracts';

export namespace WebSpotlightContracts {
export interface IWebSpotlightStatus {
enabled: boolean;
root_type: SharedContracts.IIdReferenceContract | null;
}
}
12 changes: 7 additions & 5 deletions lib/mappers/base-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { SharedModels } from '../models';
import { BaseResponses } from '../responses';

export abstract class BaseMapper {

mapResponseDebug(
baseResponse: IResponse<any>
): BaseResponses.IContentManagementResponseDebug {
mapResponseDebug(baseResponse: IResponse<any>): BaseResponses.IContentManagementResponseDebug {
if (!baseResponse) {
throw Error(`Cannot map debug model from the response`);
}
Expand All @@ -30,8 +27,13 @@ export abstract class BaseMapper {
});
}

mapIdReference(rawReference: SharedContracts.IIdReferenceContract): SharedModels.IIdRefenceObject {
return {
id: rawReference.id
};
}

mapEmptyResponse(response: IResponse<void | any>): BaseResponses.EmptyContentManagementResponse {
return new BaseResponses.EmptyContentManagementResponse(this.mapResponseDebug(response), undefined, undefined);
}
}

1 change: 1 addition & 0 deletions lib/mappers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export * from './project-user-mapper';
export * from './asset-rendition-mapper';
export * from './space-mapper';
export * from './preview-mapper';
export * from './web-spotlight-mapper';
30 changes: 30 additions & 0 deletions lib/mappers/web-spotlight-mapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { IResponse } from '@kontent-ai/core-sdk';

import { WebSpotlightContracts } from '../contracts';
import { BaseMapper } from './base-mapper';
import { WebSpotlightResponses } from '../responses';
import { WebSpotlightModels } from '../models';

export class WebSpotlightMapper extends BaseMapper {
mapWebSpotlightStatusResponse(
response: IResponse<WebSpotlightContracts.IWebSpotlightStatus>
): WebSpotlightResponses.WebSpotlightStatusResponse {
return new WebSpotlightResponses.WebSpotlightStatusResponse(
super.mapResponseDebug(response),
response.data,
this.mapWebSpotlightStatus(response.data)
);
}

private mapWebSpotlightStatus(
rawData: WebSpotlightContracts.IWebSpotlightStatus
): WebSpotlightModels.WebSpotlightStatus {
return new WebSpotlightModels.WebSpotlightStatus({
_raw: rawData,
enabled: rawData.enabled,
rootType: rawData.root_type ? this.mapIdReference(rawData.root_type) : undefined
});
}
}

export const webSpotlightMapper = new WebSpotlightMapper();
12 changes: 12 additions & 0 deletions lib/models/content-management-api-endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,18 @@ export class ContentManagementApiEndpoints {
return `${this.getEnvironmentsPath()}/spaces/${identifier.getParamValue()}`;
}

activateWebSpotlight(): string {
return `${this.getEnvironmentsPath()}/web-spotlight/activate`;
}

deactivateWebSpotlight(): string {
return `${this.getEnvironmentsPath()}/web-spotlight/deactivate`;
}

checkWebSpotlightStatus(): string {
return `${this.getEnvironmentsPath()}/web-spotlight/status`;
}

private getSubscriptionPath(): string {
if (!this.subscriptionId) {
throw Error(`SubscriptionId was not provided in client configuration`);
Expand Down
1 change: 1 addition & 0 deletions lib/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ export * from './environments/environment.models';
export * from './assets/asset-elements.builder';
export * from './spaces/space.models';
export * from './preview/preview.models';
export * from './web-spotlight/web-spotlight.models';
43 changes: 14 additions & 29 deletions lib/models/shared/shared-models.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,40 @@

export namespace SharedModels {

export interface IBaseModel<TContract> {
_raw: TContract;
}

export class Pagination {
constructor(
public continuationToken: string | null,
public nextPage: string | null
) { }
constructor(public continuationToken: string | null, public nextPage: string | null) {}
}

export class ValidationError {
public message!: string;

constructor(
data: {
message: string
}
) {
constructor(data: { message: string }) {
Object.assign(this, data);
}
}

export class ContentManagementBaseKontentError {

public validationErrors: ValidationError[];
public message: string;
public requestId: string;
public errorCode: number;
public originalError: any;

constructor(data:
{
message: string;
requestId: string;
errorCode: number;
originalError: any;
validationErrors: ValidationError[]
}
) {
constructor(data: {
message: string;
requestId: string;
errorCode: number;
originalError: any;
validationErrors: ValidationError[];
}) {
this.validationErrors = data.validationErrors;
this.message = data.message;
this.requestId = data.requestId;
this.errorCode = data.errorCode;
this.originalError = data.originalError;
}

}

export interface IReferenceObject {
Expand All @@ -56,18 +43,16 @@ export namespace SharedModels {
externalId?: string;
}

export interface IIdRefenceObject {
id: string;
}

export class ReferenceObject implements IReferenceObject {
public id?: string;
public codename?: string;
public externalId?: string;

constructor(
data: {
id?: string;
codename?: string;
externalId?: string;
}
) {
constructor(data: { id?: string; codename?: string; externalId?: string }) {
Object.assign(this, data);
}
}
Expand Down
24 changes: 24 additions & 0 deletions lib/models/web-spotlight/web-spotlight.models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { SharedModels } from '../shared/shared-models';
import { SharedContracts, WebSpotlightContracts } from '../../contracts';

export namespace WebSpotlightModels {
export class WebSpotlightStatus implements SharedModels.IBaseModel<WebSpotlightContracts.IWebSpotlightStatus> {
public enabled: boolean;
public rootType?: SharedModels.IIdRefenceObject;
public _raw: WebSpotlightContracts.IWebSpotlightStatus;

constructor(data: {
enabled: boolean;
rootType?: SharedModels.IIdRefenceObject;
_raw: WebSpotlightContracts.IWebSpotlightStatus;
}) {
this.enabled = data.enabled;
this.rootType = data.rootType;
this._raw = data._raw;
}
}

export interface IActivateWebSpotlightData {
root_type: SharedContracts.IReferenceObjectContract | null;
}
}
1 change: 1 addition & 0 deletions lib/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export * from './asset-renditions';
export * from './spaces';
export * from './environments';
export * from './preview';
export * from './web-spotlight';
23 changes: 23 additions & 0 deletions lib/queries/web-spotlight/activate-web-spotlight-query.class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { WebSpotlightResponses } from '../../responses';
import { IManagementClientConfig } from '../../config';
import { ManagementQueryService } from '../../services';
import { BaseQuery } from '../base-query';
import { WebSpotlightModels } from '../../models';

export class ActivateWebSpotlightQuery extends BaseQuery<WebSpotlightResponses.WebSpotlightStatusResponse> {
constructor(
protected config: IManagementClientConfig,
protected queryService: ManagementQueryService,
public data: WebSpotlightModels.IActivateWebSpotlightData
) {
super(config, queryService);
}

toPromise(): Promise<WebSpotlightResponses.WebSpotlightStatusResponse> {
return this.queryService.activateWebSpotlightAsync(this.getUrl(), this.queryConfig, this.data);
}

protected getAction(): string {
return this.apiEndpoints.activateWebSpotlight();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { WebSpotlightResponses } from '../../responses';
import { IManagementClientConfig } from '../../config';
import { ManagementQueryService } from '../../services';
import { BaseQuery } from '../base-query';

export class CheckWebSpotlightStatusQuery extends BaseQuery<WebSpotlightResponses.WebSpotlightStatusResponse> {
constructor(protected config: IManagementClientConfig, protected queryService: ManagementQueryService) {
super(config, queryService);
}

toPromise(): Promise<WebSpotlightResponses.WebSpotlightStatusResponse> {
return this.queryService.checkWebSpotlightStatusAsync(this.getUrl(), this.queryConfig);
}

protected getAction(): string {
return this.apiEndpoints.checkWebSpotlightStatus();
}
}
18 changes: 18 additions & 0 deletions lib/queries/web-spotlight/deactivate-web-spotlight-query.class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { WebSpotlightResponses } from '../../responses';
import { IManagementClientConfig } from '../../config';
import { ManagementQueryService } from '../../services';
import { BaseQuery } from '../base-query';

export class DeactivateWebSpotlightQuery extends BaseQuery<WebSpotlightResponses.WebSpotlightStatusResponse> {
constructor(protected config: IManagementClientConfig, protected queryService: ManagementQueryService) {
super(config, queryService);
}

toPromise(): Promise<WebSpotlightResponses.WebSpotlightStatusResponse> {
return this.queryService.deactivateWebSpotlightAsync(this.getUrl(), this.queryConfig);
}

protected getAction(): string {
return this.apiEndpoints.deactivateWebSpotlight();
}
}
3 changes: 3 additions & 0 deletions lib/queries/web-spotlight/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './activate-web-spotlight-query.class';
export * from './deactivate-web-spotlight-query.class';
export * from './check-web-spotlight-status-query.class';
1 change: 1 addition & 0 deletions lib/responses/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export * from './asset-renditions/asset-rendition-responses';
export * from './spaces/space-responses';
export * from './environments/environment-responses';
export * from './preview/preview-responses';
export * from './web-spotlight/web-spotlight-responses';
18 changes: 18 additions & 0 deletions lib/responses/web-spotlight/web-spotlight-responses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { WebSpotlightContracts } from '../../contracts';
import { WebSpotlightModels } from '../../models';
import { BaseResponses } from '../base-responses';

export namespace WebSpotlightResponses {
export class WebSpotlightStatusResponse extends BaseResponses.BaseContentManagementResponse<
WebSpotlightContracts.IWebSpotlightStatus,
WebSpotlightModels.WebSpotlightStatus
> {
constructor(
debug: BaseResponses.IContentManagementResponseDebug,
rawData: WebSpotlightContracts.IWebSpotlightStatus,
data: WebSpotlightModels.WebSpotlightStatus
) {
super(debug, rawData, data);
}
}
}
Loading

0 comments on commit 4070892

Please sign in to comment.