-
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.
Merge pull request #164 from kontent-ai/custom-apps
feat: implements support for custom apps API
- Loading branch information
Showing
32 changed files
with
842 additions
and
20 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
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[]; | ||
} | ||
} |
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,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(); |
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,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'>; | ||
}; | ||
} |
Oops, something went wrong.