-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds support for 'getPreviewConfiguration' API endpoint (#95)
- Loading branch information
Showing
19 changed files
with
291 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
lib/queries/preview/get-preview-configuration-query.class.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
lib/queries/preview/modify-preview-configuration-query.class.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.