Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const runHandler = (handler: Function, defaultResult: any, handlerArg?: any) =>
.catch(handleHandlerError)
}

export default function createApp(channel: Channel): AppConfigAPI {
export default function createApp(channel: Channel): AppConfigAPI<KeyValueMap> {
const handlers: { [key: string]: any } = {
[HOOK_STAGE_PRE_INSTALL]: null,
[HOOK_STAGE_POST_INSTALL]: null,
Expand Down Expand Up @@ -105,7 +105,7 @@ export default function createApp(channel: Channel): AppConfigAPI {
getCurrentState() {
return channel.call('callAppMethod', 'getCurrentState') as Promise<AppState | null>
},
onConfigure(handler: OnConfigureHandler) {
onConfigure(handler: OnConfigureHandler<KeyValueMap>) {
setHandler(HOOK_STAGE_PRE_INSTALL, handler)
},
onConfigurationCompleted(handler: (err: null | { message: string }) => void) {
Expand Down
2 changes: 1 addition & 1 deletion lib/types/api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ export type ConfigAppSDK<InstallationParameters extends KeyValueMap = KeyValueMa
> & {
/** A set of IDs actual for the app */
ids: Omit<IdsAPI, EntryScopedIds | 'app'> & { app: string }
app: AppConfigAPI
app: AppConfigAPI<InstallationParameters>
}

export type KnownAppSDK<
Expand Down
14 changes: 8 additions & 6 deletions lib/types/app.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@ export interface AppState {
EditorInterface: Record<ContentType['sys']['id'], AppStateEditorInterfaceItem>
}

export type OnConfigureHandlerReturn =
| { parameters?: KeyValueMap | null; targetState?: AppState | null }
export type OnConfigureHandlerReturn<InstallationParameters extends KeyValueMap> =
| { parameters?: InstallationParameters | null; targetState?: AppState | null }
| false
export type OnConfigureHandler = () => OnConfigureHandlerReturn | Promise<OnConfigureHandlerReturn>
export type OnConfigureHandler<InstallationParameters extends KeyValueMap> = () =>
| OnConfigureHandlerReturn<InstallationParameters>
| Promise<OnConfigureHandlerReturn<InstallationParameters>>

export interface AppConfigAPI {
export interface AppConfigAPI<InstallationParameters extends KeyValueMap> {
/** Tells the web app that the app is loaded */
setReady: () => Promise<void>
/** Returns true if an App is installed */
isInstalled: () => Promise<boolean>
/** Returns current state of an App */
getCurrentState: () => Promise<AppState | null>
/** Returns parameters of an App, null otherwise */
getParameters: <T extends KeyValueMap = KeyValueMap>() => Promise<null | T>
getParameters: () => Promise<null | InstallationParameters>
/** Registers a handler to be called to produce parameters for an App */
onConfigure: (handler: OnConfigureHandler) => void
onConfigure: (handler: OnConfigureHandler<InstallationParameters>) => void
/** Registers a handler to be called once configuration was finished */
onConfigurationCompleted: (handler: (err: null | { message: string }) => void) => void
}