@thoughtspot/visual-embed-sdk 1.41.0-pre-render-1 → 1.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. package/cjs/package.json +3 -3
  2. package/cjs/src/embed/app.d.ts +6 -1
  3. package/cjs/src/embed/app.d.ts.map +1 -1
  4. package/cjs/src/embed/app.js +19 -1
  5. package/cjs/src/embed/app.js.map +1 -1
  6. package/cjs/src/embed/app.spec.js +60 -3
  7. package/cjs/src/embed/app.spec.js.map +1 -1
  8. package/cjs/src/embed/bodyless-conversation.d.ts +0 -1
  9. package/cjs/src/embed/bodyless-conversation.d.ts.map +1 -1
  10. package/cjs/src/embed/bodyless-conversation.js +3 -7
  11. package/cjs/src/embed/bodyless-conversation.js.map +1 -1
  12. package/cjs/src/embed/conversation.d.ts +0 -1
  13. package/cjs/src/embed/conversation.d.ts.map +1 -1
  14. package/cjs/src/embed/conversation.js +2 -7
  15. package/cjs/src/embed/conversation.js.map +1 -1
  16. package/cjs/src/embed/liveboard.d.ts +0 -1
  17. package/cjs/src/embed/liveboard.d.ts.map +1 -1
  18. package/cjs/src/embed/liveboard.js +4 -27
  19. package/cjs/src/embed/liveboard.js.map +1 -1
  20. package/cjs/src/embed/liveboard.spec.js +25 -31
  21. package/cjs/src/embed/liveboard.spec.js.map +1 -1
  22. package/cjs/src/embed/sage.d.ts +0 -1
  23. package/cjs/src/embed/sage.d.ts.map +1 -1
  24. package/cjs/src/embed/sage.js +6 -10
  25. package/cjs/src/embed/sage.js.map +1 -1
  26. package/cjs/src/embed/search-bar.d.ts +0 -1
  27. package/cjs/src/embed/search-bar.d.ts.map +1 -1
  28. package/cjs/src/embed/search-bar.js +7 -11
  29. package/cjs/src/embed/search-bar.js.map +1 -1
  30. package/cjs/src/embed/search.d.ts +0 -1
  31. package/cjs/src/embed/search.d.ts.map +1 -1
  32. package/cjs/src/embed/search.js +8 -7
  33. package/cjs/src/embed/search.js.map +1 -1
  34. package/cjs/src/embed/ts-embed.d.ts +4 -6
  35. package/cjs/src/embed/ts-embed.d.ts.map +1 -1
  36. package/cjs/src/embed/ts-embed.js +20 -21
  37. package/cjs/src/embed/ts-embed.js.map +1 -1
  38. package/cjs/src/embed/ts-embed.spec.d.ts.map +1 -1
  39. package/cjs/src/embed/ts-embed.spec.js +122 -0
  40. package/cjs/src/embed/ts-embed.spec.js.map +1 -1
  41. package/cjs/src/errors.d.ts +10 -0
  42. package/cjs/src/errors.d.ts.map +1 -1
  43. package/cjs/src/errors.js +11 -1
  44. package/cjs/src/errors.js.map +1 -1
  45. package/cjs/src/index.d.ts +2 -2
  46. package/cjs/src/index.d.ts.map +1 -1
  47. package/cjs/src/index.js +3 -1
  48. package/cjs/src/index.js.map +1 -1
  49. package/cjs/src/react/index.d.ts +1 -1
  50. package/cjs/src/react/index.d.ts.map +1 -1
  51. package/cjs/src/react/index.js +2 -1
  52. package/cjs/src/react/index.js.map +1 -1
  53. package/cjs/src/types.d.ts +135 -17
  54. package/cjs/src/types.d.ts.map +1 -1
  55. package/cjs/src/types.js +40 -21
  56. package/cjs/src/types.js.map +1 -1
  57. package/cjs/src/utils/custom-actions.d.ts +12 -0
  58. package/cjs/src/utils/custom-actions.d.ts.map +1 -0
  59. package/cjs/src/utils/custom-actions.js +180 -0
  60. package/cjs/src/utils/custom-actions.js.map +1 -0
  61. package/cjs/src/utils/custom-actions.spec.d.ts +2 -0
  62. package/cjs/src/utils/custom-actions.spec.d.ts.map +1 -0
  63. package/cjs/src/utils/custom-actions.spec.js +399 -0
  64. package/cjs/src/utils/custom-actions.spec.js.map +1 -0
  65. package/cjs/src/utils/processData.d.ts.map +1 -1
  66. package/cjs/src/utils/processData.js +10 -0
  67. package/cjs/src/utils/processData.js.map +1 -1
  68. package/cjs/src/utils/processData.spec.js +11 -0
  69. package/cjs/src/utils/processData.spec.js.map +1 -1
  70. package/cjs/src/utils.d.ts +7 -0
  71. package/cjs/src/utils.d.ts.map +1 -1
  72. package/cjs/src/utils.js +11 -1
  73. package/cjs/src/utils.js.map +1 -1
  74. package/cjs/src/utils.spec.js +28 -0
  75. package/cjs/src/utils.spec.js.map +1 -1
  76. package/dist/{index-CmEQfuE3.js → index-B_mxAan8.js} +1 -1
  77. package/dist/src/embed/app.d.ts +6 -1
  78. package/dist/src/embed/app.d.ts.map +1 -1
  79. package/dist/src/embed/bodyless-conversation.d.ts +0 -1
  80. package/dist/src/embed/bodyless-conversation.d.ts.map +1 -1
  81. package/dist/src/embed/conversation.d.ts +0 -1
  82. package/dist/src/embed/conversation.d.ts.map +1 -1
  83. package/dist/src/embed/liveboard.d.ts +0 -1
  84. package/dist/src/embed/liveboard.d.ts.map +1 -1
  85. package/dist/src/embed/sage.d.ts +0 -1
  86. package/dist/src/embed/sage.d.ts.map +1 -1
  87. package/dist/src/embed/search-bar.d.ts +0 -1
  88. package/dist/src/embed/search-bar.d.ts.map +1 -1
  89. package/dist/src/embed/search.d.ts +0 -1
  90. package/dist/src/embed/search.d.ts.map +1 -1
  91. package/dist/src/embed/ts-embed.d.ts +4 -6
  92. package/dist/src/embed/ts-embed.d.ts.map +1 -1
  93. package/dist/src/embed/ts-embed.spec.d.ts.map +1 -1
  94. package/dist/src/errors.d.ts +10 -0
  95. package/dist/src/errors.d.ts.map +1 -1
  96. package/dist/src/index.d.ts +2 -2
  97. package/dist/src/index.d.ts.map +1 -1
  98. package/dist/src/react/index.d.ts +1 -1
  99. package/dist/src/react/index.d.ts.map +1 -1
  100. package/dist/src/types.d.ts +135 -17
  101. package/dist/src/types.d.ts.map +1 -1
  102. package/dist/src/utils/custom-actions.d.ts +12 -0
  103. package/dist/src/utils/custom-actions.d.ts.map +1 -0
  104. package/dist/src/utils/custom-actions.spec.d.ts +2 -0
  105. package/dist/src/utils/custom-actions.spec.d.ts.map +1 -0
  106. package/dist/src/utils/processData.d.ts.map +1 -1
  107. package/dist/src/utils.d.ts +7 -0
  108. package/dist/src/utils.d.ts.map +1 -1
  109. package/dist/tsembed-react.es.js +1704 -250
  110. package/dist/tsembed-react.js +1703 -249
  111. package/dist/tsembed.es.js +1704 -250
  112. package/dist/tsembed.js +1703 -249
  113. package/dist/visual-embed-sdk-react-full.d.ts +146 -31
  114. package/dist/visual-embed-sdk-react.d.ts +146 -31
  115. package/dist/visual-embed-sdk.d.ts +146 -31
  116. package/lib/package.json +3 -3
  117. package/lib/src/embed/app.d.ts +6 -1
  118. package/lib/src/embed/app.d.ts.map +1 -1
  119. package/lib/src/embed/app.js +19 -1
  120. package/lib/src/embed/app.js.map +1 -1
  121. package/lib/src/embed/app.spec.js +60 -3
  122. package/lib/src/embed/app.spec.js.map +1 -1
  123. package/lib/src/embed/bodyless-conversation.d.ts +0 -1
  124. package/lib/src/embed/bodyless-conversation.d.ts.map +1 -1
  125. package/lib/src/embed/bodyless-conversation.js +3 -7
  126. package/lib/src/embed/bodyless-conversation.js.map +1 -1
  127. package/lib/src/embed/conversation.d.ts +0 -1
  128. package/lib/src/embed/conversation.d.ts.map +1 -1
  129. package/lib/src/embed/conversation.js +2 -7
  130. package/lib/src/embed/conversation.js.map +1 -1
  131. package/lib/src/embed/liveboard.d.ts +0 -1
  132. package/lib/src/embed/liveboard.d.ts.map +1 -1
  133. package/lib/src/embed/liveboard.js +4 -27
  134. package/lib/src/embed/liveboard.js.map +1 -1
  135. package/lib/src/embed/liveboard.spec.js +25 -31
  136. package/lib/src/embed/liveboard.spec.js.map +1 -1
  137. package/lib/src/embed/sage.d.ts +0 -1
  138. package/lib/src/embed/sage.d.ts.map +1 -1
  139. package/lib/src/embed/sage.js +6 -10
  140. package/lib/src/embed/sage.js.map +1 -1
  141. package/lib/src/embed/search-bar.d.ts +0 -1
  142. package/lib/src/embed/search-bar.d.ts.map +1 -1
  143. package/lib/src/embed/search-bar.js +7 -11
  144. package/lib/src/embed/search-bar.js.map +1 -1
  145. package/lib/src/embed/search.d.ts +0 -1
  146. package/lib/src/embed/search.d.ts.map +1 -1
  147. package/lib/src/embed/search.js +8 -7
  148. package/lib/src/embed/search.js.map +1 -1
  149. package/lib/src/embed/ts-embed.d.ts +4 -6
  150. package/lib/src/embed/ts-embed.d.ts.map +1 -1
  151. package/lib/src/embed/ts-embed.js +20 -21
  152. package/lib/src/embed/ts-embed.js.map +1 -1
  153. package/lib/src/embed/ts-embed.spec.d.ts.map +1 -1
  154. package/lib/src/embed/ts-embed.spec.js +123 -1
  155. package/lib/src/embed/ts-embed.spec.js.map +1 -1
  156. package/lib/src/errors.d.ts +10 -0
  157. package/lib/src/errors.d.ts.map +1 -1
  158. package/lib/src/errors.js +10 -0
  159. package/lib/src/errors.js.map +1 -1
  160. package/lib/src/index.d.ts +2 -2
  161. package/lib/src/index.d.ts.map +1 -1
  162. package/lib/src/index.js +2 -2
  163. package/lib/src/index.js.map +1 -1
  164. package/lib/src/react/index.d.ts +1 -1
  165. package/lib/src/react/index.d.ts.map +1 -1
  166. package/lib/src/react/index.js +1 -1
  167. package/lib/src/react/index.js.map +1 -1
  168. package/lib/src/types.d.ts +135 -17
  169. package/lib/src/types.d.ts.map +1 -1
  170. package/lib/src/types.js +39 -20
  171. package/lib/src/types.js.map +1 -1
  172. package/lib/src/utils/custom-actions.d.ts +12 -0
  173. package/lib/src/utils/custom-actions.d.ts.map +1 -0
  174. package/lib/src/utils/custom-actions.js +175 -0
  175. package/lib/src/utils/custom-actions.js.map +1 -0
  176. package/lib/src/utils/custom-actions.spec.d.ts +2 -0
  177. package/lib/src/utils/custom-actions.spec.d.ts.map +1 -0
  178. package/lib/src/utils/custom-actions.spec.js +397 -0
  179. package/lib/src/utils/custom-actions.spec.js.map +1 -0
  180. package/lib/src/utils/processData.d.ts.map +1 -1
  181. package/lib/src/utils/processData.js +10 -0
  182. package/lib/src/utils/processData.js.map +1 -1
  183. package/lib/src/utils/processData.spec.js +11 -0
  184. package/lib/src/utils/processData.spec.js.map +1 -1
  185. package/lib/src/utils.d.ts +7 -0
  186. package/lib/src/utils.d.ts.map +1 -1
  187. package/lib/src/utils.js +9 -0
  188. package/lib/src/utils.js.map +1 -1
  189. package/lib/src/utils.spec.js +29 -1
  190. package/lib/src/utils.spec.js.map +1 -1
  191. package/lib/src/visual-embed-sdk.d.ts +147 -32
  192. package/package.json +3 -3
  193. package/src/embed/app.spec.ts +85 -3
  194. package/src/embed/app.ts +21 -0
  195. package/src/embed/bodyless-conversation.ts +3 -8
  196. package/src/embed/conversation.ts +2 -17
  197. package/src/embed/liveboard.spec.ts +35 -35
  198. package/src/embed/liveboard.ts +4 -32
  199. package/src/embed/sage.ts +7 -12
  200. package/src/embed/search-bar.tsx +7 -14
  201. package/src/embed/search.ts +7 -18
  202. package/src/embed/ts-embed.spec.ts +136 -2
  203. package/src/embed/ts-embed.ts +25 -28
  204. package/src/errors.ts +11 -0
  205. package/src/index.ts +4 -0
  206. package/src/react/index.tsx +1 -0
  207. package/src/types.ts +198 -76
  208. package/src/utils/custom-actions.spec.ts +431 -0
  209. package/src/utils/custom-actions.ts +217 -0
  210. package/src/utils/processData.spec.ts +12 -0
  211. package/src/utils/processData.ts +10 -0
  212. package/src/utils.spec.ts +34 -0
  213. package/src/utils.ts +10 -0
  214. package/dist/index-BDlM0f0T.js +0 -7371
  215. package/dist/index-D1pyb7RG.js +0 -7371
  216. package/dist/index-DeFzsyFF.js +0 -7371
  217. package/dist/index-Dpf0rd6w.js +0 -7371
  218. package/dist/index-UuEbsISo.js +0 -7447
  219. package/dist/index-e3Uw3YFO.js +0 -7371
  220. package/dist/index-k7pkZMhx.js +0 -7371
@@ -0,0 +1,431 @@
1
+ import { getCustomActions } from './custom-actions';
2
+ import { CustomAction, CustomActionsPosition, CustomActionTarget } from '../types';
3
+ import { logger } from './logger';
4
+
5
+ // Mock logger
6
+ jest.mock('./logger', () => ({
7
+ logger: {
8
+ warn: jest.fn(),
9
+ error: jest.fn(),
10
+ },
11
+ }));
12
+
13
+ describe('getCustomActions function', () => {
14
+ describe('Static getCustomActions method', () => {
15
+ test('should return empty result for empty array', () => {
16
+ const result = getCustomActions([]);
17
+ expect(result.actions).toEqual([]);
18
+ expect(result.errors).toEqual([]);
19
+ });
20
+
21
+ test('should return empty result for null/undefined input', () => {
22
+ const result1 = getCustomActions(null as any);
23
+ expect(result1.actions).toEqual([]);
24
+ expect(result1.errors).toEqual([]);
25
+
26
+ const result2 = getCustomActions(undefined as any);
27
+ expect(result2.actions).toEqual([]);
28
+ expect(result2.errors).toEqual([]);
29
+ });
30
+
31
+ test('should validate and return valid actions', () => {
32
+ const actions: CustomAction[] = [
33
+ {
34
+ name: 'Test Action',
35
+ id: 'test-id',
36
+ target: CustomActionTarget.LIVEBOARD,
37
+ position: CustomActionsPosition.PRIMARY,
38
+ },
39
+ ];
40
+ const result = getCustomActions(actions);
41
+
42
+ expect(result.actions).toEqual(actions);
43
+ expect(result.errors).toEqual([]);
44
+ });
45
+
46
+ test('should reject invalid actions and collect errors', () => {
47
+ const actions: CustomAction[] = [
48
+ {
49
+ name: 'Valid Action',
50
+ id: 'valid-id',
51
+ target: CustomActionTarget.LIVEBOARD,
52
+ position: CustomActionsPosition.PRIMARY,
53
+ },
54
+ {
55
+ name: 'Invalid Action',
56
+ id: 'invalid-id',
57
+ target: CustomActionTarget.SPOTTER,
58
+ position: CustomActionsPosition.PRIMARY, // Invalid for SPOTTER
59
+ },
60
+ ];
61
+ const result = getCustomActions(actions);
62
+
63
+ expect(result.actions).toEqual([actions[0]]);
64
+ expect(result.errors).toHaveLength(1);
65
+ expect(result.errors[0]).toContain("Position 'PRIMARY' is not supported for spotter-level custom actions. Supported positions: MENU, CONTEXTMENU");
66
+ });
67
+
68
+ test('should sort actions by name', () => {
69
+ const actions: CustomAction[] = [
70
+ {
71
+ name: 'Zebra Action',
72
+ id: 'zebra-id',
73
+ target: CustomActionTarget.LIVEBOARD,
74
+ position: CustomActionsPosition.PRIMARY,
75
+ },
76
+ {
77
+ name: 'Alpha Action',
78
+ id: 'alpha-id',
79
+ target: CustomActionTarget.LIVEBOARD,
80
+ position: CustomActionsPosition.MENU,
81
+ },
82
+ ];
83
+ const result = getCustomActions(actions);
84
+
85
+ expect(result.actions).toHaveLength(2);
86
+ expect(result.actions[0].name).toBe('Alpha Action');
87
+ expect(result.actions[1].name).toBe('Zebra Action');
88
+ });
89
+ });
90
+
91
+ describe('Input Validation', () => {
92
+ test('should return false for null action', () => {
93
+ const result = getCustomActions([null as any]);
94
+ expect(result.actions).toEqual([]);
95
+ expect(result.errors).toHaveLength(1);
96
+ expect(result.errors[0]).toContain('Custom Action Validation Error: Invalid action object provided');
97
+ });
98
+
99
+ test('should return false for undefined action', () => {
100
+ const result = getCustomActions([undefined as any]);
101
+ expect(result.actions).toEqual([]);
102
+ expect(result.errors).toHaveLength(1);
103
+ expect(result.errors[0]).toContain('Custom Action Validation Error: Invalid action object provided');
104
+ });
105
+
106
+ test('should return false for non-object action', () => {
107
+ const result = getCustomActions(['string' as any]);
108
+ expect(result.actions).toEqual([]);
109
+ expect(result.errors).toHaveLength(1);
110
+ expect(result.errors[0]).toContain('Custom Action Validation Error: Invalid action object provided');
111
+ });
112
+
113
+ test('should return false for action missing id', () => {
114
+ const action = {
115
+ name: 'Test Action',
116
+ target: CustomActionTarget.LIVEBOARD,
117
+ position: CustomActionsPosition.PRIMARY,
118
+ };
119
+ const result = getCustomActions([action as CustomAction]);
120
+ expect(result.actions).toEqual([]);
121
+ expect(result.errors).toHaveLength(1);
122
+ expect(result.errors[0]).toContain("Missing required fields: id");
123
+ });
124
+
125
+ test('should return false for action missing name', () => {
126
+ const action = {
127
+ id: 'test-id',
128
+ target: CustomActionTarget.LIVEBOARD,
129
+ position: CustomActionsPosition.PRIMARY,
130
+ };
131
+ const result = getCustomActions([action as CustomAction]);
132
+ expect(result.actions).toEqual([]);
133
+ expect(result.errors).toHaveLength(1);
134
+ expect(result.errors[0]).toContain("Missing required fields: name");
135
+ });
136
+
137
+ test('should return false for action missing target', () => {
138
+ const action = {
139
+ id: 'test-id',
140
+ name: 'Test Action',
141
+ position: CustomActionsPosition.PRIMARY,
142
+ };
143
+ const result = getCustomActions([action as CustomAction]);
144
+ expect(result.actions).toEqual([]);
145
+ expect(result.errors).toHaveLength(1);
146
+ expect(result.errors[0]).toContain("Missing required fields: target");
147
+ });
148
+
149
+ test('should return false for action missing position', () => {
150
+ const action = {
151
+ id: 'test-id',
152
+ name: 'Test Action',
153
+ target: CustomActionTarget.LIVEBOARD,
154
+ };
155
+ const result = getCustomActions([action as CustomAction]);
156
+ expect(result.actions).toEqual([]);
157
+ expect(result.errors).toHaveLength(1);
158
+ expect(result.errors[0]).toContain("Missing required fields: position");
159
+ });
160
+ });
161
+
162
+ describe('Target Type Validation', () => {
163
+ test('should reject unsupported target type', () => {
164
+ const action = {
165
+ id: 'test-id',
166
+ name: 'Test Action',
167
+ target: 'UNSUPPORTED' as any,
168
+ position: CustomActionsPosition.PRIMARY,
169
+ };
170
+ const result = getCustomActions([action]);
171
+ expect(result.actions).toEqual([]);
172
+ expect(result.errors).toHaveLength(1);
173
+ expect(result.errors[0]).toContain("Target type 'UNSUPPORTED' is not supported");
174
+ });
175
+
176
+ test('should accept LIVEBOARD target type', () => {
177
+ const action = {
178
+ id: 'test-id',
179
+ name: 'Test Action',
180
+ target: CustomActionTarget.LIVEBOARD,
181
+ position: CustomActionsPosition.PRIMARY,
182
+ };
183
+ const result = getCustomActions([action]);
184
+ expect(result.actions).toEqual([action]);
185
+ expect(result.errors).toEqual([]);
186
+ });
187
+
188
+ test('should accept VIZ target type', () => {
189
+ const action = {
190
+ id: 'test-id',
191
+ name: 'Test Action',
192
+ target: CustomActionTarget.VIZ,
193
+ position: CustomActionsPosition.MENU,
194
+ };
195
+ const result = getCustomActions([action]);
196
+ expect(result.actions).toEqual([action]);
197
+ expect(result.errors).toEqual([]);
198
+ });
199
+
200
+ test('should accept ANSWER target type', () => {
201
+ const action = {
202
+ id: 'test-id',
203
+ name: 'Test Action',
204
+ target: CustomActionTarget.ANSWER,
205
+ position: CustomActionsPosition.MENU,
206
+ };
207
+ const result = getCustomActions([action]);
208
+ expect(result.actions).toEqual([action]);
209
+ expect(result.errors).toEqual([]);
210
+ });
211
+
212
+ test('should accept SPOTTER target type', () => {
213
+ const action = {
214
+ id: 'test-id',
215
+ name: 'Test Action',
216
+ target: CustomActionTarget.SPOTTER,
217
+ position: CustomActionsPosition.MENU,
218
+ };
219
+ const result = getCustomActions([action]);
220
+ expect(result.actions).toEqual([action]);
221
+ expect(result.errors).toEqual([]);
222
+ });
223
+ });
224
+
225
+ describe('Position Validation', () => {
226
+ test('should reject invalid position for LIVEBOARD', () => {
227
+ const action = {
228
+ id: 'test-id',
229
+ name: 'Test Action',
230
+ target: CustomActionTarget.LIVEBOARD,
231
+ position: CustomActionsPosition.CONTEXTMENU, // Invalid for LIVEBOARD
232
+ };
233
+ const result = getCustomActions([action]);
234
+ expect(result.actions).toEqual([]);
235
+ expect(result.errors).toHaveLength(1);
236
+ expect(result.errors).toContain("Position 'CONTEXTMENU' is not supported for liveboard-level custom actions. Supported positions: PRIMARY, MENU");
237
+ });
238
+
239
+ test('should reject invalid position for SPOTTER', () => {
240
+ const action = {
241
+ id: 'test-id',
242
+ name: 'Test Action',
243
+ target: CustomActionTarget.SPOTTER,
244
+ position: CustomActionsPosition.PRIMARY, // Invalid for SPOTTER
245
+ };
246
+ const result = getCustomActions([action]);
247
+ expect(result.actions).toEqual([]);
248
+ expect(result.errors).toHaveLength(1);
249
+ expect(result.errors[0]).toContain("Position 'PRIMARY' is not supported for spotter-level custom actions. Supported positions: MENU, CONTEXTMENU");
250
+ });
251
+
252
+ test('should accept valid positions for LIVEBOARD', () => {
253
+ const primaryAction = {
254
+ id: 'primary-id',
255
+ name: 'Primary Action',
256
+ target: CustomActionTarget.LIVEBOARD,
257
+ position: CustomActionsPosition.PRIMARY,
258
+ };
259
+ const menuAction = {
260
+ id: 'menu-id',
261
+ name: 'Menu Action',
262
+ target: CustomActionTarget.LIVEBOARD,
263
+ position: CustomActionsPosition.MENU,
264
+ };
265
+ const result = getCustomActions([primaryAction, menuAction]);
266
+ expect(result.actions).toHaveLength(2);
267
+ expect(result.errors).toEqual([]);
268
+ });
269
+ });
270
+
271
+ describe('Metadata IDs Validation', () => {
272
+ test('should reject invalid metadata IDs for LIVEBOARD', () => {
273
+ const action = {
274
+ id: 'test-id',
275
+ name: 'Test Action',
276
+ target: CustomActionTarget.LIVEBOARD,
277
+ position: CustomActionsPosition.PRIMARY,
278
+ metadataIds: {
279
+ invalidId: 'some-value',
280
+ },
281
+ } as any;
282
+ const result = getCustomActions([action]);
283
+ expect(result.actions).toEqual([]);
284
+ expect(result.errors).toHaveLength(1);
285
+ expect(result.errors[0]).toContain("Invalid metadata IDs for liveboard-level custom actions: invalidId. Supported metadata IDs: liveboardIds");
286
+ });
287
+
288
+ test('should accept valid metadata IDs for LIVEBOARD', () => {
289
+ const action = {
290
+ id: 'test-id',
291
+ name: 'Test Action',
292
+ target: CustomActionTarget.LIVEBOARD,
293
+ position: CustomActionsPosition.PRIMARY,
294
+ metadataIds: {
295
+ liveboardIds: ['lb-1', 'lb-2'],
296
+ },
297
+ };
298
+ const result = getCustomActions([action]);
299
+ expect(result.actions).toEqual([action]);
300
+ expect(result.errors).toEqual([]);
301
+ });
302
+ });
303
+
304
+ describe('Data Model IDs Validation', () => {
305
+ test('should reject invalid data model IDs for VIZ', () => {
306
+ const action = {
307
+ id: 'test-id',
308
+ name: 'Test Action',
309
+ target: CustomActionTarget.VIZ,
310
+ position: CustomActionsPosition.MENU,
311
+ dataModelIds: {
312
+ invalidId: 'some-value',
313
+ },
314
+ } as any;
315
+ const result = getCustomActions([action]);
316
+ expect(result.actions).toEqual([]);
317
+ expect(result.errors).toHaveLength(1);
318
+ expect(result.errors[0]).toContain("Invalid data model IDs for viz-level custom actions: invalidId. Supported data model IDs: modelIds, modelColumnNames");
319
+ });
320
+
321
+ test('should accept valid data model IDs for VIZ', () => {
322
+ const action = {
323
+ id: 'test-id',
324
+ name: 'Test Action',
325
+ target: CustomActionTarget.VIZ,
326
+ position: CustomActionsPosition.MENU,
327
+ dataModelIds: {
328
+ modelIds: ['model-1'],
329
+ modelColumnNames: ['col-1'],
330
+ },
331
+ };
332
+ const result = getCustomActions([action]);
333
+ expect(result.actions).toEqual([action]);
334
+ expect(result.errors).toEqual([]);
335
+ });
336
+ });
337
+
338
+ describe('Field Validation', () => {
339
+ test('should reject invalid fields for LIVEBOARD', () => {
340
+ const action = {
341
+ id: 'test-id',
342
+ name: 'Test Action',
343
+ target: CustomActionTarget.LIVEBOARD,
344
+ position: CustomActionsPosition.PRIMARY,
345
+ invalidField: 'some-value',
346
+ };
347
+ const result = getCustomActions([action]);
348
+ expect(result.actions).toEqual([]);
349
+ expect(result.errors).toHaveLength(1);
350
+ expect(result.errors[0]).toContain("Invalid fields for liveboard-level custom actions: invalidField. Supported fields: name, id, position, target, metadataIds, orgIds, groupIds");
351
+ });
352
+
353
+ test('should accept valid fields for LIVEBOARD', () => {
354
+ const action = {
355
+ id: 'test-id',
356
+ name: 'Test Action',
357
+ target: CustomActionTarget.LIVEBOARD,
358
+ position: CustomActionsPosition.PRIMARY,
359
+ orgIds: ['org-1'],
360
+ groupIds: ['group-1'],
361
+ };
362
+ const result = getCustomActions([action]);
363
+ expect(result.actions).toEqual([action]);
364
+ expect(result.errors).toEqual([]);
365
+ });
366
+ });
367
+
368
+ describe('Duplicate ID Handling', () => {
369
+ test('should keep only the first action when duplicate IDs are found and report duplicate errors', () => {
370
+ const action1 = {
371
+ id: 'duplicate-id',
372
+ name: 'First Action',
373
+ target: CustomActionTarget.LIVEBOARD,
374
+ position: CustomActionsPosition.PRIMARY,
375
+ };
376
+ const action2 = {
377
+ id: 'duplicate-id',
378
+ name: 'Second Action',
379
+ target: CustomActionTarget.LIVEBOARD,
380
+ position: CustomActionsPosition.MENU,
381
+ };
382
+ const result = getCustomActions([action1, action2]);
383
+ expect(result.actions).toHaveLength(1);
384
+ expect(result.actions[0]).toEqual(action1);
385
+ expect(result.errors).toHaveLength(1);
386
+ expect(result.errors[0]).toContain("Duplicate custom action ID 'duplicate-id' found");
387
+ expect(result.errors[0]).toContain("Actions with names 'Second Action' will be ignored");
388
+ expect(result.errors[0]).toContain("Keeping 'First Action'");
389
+ });
390
+ });
391
+
392
+ describe('Complex Validation Scenarios', () => {
393
+ test('should handle multiple validation errors for a single action', () => {
394
+ const action = {
395
+ id: 'test-id',
396
+ name: 'Test Action',
397
+ target: CustomActionTarget.LIVEBOARD,
398
+ position: CustomActionsPosition.CONTEXTMENU, // Invalid position
399
+ metadataIds: {
400
+ invalidId: 'some-value', // Invalid metadata ID
401
+ },
402
+ invalidField: 'some-value', // Invalid field
403
+ } as any;
404
+ const result = getCustomActions([action]);
405
+ expect(result.actions).toEqual([]);
406
+ expect(result.errors).toHaveLength(3);
407
+ expect(result.errors).toContain("Position 'CONTEXTMENU' is not supported for liveboard-level custom actions. Supported positions: PRIMARY, MENU");
408
+ expect(result.errors).toContain("Invalid metadata IDs for liveboard-level custom actions: invalidId. Supported metadata IDs: liveboardIds");
409
+ expect(result.errors).toContain("Invalid fields for liveboard-level custom actions: invalidField. Supported fields: name, id, position, target, metadataIds, orgIds, groupIds");
410
+ });
411
+
412
+ test('should handle mix of valid and invalid actions', () => {
413
+ const validAction = {
414
+ id: 'valid-id',
415
+ name: 'Valid Action',
416
+ target: CustomActionTarget.LIVEBOARD,
417
+ position: CustomActionsPosition.PRIMARY,
418
+ };
419
+ const invalidAction = {
420
+ id: 'invalid-id',
421
+ name: 'Invalid Action',
422
+ target: CustomActionTarget.SPOTTER,
423
+ position: CustomActionsPosition.PRIMARY, // Invalid for SPOTTER
424
+ };
425
+ const result = getCustomActions([validAction, invalidAction]);
426
+ expect(result.actions).toEqual([validAction]);
427
+ expect(result.errors).toHaveLength(1);
428
+ expect(result.errors[0]).toContain("Position 'PRIMARY' is not supported for spotter-level custom actions. Supported positions: MENU, CONTEXTMENU");
429
+ });
430
+ });
431
+ });
@@ -0,0 +1,217 @@
1
+ import { CustomAction, CustomActionsPosition, CustomActionTarget } from '../types';
2
+ import { arrayIncludesString } from '../utils';
3
+ import sortBy from 'lodash/sortBy';
4
+ import { CUSTOM_ACTIONS_ERROR_MESSAGE } from '../errors';
5
+
6
+ export interface CustomActionsValidationResult {
7
+ actions: CustomAction[];
8
+ errors: string[];
9
+ }
10
+
11
+ type CustomActionValidation = {
12
+ isValid: boolean;
13
+ errors: string[];
14
+ };
15
+
16
+ /**
17
+ * Configuration for custom action validation rules.
18
+ * Defines allowed positions, metadata IDs, data model IDs, and fields for each target
19
+ * type.
20
+ *
21
+ */
22
+ const customActionValidationConfig: Record<CustomActionTarget, {
23
+ positions: string[];
24
+ allowedMetadataIds: string[];
25
+ allowedDataModelIds: string[];
26
+ allowedFields: string[];
27
+ }> = {
28
+ [CustomActionTarget.LIVEBOARD]: {
29
+ positions: [CustomActionsPosition.PRIMARY, CustomActionsPosition.MENU],
30
+ allowedMetadataIds: ['liveboardIds'],
31
+ allowedDataModelIds: [],
32
+ allowedFields: ['name', 'id', 'position', 'target', 'metadataIds', 'orgIds', 'groupIds'],
33
+ },
34
+ [CustomActionTarget.VIZ]: {
35
+ positions: [CustomActionsPosition.MENU, CustomActionsPosition.PRIMARY, CustomActionsPosition.CONTEXTMENU],
36
+ allowedMetadataIds: ['liveboardIds', 'vizIds', 'answerIds'],
37
+ allowedDataModelIds: ['modelIds', 'modelColumnNames'],
38
+ allowedFields: ['name', 'id', 'position', 'target', 'metadataIds', 'orgIds', 'groupIds', 'dataModelIds'],
39
+ },
40
+ [CustomActionTarget.ANSWER]: {
41
+ positions: [CustomActionsPosition.MENU, CustomActionsPosition.PRIMARY, CustomActionsPosition.CONTEXTMENU],
42
+ allowedMetadataIds: ['answerIds'],
43
+ allowedDataModelIds: ['modelIds', 'modelColumnNames'],
44
+ allowedFields: ['name', 'id', 'position', 'target', 'metadataIds', 'orgIds', 'groupIds', 'dataModelIds'],
45
+ },
46
+ [CustomActionTarget.SPOTTER]: {
47
+ positions: [CustomActionsPosition.MENU, CustomActionsPosition.CONTEXTMENU],
48
+ allowedMetadataIds: [],
49
+ allowedDataModelIds: ['modelIds'],
50
+ allowedFields: ['name', 'id', 'position', 'target', 'orgIds', 'groupIds', 'dataModelIds'],
51
+ },
52
+ };
53
+
54
+ /**
55
+ * Validates a single custom action based on its target type
56
+ * @param action - The custom action to validate
57
+ * @param primaryActionsPerTarget - Map to track primary actions per target
58
+ * @returns CustomActionValidation with isValid flag and reason string
59
+ *
60
+ * @hidden
61
+ */
62
+ const validateCustomAction = (action: CustomAction, primaryActionsPerTarget: Map<CustomActionTarget, CustomAction>): CustomActionValidation => {
63
+ const { id: actionId, target: targetType, position, metadataIds, dataModelIds } = action;
64
+
65
+ // Check if target type is supported
66
+ if (!customActionValidationConfig[targetType]) {
67
+ const errorMessage = CUSTOM_ACTIONS_ERROR_MESSAGE.UNSUPPORTED_TARGET(actionId, targetType);
68
+ return { isValid: false, errors: [errorMessage] };
69
+ }
70
+
71
+ const config = customActionValidationConfig[targetType];
72
+ const errors: string[] = [];
73
+
74
+ // Validate position
75
+ if (!arrayIncludesString(config.positions, position)) {
76
+ const supportedPositions = config.positions.join(', ');
77
+ errors.push(CUSTOM_ACTIONS_ERROR_MESSAGE.INVALID_POSITION(position, targetType, supportedPositions));
78
+ }
79
+
80
+ // Validate metadata IDs
81
+ if (metadataIds) {
82
+ const invalidMetadataIds = Object.keys(metadataIds).filter(
83
+ (key) => !arrayIncludesString(config.allowedMetadataIds, key)
84
+ );
85
+ if (invalidMetadataIds.length > 0) {
86
+ const supportedMetadataIds = config.allowedMetadataIds.length > 0 ? config.allowedMetadataIds.join(', ') : 'none';
87
+ errors.push(CUSTOM_ACTIONS_ERROR_MESSAGE.INVALID_METADATA_IDS(targetType, invalidMetadataIds, supportedMetadataIds));
88
+ }
89
+ }
90
+
91
+ // Validate data model IDs
92
+ if (dataModelIds) {
93
+ const invalidDataModelIds = Object.keys(dataModelIds).filter(
94
+ (key) => !arrayIncludesString(config.allowedDataModelIds, key)
95
+ );
96
+ if (invalidDataModelIds.length > 0) {
97
+ const supportedDataModelIds = config.allowedDataModelIds.length > 0 ? config.allowedDataModelIds.join(', ') : 'none';
98
+ errors.push(CUSTOM_ACTIONS_ERROR_MESSAGE.INVALID_DATA_MODEL_IDS(targetType, invalidDataModelIds, supportedDataModelIds));
99
+ }
100
+ }
101
+
102
+ // Validate allowed fields
103
+ const actionKeys = Object.keys(action);
104
+ const invalidFields = actionKeys.filter((key) => !arrayIncludesString(config.allowedFields, key));
105
+ if (invalidFields.length > 0) {
106
+ const supportedFields = config.allowedFields.join(', ');
107
+ errors.push(CUSTOM_ACTIONS_ERROR_MESSAGE.INVALID_FIELDS(targetType, invalidFields, supportedFields));
108
+ }
109
+
110
+ return {
111
+ isValid: errors.length === 0,
112
+ errors,
113
+ };
114
+ };
115
+
116
+ /**
117
+ * Validates basic action structure and required fields
118
+ * @param action - The action to validate
119
+ * @returns Object containing validation result and missing fields
120
+ *
121
+ * @hidden
122
+ */
123
+ const validateActionStructure = (action: any): { isValid: boolean; missingFields: string[] } => {
124
+ if (!action || typeof action !== 'object') {
125
+ return { isValid: false, missingFields: [] };
126
+ }
127
+
128
+ // Check for all missing required fields
129
+ const missingFields = ['id', 'name', 'target', 'position'].filter(field => !action[field]);
130
+ return { isValid: missingFields.length === 0, missingFields };
131
+ };
132
+
133
+ /**
134
+ * Checks for duplicate IDs among actions
135
+ * @param actions - Array of actions to check
136
+ * @returns Object containing filtered actions and duplicate errors
137
+ *
138
+ * @hidden
139
+ */
140
+ const filterDuplicateIds = (actions: CustomAction[]): { actions: CustomAction[]; errors: string[] } => {
141
+ const idMap = actions.reduce((map, action) => {
142
+ const list = map.get(action.id) || [];
143
+ list.push(action);
144
+ map.set(action.id, list);
145
+ return map;
146
+ }, new Map<string, CustomAction[]>());
147
+
148
+ const { actions: actionsWithUniqueIds, errors } = Array.from(idMap.entries()).reduce(
149
+ (acc, [id, actionsWithSameId]) => {
150
+ if (actionsWithSameId.length === 1) {
151
+ acc.actions.push(actionsWithSameId[0]);
152
+ } else {
153
+ // Keep the first action and add error for duplicates
154
+ acc.actions.push(actionsWithSameId[0]);
155
+ const duplicateNames = actionsWithSameId.slice(1).map(action => action.name);
156
+ acc.errors.push(CUSTOM_ACTIONS_ERROR_MESSAGE.DUPLICATE_IDS(id, duplicateNames, actionsWithSameId[0].name));
157
+ }
158
+ return acc;
159
+ },
160
+ { actions: [] as CustomAction[], errors: [] as string[] }
161
+ );
162
+
163
+ return { actions: actionsWithUniqueIds, errors };
164
+ };
165
+
166
+ /**
167
+ * Validates and processes custom actions
168
+ * @param customActions - Array of custom actions to validate
169
+ * @returns Object containing valid actions and any validation errors
170
+ */
171
+ export const getCustomActions = (customActions: CustomAction[]): CustomActionsValidationResult => {
172
+ const errors: string[] = [];
173
+ const primaryActionsPerTarget = new Map<CustomActionTarget, CustomAction>();
174
+
175
+ if (!customActions || !Array.isArray(customActions)) {
176
+ return { actions: [], errors: [] };
177
+ }
178
+
179
+ // Step 1: Handle invalid actions first (null, undefined, missing required
180
+ // fields)
181
+ const validActions = customActions.filter(action => {
182
+ const validation = validateActionStructure(action);
183
+ if (!validation.isValid) {
184
+ if (!action || typeof action !== 'object') {
185
+ errors.push(CUSTOM_ACTIONS_ERROR_MESSAGE.INVALID_ACTION_OBJECT);
186
+ } else {
187
+ errors.push(CUSTOM_ACTIONS_ERROR_MESSAGE.MISSING_REQUIRED_FIELDS((action as any).id, validation.missingFields));
188
+ }
189
+ return false;
190
+ }
191
+ return true;
192
+ });
193
+
194
+ // Step 2: Check for duplicate IDs among valid actions
195
+ const { actions: actionsWithUniqueIds, errors: duplicateErrors } = filterDuplicateIds(validActions);
196
+
197
+ // Add duplicate errors to the errors array
198
+ duplicateErrors.forEach(error => errors.push(error));
199
+
200
+ // Step 3: Validate actions with unique IDs
201
+ const finalValidActions: CustomAction[] = [];
202
+ actionsWithUniqueIds.forEach((action) => {
203
+ const { isValid, errors: validationErrors } = validateCustomAction(action, primaryActionsPerTarget);
204
+ validationErrors.forEach(error => errors.push(error));
205
+
206
+ if (isValid) {
207
+ finalValidActions.push(action);
208
+ }
209
+ });
210
+
211
+ const sortedActions = sortBy(finalValidActions, (a) => a.name.toLocaleLowerCase());
212
+
213
+ return {
214
+ actions: sortedActions,
215
+ errors: errors,
216
+ };
217
+ };
@@ -279,4 +279,16 @@ describe('Unit test for process data', () => {
279
279
 
280
280
  mockHandleExitPresentMode.mockReset();
281
281
  });
282
+
283
+ test('should handle ClearInfoCache', () => {
284
+ const mockResetCachedPreauthInfo = jest.spyOn(sessionInfoService, 'resetCachedPreauthInfo').mockImplementation(() => {});
285
+ const mockResetCachedSessionInfo = jest.spyOn(sessionInfoService, 'resetCachedSessionInfo').mockImplementation(() => {});
286
+ const processedData = {
287
+ type: EmbedEvent.CLEAR_INFO_CACHE,
288
+ data: {},
289
+ };
290
+ processDataInstance.processEventData(EmbedEvent.CLEAR_INFO_CACHE, processedData, thoughtSpotHost, null);
291
+ expect(mockResetCachedPreauthInfo).toHaveBeenCalled();
292
+ expect(mockResetCachedSessionInfo).toHaveBeenCalled();
293
+ });
282
294
  });