|
| 1 | +import { HostEvent } from '../../types'; |
| 2 | + |
| 3 | +export enum EmbedApiEvent { |
| 4 | + addVizToPinboard = 'addVizToPinboard', |
| 5 | + saveAnswer = 'saveAnswer', |
| 6 | + getA3AnalysisColumns = 'getA3AnalysisColumns', |
| 7 | + getPinboardTabInfo = 'getPinboardTabInfo', |
| 8 | + getDiscoverabilityStatus = 'getDiscoverabilityStatus', |
| 9 | + getAvailableEmbedApis = 'getAvailableEmbedApis', |
| 10 | + getAnswerPageConfig = 'getAnswerPageConfig', |
| 11 | + getPinboardPageConfig = 'getPinboardPageConfig', |
| 12 | + embedApiEventNotFound = 'embedApiEventNotFound', |
| 13 | +} |
| 14 | + |
| 15 | +export type EmbedApiContractBase = { |
| 16 | + [EmbedApiEvent.addVizToPinboard]: { |
| 17 | + request: { |
| 18 | + vizId?: string; |
| 19 | + newVizName: string; |
| 20 | + newVizDescription?: string; |
| 21 | + pinboardId?: string; |
| 22 | + tabId?: string; |
| 23 | + newPinboardName?: string; |
| 24 | + newTabName?: string; |
| 25 | + pinFromStore?: boolean; |
| 26 | + }; |
| 27 | + response: { |
| 28 | + pinboardId: string extends string ? null : string; |
| 29 | + tabId: string; |
| 30 | + vizId: string; |
| 31 | + errors?: any; |
| 32 | + }; |
| 33 | + }; |
| 34 | + [EmbedApiEvent.saveAnswer]: { |
| 35 | + request: { |
| 36 | + name: string; |
| 37 | + description: string; |
| 38 | + vizId: string; |
| 39 | + isDiscoverable?: boolean; |
| 40 | + }; |
| 41 | + response: any; |
| 42 | + }; |
| 43 | + [EmbedApiEvent.getA3AnalysisColumns]: { |
| 44 | + request: { |
| 45 | + vizId: string; |
| 46 | + }; |
| 47 | + response: { |
| 48 | + data?: any; |
| 49 | + errors?: any; |
| 50 | + }; |
| 51 | + }; |
| 52 | + [EmbedApiEvent.getPinboardTabInfo]: { |
| 53 | + request: any; |
| 54 | + response: any; |
| 55 | + }; |
| 56 | + [EmbedApiEvent.getDiscoverabilityStatus]: { |
| 57 | + request: any; |
| 58 | + response: { |
| 59 | + shouldShowDiscoverability: boolean; |
| 60 | + isDiscoverabilityCheckboxUnselectedPerOrg: boolean; |
| 61 | + }; |
| 62 | + }; |
| 63 | + [EmbedApiEvent.getAvailableEmbedApis]: { |
| 64 | + request: any; |
| 65 | + response: { |
| 66 | + keys: string[]; |
| 67 | + }; |
| 68 | + }; |
| 69 | + [EmbedApiEvent.getAnswerPageConfig]: { |
| 70 | + request: { |
| 71 | + vizId: string; |
| 72 | + }; |
| 73 | + response: any; |
| 74 | + }; |
| 75 | + [EmbedApiEvent.getPinboardPageConfig]: { |
| 76 | + request: any; |
| 77 | + response: any; |
| 78 | + }; |
| 79 | + [EmbedApiEvent.embedApiEventNotFound]: { |
| 80 | + request: any; |
| 81 | + response: any; |
| 82 | + }; |
| 83 | +}; |
| 84 | + |
| 85 | +export type EmbedApiRequest<T extends keyof EmbedApiContractBase> = EmbedApiContractBase[T]['request']; |
| 86 | +export type EmbedApiResponse<T extends keyof EmbedApiContractBase> = EmbedApiContractBase[T]['response']; |
| 87 | + |
| 88 | +export type EmbedApiArrayResponse<ApiName extends keyof EmbedApiContractBase> = |
| 89 | + Promise<Array<{ |
| 90 | + redId?: string; |
| 91 | + value?: EmbedApiResponse<ApiName>; |
| 92 | + error?: any; |
| 93 | + }>> |
| 94 | + |
| 95 | +export type EmbedApiHostEventMapping = { |
| 96 | + [HostEvent.Pin]: EmbedApiEvent.addVizToPinboard; |
| 97 | + 'hostEventNotMapped': EmbedApiEvent.embedApiEventNotFound; |
| 98 | +} |
| 99 | + |
| 100 | +export type FlattenType<T> = T extends infer R ? { [K in keyof R]: R[K] } : never; |
| 101 | + |
| 102 | +export type HostEventRequest<HostEventT extends HostEvent> = |
| 103 | +HostEventT extends keyof EmbedApiHostEventMapping ? |
| 104 | +FlattenType<EmbedApiRequest<EmbedApiHostEventMapping[HostEventT]>> : any; |
| 105 | + |
| 106 | +export type HostEventResponse<HostEventT extends HostEvent> = |
| 107 | + HostEventT extends keyof EmbedApiHostEventMapping ? |
| 108 | + { |
| 109 | + value?: EmbedApiResponse<EmbedApiHostEventMapping[HostEventT]> |
| 110 | + error?: any; |
| 111 | + } |
| 112 | + : any; |
0 commit comments