/
UIKitInteractionResponder.ts
75 lines (61 loc) · 2.84 KB
/
UIKitInteractionResponder.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import type { Omit } from '../../lib/utils';
import type { IUIKitErrorInteractionParam } from '../accessors/IUIController';
import type { IUIKitContextualBarResponse, IUIKitErrorResponse, IUIKitModalResponse, IUIKitResponse } from './IUIKitInteractionType';
import { UIKitInteractionType } from './IUIKitInteractionType';
import type { IUIKitSurface } from './IUIKitSurface';
import type { IUIKitBaseIncomingInteraction } from './UIKitIncomingInteractionTypes';
import { formatContextualBarInteraction, formatModalInteraction } from './UIKitInteractionPayloadFormatter';
export type IUIKitModalViewParam = Omit<IUIKitSurface, 'appId' | 'id' | 'type'> & Partial<Pick<IUIKitSurface, 'id'>>;
export type IUIKitContextualBarViewParam = Omit<IUIKitSurface, 'appId' | 'id' | 'type'> & Partial<Pick<IUIKitSurface, 'id'>>;
export class UIKitInteractionResponder {
constructor(private readonly baseContext: IUIKitBaseIncomingInteraction) {}
public successResponse(): IUIKitResponse {
return {
success: true,
};
}
public errorResponse(): IUIKitResponse {
return {
success: false,
};
}
public openModalViewResponse(viewData: IUIKitModalViewParam): IUIKitModalResponse {
const { appId, triggerId } = this.baseContext;
return {
success: true,
...formatModalInteraction(viewData, { appId, triggerId, type: UIKitInteractionType.MODAL_OPEN }),
};
}
public updateModalViewResponse(viewData: IUIKitModalViewParam): IUIKitModalResponse {
const { appId, triggerId } = this.baseContext;
return {
success: true,
...formatModalInteraction(viewData, { appId, triggerId, type: UIKitInteractionType.MODAL_UPDATE }),
};
}
public openContextualBarViewResponse(viewData: IUIKitContextualBarViewParam): IUIKitContextualBarResponse {
const { appId, triggerId } = this.baseContext;
return {
success: true,
...formatContextualBarInteraction(viewData, { appId, triggerId, type: UIKitInteractionType.CONTEXTUAL_BAR_OPEN }),
};
}
public updateContextualBarViewResponse(viewData: IUIKitContextualBarViewParam): IUIKitContextualBarResponse {
const { appId, triggerId } = this.baseContext;
return {
success: true,
...formatContextualBarInteraction(viewData, { appId, triggerId, type: UIKitInteractionType.CONTEXTUAL_BAR_UPDATE }),
};
}
public viewErrorResponse(errorInteraction: IUIKitErrorInteractionParam): IUIKitErrorResponse {
const { appId, triggerId } = this.baseContext;
return {
appId,
triggerId,
success: false,
type: UIKitInteractionType.ERRORS,
viewId: errorInteraction.viewId,
errors: errorInteraction.errors,
};
}
}