Skip to content

Commit

Permalink
Merge pull request #164 from kontent-ai/custom-apps
Browse files Browse the repository at this point in the history
feat: implements support for custom apps API
  • Loading branch information
Enngage authored Feb 4, 2025
2 parents 3ed67ed + af0799e commit dd8e302
Show file tree
Hide file tree
Showing 32 changed files with 842 additions and 20 deletions.
36 changes: 35 additions & 1 deletion lib/client/imanagement-client.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ContentTypeModels,
ContentTypeSnippetElements,
ContentTypeSnippetModels,
CustomAppModels,
LanguageModels,
LanguageVariantElementsBuilder,
PreviewModels,
Expand Down Expand Up @@ -139,7 +140,13 @@ import {
ModifyPreviewConfigurationQuery,
ActivateWebSpotlightQuery,
DeactivateWebSpotlightQuery,
CheckWebSpotlightStatusQuery
CheckWebSpotlightStatusQuery,
AddCustomAppQuery,
CustomAppsIdentifierQuery,
GetCustomAppQuery,
ListCustomAppsQuery,
ModifyCustomAppQuery,
DeleteCustomAppQuery
} from '../queries';
import { IMappingService } from '../services';
import { GetEnvironmentCloningStateQuery } from '../queries/environments';
Expand Down Expand Up @@ -752,4 +759,31 @@ export interface IManagementClient<TCancelToken> {
* Checks Web Spotlight status
*/
checkWebSpotlightStatus(): CheckWebSpotlightStatusQuery;

/**
* Modify custom app
*/
modifyCustomApp(): CustomAppsIdentifierQuery<
DataQuery<ModifyCustomAppQuery, CustomAppModels.ModifyCustomAppOperation[]>
>;

/**
* Delete custom app
*/
deleteCustomApp(): CustomAppsIdentifierQuery<DeleteCustomAppQuery>;

/**
* Add custom app
*/
addCustomApp(): DataQuery<AddCustomAppQuery, CustomAppModels.IAddCustomAppData>;

/**
* List custom apps
*/
listCustomApps(): ListCustomAppsQuery;

/*
* Get custom app
*/
getCustomApp(): CustomAppsIdentifierQuery<GetCustomAppQuery>;
}
54 changes: 53 additions & 1 deletion lib/client/management-client.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
AssetElementsBuilder,
AssetRenditionModels,
CollectionModels,
CustomAppModels,
LanguageVariantElementsBuilder,
PreviewModels,
ProjectUserModels,
Expand Down Expand Up @@ -143,7 +144,13 @@ import {
ModifyPreviewConfigurationQuery,
ActivateWebSpotlightQuery,
DeactivateWebSpotlightQuery,
CheckWebSpotlightStatusQuery
CheckWebSpotlightStatusQuery,
ListCustomAppsQuery,
AddCustomAppQuery,
CustomAppsIdentifierQuery,
GetCustomAppQuery,
ModifyCustomAppQuery,
DeleteCustomAppQuery
} from '../queries';
import { sdkInfo } from '../sdk-info.generated';
import { ManagementQueryService, IMappingService, MappingService } from '../services';
Expand Down Expand Up @@ -1296,4 +1303,49 @@ export class ManagementClient implements IManagementClient<CancelToken> {
checkWebSpotlightStatus(): CheckWebSpotlightStatusQuery {
return new CheckWebSpotlightStatusQuery(this.config, this.queryService);
}

modifyCustomApp(): CustomAppsIdentifierQuery<
DataQuery<ModifyCustomAppQuery, CustomAppModels.ModifyCustomAppOperation[]>
> {
return new CustomAppsIdentifierQuery<
DataQuery<ModifyCustomAppQuery, CustomAppModels.ModifyCustomAppOperation[]>
>(
this.config,
this.queryService,
(config, queryService, identifier) =>
new DataQuery<ModifyCustomAppQuery, CustomAppModels.ModifyCustomAppOperation[]>(
config,
queryService,
(nConfig, nQueryService, data) => new ModifyCustomAppQuery(nConfig, nQueryService, identifier, data)
)
);
}

deleteCustomApp(): CustomAppsIdentifierQuery<DeleteCustomAppQuery> {
return new CustomAppsIdentifierQuery<DeleteCustomAppQuery>(
this.config,
this.queryService,
(config, queryService, identifier) => new DeleteCustomAppQuery(config, queryService, identifier)
);
}

addCustomApp(): DataQuery<AddCustomAppQuery, CustomAppModels.IAddCustomAppData> {
return new DataQuery<AddCustomAppQuery, CustomAppModels.IAddCustomAppData>(
this.config,
this.queryService,
(config, queryService, data) => new AddCustomAppQuery(config, queryService, data)
);
}

listCustomApps(): ListCustomAppsQuery {
return new ListCustomAppsQuery(this.config, this.queryService);
}

getCustomApp(): CustomAppsIdentifierQuery<GetCustomAppQuery> {
return new CustomAppsIdentifierQuery<GetCustomAppQuery>(
this.config,
this.queryService,
(config, queryService, identifier) => new GetCustomAppQuery(config, queryService, identifier)
);
}
}
11 changes: 11 additions & 0 deletions lib/contracts/custom-apps-contracts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { SharedContracts } from './shared-contracts';

export namespace CustomAppsContracts {
export interface ICustomAppContract {
name: string;
codename: string;
source_url: string;
config: string | null;
allowed_roles?: SharedContracts.ICodenameIdReferenceContract[];
}
}
1 change: 1 addition & 0 deletions lib/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export * from './asset-rendition-contracts';
export * from './space-contracts';
export * from './preview-contracts';
export * from './web-spotlight-contracts';
export * from './custom-apps-contracts';
56 changes: 56 additions & 0 deletions lib/mappers/custom-app-mapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { IResponse } from '@kontent-ai/core-sdk';
import { CustomAppsContracts } from '../contracts';
import { CustomAppModels } from '../models';
import { CustomAppsResponses } from '../responses';
import { BaseMapper } from './base-mapper';

export class CustomAppMapper extends BaseMapper {
mapGetCustomAppResponse(
response: IResponse<CustomAppsContracts.ICustomAppContract>
): CustomAppsResponses.GetCustomAppResponse {
return new CustomAppsResponses.GetCustomAppResponse(
super.mapResponseDebug(response),
response.data,
this.mapCustomApp(response.data)
);
}

mapListCustomAppsResponse(
response: IResponse<CustomAppsContracts.ICustomAppContract[]>
): CustomAppsResponses.ListCustomAppsResponse {
return new CustomAppsResponses.ListCustomAppsResponse(
super.mapResponseDebug(response),
response.data,
response.data.map((m) => this.mapCustomApp(m))
);
}

mapModifyCustomAppResponse(
response: IResponse<CustomAppsContracts.ICustomAppContract>
): CustomAppsResponses.ModifyCustomAppResponse {
return new CustomAppsResponses.ModifyCustomAppResponse(
super.mapResponseDebug(response),
response.data,
this.mapCustomApp(response.data)
);
}

mapAddCustomAppResponse(
response: IResponse<CustomAppsContracts.ICustomAppContract>
): CustomAppsResponses.AddCustomAppResponse {
return new CustomAppsResponses.AddCustomAppResponse(
super.mapResponseDebug(response),
response.data,
this.mapCustomApp(response.data)
);
}

mapCustomApp(rawCustomApp: CustomAppsContracts.ICustomAppContract): CustomAppModels.CustomApp {
return new CustomAppModels.CustomApp({
...rawCustomApp,
_raw: rawCustomApp
});
}
}

export const customAppMapper = new CustomAppMapper();
1 change: 1 addition & 0 deletions lib/mappers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export * from './asset-rendition-mapper';
export * from './space-mapper';
export * from './preview-mapper';
export * from './web-spotlight-mapper';
export * from './custom-app-mapper';
20 changes: 20 additions & 0 deletions lib/models/content-management-api-endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,26 @@ export class ContentManagementApiEndpoints {
return `${this.getEnvironmentsPath()}/types/${identifier.getParamValue()}`;
}

addCustomApp(): string {
return `${this.getEnvironmentsPath()}/custom-apps`;
}

modifyCustomApp(identifier: Identifiers.CustomAppIdentifier): string {
return `${this.getEnvironmentsPath()}/custom-apps/${identifier.getParamValue()}`;
}

deleteCustomApp(identifier: Identifiers.CustomAppIdentifier): string {
return `${this.getEnvironmentsPath()}/custom-apps/${identifier.getParamValue()}`;
}

getCustomApp(identifier: Identifiers.CustomAppIdentifier): string {
return `${this.getEnvironmentsPath()}/custom-apps/${identifier.getParamValue()}`;
}

listCustomApps(): string {
return `${this.getEnvironmentsPath()}/custom-apps`;
}

addTaxonomy(): string {
return `${this.getEnvironmentsPath()}/taxonomies`;
}
Expand Down
67 changes: 67 additions & 0 deletions lib/models/custom-apps/custom-app.models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { CustomAppsContracts, SharedContracts } from '../../contracts';
import { SharedModels } from '../shared/shared-models';

export namespace CustomAppModels {
export class CustomApp implements SharedModels.IBaseModel<CustomAppsContracts.ICustomAppContract> {
public name: string;
public codename: string;
public source_url: string;
public config: string | null;
public allowed_roles?: SharedContracts.ICodenameIdReferenceContract[];
public _raw!: CustomAppsContracts.ICustomAppContract;

constructor(data: {
name: string;
codename: string;
source_url: string;
config: string | null;
allowed_roles?: SharedContracts.ICodenameIdReferenceContract[];
_raw: CustomAppsContracts.ICustomAppContract;
}) {
this.name = data.name;
this.codename = data.codename;
this._raw = data._raw;
this.source_url = data.source_url;
this.config = data.config;
}
}

export interface IAddCustomAppData {
name: string;
codename: string;
source_url: string;
config?: string | null;
allowed_roles?: SharedContracts.ICodenameIdReferenceContract[];
}

export type ModifyCustomAppPropertyName = 'name' | 'source_url' | 'config' | 'allowed_roles';

export type ModifyCustomAppOperation =
| {
op: 'addInto';
value: SharedContracts.IReferenceObjectContract;
property_name: Extract<ModifyCustomAppPropertyName, 'allowed_roles'>;
}
| (
| {
op: 'replace';
value: SharedContracts.IReferenceObjectContract;
property_name: Extract<ModifyCustomAppPropertyName, 'allowed_roles'>;
}
| {
op: 'replace';
value: string;
property_name: Extract<ModifyCustomAppPropertyName, 'name' | 'source_url'>;
}
| {
op: 'replace';
value: string | null;
property_name: Extract<ModifyCustomAppPropertyName, 'config'>;
}
)
| {
op: 'remove';
value: SharedContracts.IReferenceObjectContract;
property_name: Extract<ModifyCustomAppPropertyName, 'allowed_roles'>;
};
}
Loading

0 comments on commit dd8e302

Please sign in to comment.