@gooddata/sdk-backend-tiger 11.58.0-alpha.0 → 11.58.0-alpha.2
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.
- package/esm/__version.d.ts +1 -1
- package/esm/__version.js +1 -1
- package/esm/backend/features/feature.d.ts.map +1 -1
- package/esm/backend/features/feature.js +1 -4
- package/esm/backend/geo/index.d.ts +8 -1
- package/esm/backend/geo/index.d.ts.map +1 -1
- package/esm/backend/geo/index.js +56 -15
- package/esm/backend/uiFeatures.d.ts +3 -12
- package/esm/backend/uiFeatures.d.ts.map +1 -1
- package/esm/backend/uiFeatures.js +3 -12
- package/esm/backend/workspace/genAI/ChatConversations.d.ts.map +1 -1
- package/esm/backend/workspace/genAI/ChatConversations.js +84 -69
- package/esm/backend/workspace/genAI/index.d.ts +1 -2
- package/esm/backend/workspace/genAI/index.d.ts.map +1 -1
- package/esm/backend/workspace/genAI/index.js +0 -4
- package/esm/backend/workspace/insights/index.d.ts.map +1 -1
- package/esm/backend/workspace/insights/index.js +9 -16
- package/esm/backend/workspace/insights/insightsQuery.d.ts +2 -0
- package/esm/backend/workspace/insights/insightsQuery.d.ts.map +1 -1
- package/esm/backend/workspace/insights/insightsQuery.js +11 -1
- package/esm/backend/workspace/permissions/index.d.ts.map +1 -1
- package/esm/backend/workspace/permissions/index.js +1 -0
- package/esm/convertors/fromBackend/InsightConverter.d.ts +8 -3
- package/esm/convertors/fromBackend/InsightConverter.d.ts.map +1 -1
- package/esm/convertors/fromBackend/InsightConverter.js +12 -3
- package/package.json +12 -12
- package/esm/backend/workspace/genAI/ChatThread.d.ts +0 -57
- package/esm/backend/workspace/genAI/ChatThread.d.ts.map +0 -1
- package/esm/backend/workspace/genAI/ChatThread.js +0 -512
|
@@ -1,512 +0,0 @@
|
|
|
1
|
-
// (C) 2024-2026 GoodData Corporation
|
|
2
|
-
import { EventSourceParserStream } from "eventsource-parser/stream";
|
|
3
|
-
import { GenAiApi_AiChat, GenAiApi_AiChatHistory, GenAiApi_AiChatStream, } from "@gooddata/api-client-tiger/endpoints/genAI";
|
|
4
|
-
import { objRefToString, } from "@gooddata/sdk-model";
|
|
5
|
-
import { convertFilter } from "../../../convertors/fromBackend/afm/FilterConverter.js";
|
|
6
|
-
import { convertMeasure } from "../../../convertors/fromBackend/afm/MeasureConverter.js";
|
|
7
|
-
import { convertAttribute } from "../../../convertors/fromBackend/AttributeConvertor.js";
|
|
8
|
-
import { getFormatByGranularity } from "../../../utils/dateUtils.js";
|
|
9
|
-
/**
|
|
10
|
-
* Chat thread service.
|
|
11
|
-
* @beta
|
|
12
|
-
*/
|
|
13
|
-
export class ChatThreadService {
|
|
14
|
-
authCall;
|
|
15
|
-
workspaceId;
|
|
16
|
-
dateNormalizer;
|
|
17
|
-
constructor(authCall, workspaceId, dateNormalizer) {
|
|
18
|
-
this.authCall = authCall;
|
|
19
|
-
this.workspaceId = workspaceId;
|
|
20
|
-
this.dateNormalizer = dateNormalizer;
|
|
21
|
-
}
|
|
22
|
-
async loadHistory(fromInteractionId, options) {
|
|
23
|
-
const response = await this.authCall((client) => {
|
|
24
|
-
return GenAiApi_AiChatHistory(client.axios, client.basePath, {
|
|
25
|
-
workspaceId: this.workspaceId,
|
|
26
|
-
chatHistoryRequest: {
|
|
27
|
-
chatHistoryInteractionId: fromInteractionId,
|
|
28
|
-
},
|
|
29
|
-
}, options);
|
|
30
|
-
});
|
|
31
|
-
return convertChatHistoryResult(this.dateNormalizer, response.data);
|
|
32
|
-
}
|
|
33
|
-
async reset() {
|
|
34
|
-
await this.authCall((client) => {
|
|
35
|
-
return GenAiApi_AiChatHistory(client.axios, client.basePath, {
|
|
36
|
-
workspaceId: this.workspaceId,
|
|
37
|
-
chatHistoryRequest: {
|
|
38
|
-
reset: true,
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
async saveUserFeedback(chatHistoryInteractionId, userFeedback, userTextFeedback) {
|
|
44
|
-
await this.authCall((client) => {
|
|
45
|
-
return GenAiApi_AiChatHistory(client.axios, client.basePath, {
|
|
46
|
-
workspaceId: this.workspaceId,
|
|
47
|
-
chatHistoryRequest: {
|
|
48
|
-
chatHistoryInteractionId,
|
|
49
|
-
userFeedback,
|
|
50
|
-
userTextFeedback,
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
async saveUserVisualisation(chatHistoryInteractionId, savedVisualization) {
|
|
56
|
-
await this.authCall((client) => {
|
|
57
|
-
return GenAiApi_AiChatHistory(client.axios, client.basePath, {
|
|
58
|
-
workspaceId: this.workspaceId,
|
|
59
|
-
chatHistoryRequest: {
|
|
60
|
-
chatHistoryInteractionId,
|
|
61
|
-
savedVisualization: {
|
|
62
|
-
createdVisualizationId: savedVisualization.createdId,
|
|
63
|
-
savedVisualizationId: savedVisualization.savedId,
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
async saveRenderVisualisationStatus(chatHistoryInteractionId, responseState) {
|
|
70
|
-
await this.authCall((client) => {
|
|
71
|
-
return GenAiApi_AiChatHistory(client.axios, client.basePath, {
|
|
72
|
-
workspaceId: this.workspaceId,
|
|
73
|
-
chatHistoryRequest: {
|
|
74
|
-
chatHistoryInteractionId,
|
|
75
|
-
responseState,
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
query(userMessage) {
|
|
81
|
-
return new ChatThreadQuery(this.authCall, this.dateNormalizer, {
|
|
82
|
-
workspaceId: this.workspaceId,
|
|
83
|
-
userQuestion: userMessage,
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Chat thread query builder.
|
|
89
|
-
* @beta
|
|
90
|
-
*/
|
|
91
|
-
export class ChatThreadQuery {
|
|
92
|
-
authCall;
|
|
93
|
-
dateNormalizer;
|
|
94
|
-
config;
|
|
95
|
-
constructor(authCall, dateNormalizer, config) {
|
|
96
|
-
this.authCall = authCall;
|
|
97
|
-
this.dateNormalizer = dateNormalizer;
|
|
98
|
-
this.config = config;
|
|
99
|
-
}
|
|
100
|
-
withSearchLimit(limitSearch) {
|
|
101
|
-
return new ChatThreadQuery(this.authCall, this.dateNormalizer, {
|
|
102
|
-
...this.config,
|
|
103
|
-
limitSearch,
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
withCreateLimit(limitCreate) {
|
|
107
|
-
return new ChatThreadQuery(this.authCall, this.dateNormalizer, {
|
|
108
|
-
...this.config,
|
|
109
|
-
limitCreate,
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
withUserContext(userContext) {
|
|
113
|
-
return new ChatThreadQuery(this.authCall, this.dateNormalizer, {
|
|
114
|
-
...this.config,
|
|
115
|
-
userContext,
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
withObjectTypes(objectTypes) {
|
|
119
|
-
return new ChatThreadQuery(this.authCall, this.dateNormalizer, {
|
|
120
|
-
...this.config,
|
|
121
|
-
objectTypes,
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
withAllowedRelationshipTypes(allowedRelationshipTypes) {
|
|
125
|
-
return new ChatThreadQuery(this.authCall, this.dateNormalizer, {
|
|
126
|
-
...this.config,
|
|
127
|
-
allowedRelationshipTypes,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
async query(options) {
|
|
131
|
-
const response = await this.authCall((client) => GenAiApi_AiChat(client.axios, client.basePath, {
|
|
132
|
-
workspaceId: this.config.workspaceId,
|
|
133
|
-
chatRequest: {
|
|
134
|
-
question: this.config.userQuestion,
|
|
135
|
-
limitSearch: this.config.limitSearch,
|
|
136
|
-
limitCreate: this.config.limitCreate,
|
|
137
|
-
userContext: convertUserContext(this.config.userContext),
|
|
138
|
-
objectTypes: this.config.objectTypes,
|
|
139
|
-
allowedRelationshipTypes: this.config.allowedRelationshipTypes,
|
|
140
|
-
},
|
|
141
|
-
}, options));
|
|
142
|
-
return response.data;
|
|
143
|
-
}
|
|
144
|
-
stream() {
|
|
145
|
-
// We are using Axios <1.7, which does not support streaming,
|
|
146
|
-
// as it can't use fetch API instead of XHR.
|
|
147
|
-
// This method can be simplified once we upgrade to Axios >=1.7.
|
|
148
|
-
const { authCall, config } = this;
|
|
149
|
-
let lastLoaded = 0;
|
|
150
|
-
// Generate a stream of string from server, as XHR delivers data in chunks.
|
|
151
|
-
const textStream = new ReadableStream({
|
|
152
|
-
start(controller) {
|
|
153
|
-
authCall((client) => GenAiApi_AiChatStream(client.axios, client.basePath, {
|
|
154
|
-
workspaceId: config.workspaceId,
|
|
155
|
-
chatRequest: {
|
|
156
|
-
question: config.userQuestion,
|
|
157
|
-
limitSearch: config.limitSearch,
|
|
158
|
-
limitCreate: config.limitCreate,
|
|
159
|
-
userContext: convertUserContext(config.userContext),
|
|
160
|
-
objectTypes: config.objectTypes,
|
|
161
|
-
allowedRelationshipTypes: config.allowedRelationshipTypes,
|
|
162
|
-
},
|
|
163
|
-
}, {
|
|
164
|
-
// Abort signal only affecting the request, as the stream is generally
|
|
165
|
-
// processed very quickly, and we don't care if an extra event slips through.
|
|
166
|
-
headers: {
|
|
167
|
-
Accept: "text/event-stream",
|
|
168
|
-
},
|
|
169
|
-
onDownloadProgress: (evt) => {
|
|
170
|
-
const data = evt.event.target.responseText.slice(lastLoaded);
|
|
171
|
-
lastLoaded += data.length;
|
|
172
|
-
controller.enqueue(data);
|
|
173
|
-
},
|
|
174
|
-
}))
|
|
175
|
-
.then(() => {
|
|
176
|
-
// Signal end-of-stream to consumers once the request completes successfully.
|
|
177
|
-
controller.close();
|
|
178
|
-
})
|
|
179
|
-
.catch((error) => {
|
|
180
|
-
// Signal an error to consumers. This terminates the stream — calling
|
|
181
|
-
// close() afterwards is illegal (ReadableStream spec) and was previously
|
|
182
|
-
// triggered by using .finally() which runs after both success and failure.
|
|
183
|
-
controller.error(error);
|
|
184
|
-
});
|
|
185
|
-
},
|
|
186
|
-
});
|
|
187
|
-
// Convert the text stream to a stream of server sent events using eventsource-parser lib.
|
|
188
|
-
// and then to a stream of IGenAIChatEvaluation.
|
|
189
|
-
return textStream
|
|
190
|
-
.pipeThrough(new EventSourceParserStream())
|
|
191
|
-
.pipeThrough(new ServerSentEventsDataParser())
|
|
192
|
-
.pipeThrough(new ServerSentEventsDataConverter(this.dateNormalizer));
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* A transform stream from SSE to IGenAIChatEvaluation
|
|
197
|
-
* @internal
|
|
198
|
-
*/
|
|
199
|
-
class ServerSentEventsDataParser extends TransformStream {
|
|
200
|
-
constructor() {
|
|
201
|
-
super({
|
|
202
|
-
transform(event, controller) {
|
|
203
|
-
if (event.event === "chat-message") {
|
|
204
|
-
controller.enqueue(JSON.parse(event.data));
|
|
205
|
-
}
|
|
206
|
-
},
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* A transform stream from SSE to IGenAIChatEvaluation
|
|
212
|
-
* @internal
|
|
213
|
-
*/
|
|
214
|
-
class ServerSentEventsDataConverter extends TransformStream {
|
|
215
|
-
constructor(dateNormalizer, locale, timezone) {
|
|
216
|
-
super({
|
|
217
|
-
transform(event, controller) {
|
|
218
|
-
controller.enqueue(convertChatEvaluation(dateNormalizer, event, locale, timezone));
|
|
219
|
-
},
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
function convertChatHistoryResult(dateNormalizer, data, locale, timezone) {
|
|
224
|
-
return {
|
|
225
|
-
...data,
|
|
226
|
-
interactions: data.interactions.map((i) => convertChatHistoryInteraction(dateNormalizer, i, locale, timezone)),
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
function convertChatHistoryInteraction(dateNormalizer, data, locale, timezone) {
|
|
230
|
-
return {
|
|
231
|
-
question: data.question,
|
|
232
|
-
chatHistoryInteractionId: data.chatHistoryInteractionId,
|
|
233
|
-
interactionFinished: data.interactionFinished,
|
|
234
|
-
textResponse: data.textResponse,
|
|
235
|
-
userFeedback: data.userFeedback,
|
|
236
|
-
errorResponse: data.errorResponse,
|
|
237
|
-
routing: convertRouting(data.routing),
|
|
238
|
-
...(data.reasoning
|
|
239
|
-
? {
|
|
240
|
-
reasoning: data.reasoning,
|
|
241
|
-
}
|
|
242
|
-
: {}),
|
|
243
|
-
...(data.foundObjects
|
|
244
|
-
? {
|
|
245
|
-
foundObjects: convertFoundObjects(data.foundObjects),
|
|
246
|
-
}
|
|
247
|
-
: {}),
|
|
248
|
-
...(data.semanticSearch
|
|
249
|
-
? {
|
|
250
|
-
semanticSearch: convertSemanticSearch(data.semanticSearch),
|
|
251
|
-
}
|
|
252
|
-
: {}),
|
|
253
|
-
...(data.createdVisualizations
|
|
254
|
-
? {
|
|
255
|
-
createdVisualizations: convertCreatedVisualizations(data.createdVisualizations),
|
|
256
|
-
}
|
|
257
|
-
: {}),
|
|
258
|
-
...(data.changeAnalysisParams
|
|
259
|
-
? {
|
|
260
|
-
changeAnalysisParams: convertChangeAnalysisParams(dateNormalizer, data.changeAnalysisParams, locale, timezone),
|
|
261
|
-
}
|
|
262
|
-
: {}),
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
function convertChatEvaluation(dateNormalizer, data, locale, timezone) {
|
|
266
|
-
return {
|
|
267
|
-
...(data.routing
|
|
268
|
-
? {
|
|
269
|
-
routing: convertRouting(data.routing),
|
|
270
|
-
}
|
|
271
|
-
: {}),
|
|
272
|
-
...(data.reasoning
|
|
273
|
-
? {
|
|
274
|
-
reasoning: data.reasoning,
|
|
275
|
-
}
|
|
276
|
-
: {}),
|
|
277
|
-
...(data.question
|
|
278
|
-
? {
|
|
279
|
-
question: data.question,
|
|
280
|
-
}
|
|
281
|
-
: {}),
|
|
282
|
-
...(data.textResponse
|
|
283
|
-
? {
|
|
284
|
-
textResponse: data.textResponse,
|
|
285
|
-
}
|
|
286
|
-
: {}),
|
|
287
|
-
...(data.foundObjects
|
|
288
|
-
? {
|
|
289
|
-
foundObjects: convertFoundObjects(data.foundObjects),
|
|
290
|
-
}
|
|
291
|
-
: {}),
|
|
292
|
-
...(data.semanticSearch
|
|
293
|
-
? {
|
|
294
|
-
semanticSearch: convertSemanticSearch(data.semanticSearch),
|
|
295
|
-
}
|
|
296
|
-
: {}),
|
|
297
|
-
...(data.createdVisualizations
|
|
298
|
-
? {
|
|
299
|
-
createdVisualizations: convertCreatedVisualizations(data.createdVisualizations),
|
|
300
|
-
}
|
|
301
|
-
: {}),
|
|
302
|
-
...(data.changeAnalysisParams
|
|
303
|
-
? {
|
|
304
|
-
changeAnalysisParams: convertChangeAnalysisParams(dateNormalizer, data.changeAnalysisParams, locale, timezone),
|
|
305
|
-
}
|
|
306
|
-
: {}),
|
|
307
|
-
...(data.errorResponse
|
|
308
|
-
? {
|
|
309
|
-
errorResponse: data.errorResponse,
|
|
310
|
-
}
|
|
311
|
-
: {}),
|
|
312
|
-
...(data.chatHistoryInteractionId
|
|
313
|
-
? {
|
|
314
|
-
chatHistoryInteractionId: data.chatHistoryInteractionId,
|
|
315
|
-
}
|
|
316
|
-
: {}),
|
|
317
|
-
...(data.userFeedback
|
|
318
|
-
? {
|
|
319
|
-
userFeedback: data.userFeedback,
|
|
320
|
-
}
|
|
321
|
-
: {}),
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
function convertRouting(data) {
|
|
325
|
-
return {
|
|
326
|
-
...data,
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
function convertFoundObjects(data) {
|
|
330
|
-
return {
|
|
331
|
-
reasoning: data.reasoning,
|
|
332
|
-
objects: data.objects?.map(convertSemanticSearchResultItem) ?? [],
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
function convertSemanticSearch(data) {
|
|
336
|
-
return {
|
|
337
|
-
reasoning: data.reasoning,
|
|
338
|
-
error: data.error,
|
|
339
|
-
results: data.results?.map(convertSemanticSearchResultItem) ?? [],
|
|
340
|
-
relationships: data.relationships?.map(convertSemanticSearchRelationship) ?? [],
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
function convertSemanticSearchResultItem(data) {
|
|
344
|
-
return {
|
|
345
|
-
id: data.id,
|
|
346
|
-
type: data.type,
|
|
347
|
-
workspaceId: data.workspaceId,
|
|
348
|
-
title: data.title,
|
|
349
|
-
description: data.description,
|
|
350
|
-
tags: data.tags,
|
|
351
|
-
createdAt: data.createdAt,
|
|
352
|
-
modifiedAt: data.modifiedAt,
|
|
353
|
-
visualizationUrl: data.visualizationUrl,
|
|
354
|
-
score: data.score,
|
|
355
|
-
scoreTitle: data.scoreTitle,
|
|
356
|
-
scoreDescriptor: data.scoreDescriptor,
|
|
357
|
-
scoreExactMatch: data.scoreExactMatch,
|
|
358
|
-
certification: data.certification?.status === "CERTIFIED"
|
|
359
|
-
? {
|
|
360
|
-
status: "CERTIFIED",
|
|
361
|
-
certificationMessage: data.certification.certificationMessage ?? undefined,
|
|
362
|
-
}
|
|
363
|
-
: undefined,
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
function convertSemanticSearchRelationship(data) {
|
|
367
|
-
return {
|
|
368
|
-
sourceWorkspaceId: data.sourceWorkspaceId,
|
|
369
|
-
sourceObjectId: data.sourceObjectId,
|
|
370
|
-
sourceObjectType: data.sourceObjectType,
|
|
371
|
-
sourceObjectTitle: data.sourceObjectTitle,
|
|
372
|
-
targetWorkspaceId: data.targetWorkspaceId,
|
|
373
|
-
targetObjectId: data.targetObjectId,
|
|
374
|
-
targetObjectType: data.targetObjectType,
|
|
375
|
-
targetObjectTitle: data.targetObjectTitle,
|
|
376
|
-
};
|
|
377
|
-
}
|
|
378
|
-
function convertCreatedVisualizations(data) {
|
|
379
|
-
return {
|
|
380
|
-
objects: data.objects?.map(convertCreatedVisualization) ?? [],
|
|
381
|
-
reasoning: data.reasoning,
|
|
382
|
-
suggestions: data.suggestions,
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
export function convertCreatedVisualization(data) {
|
|
386
|
-
const config = {};
|
|
387
|
-
if (data.config?.forecast) {
|
|
388
|
-
config.forecast = {
|
|
389
|
-
forecastPeriod: data.config.forecast.forecastPeriod,
|
|
390
|
-
confidenceLevel: data.config.forecast.confidenceLevel,
|
|
391
|
-
seasonal: data.config.forecast.seasonal,
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
if (data.config?.anomalyDetection) {
|
|
395
|
-
config.anomalyDetection = {
|
|
396
|
-
sensitivity: data.config.anomalyDetection.sensitivity,
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
|
-
if (data.config?.clustering) {
|
|
400
|
-
config.clustering = {
|
|
401
|
-
numberOfClusters: data.config.clustering.numberOfClusters,
|
|
402
|
-
threshold: data.config.clustering.threshold,
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
if (data.config?.whatIf) {
|
|
406
|
-
config.whatIf = {
|
|
407
|
-
scenarios: data.config.whatIf.scenarios.map((scenario) => ({
|
|
408
|
-
label: scenario.label,
|
|
409
|
-
adjustments: scenario.adjustments.map((adj) => ({
|
|
410
|
-
metricId: adj.metricId,
|
|
411
|
-
metricType: adj.metricType,
|
|
412
|
-
scenarioMaql: adj.scenarioMaql,
|
|
413
|
-
})),
|
|
414
|
-
})),
|
|
415
|
-
includeBaseline: data.config.whatIf.includeBaseline,
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
|
-
return {
|
|
419
|
-
id: data.id,
|
|
420
|
-
title: data.title,
|
|
421
|
-
visualizationType: data.visualizationType,
|
|
422
|
-
metrics: data.metrics,
|
|
423
|
-
dimensionality: data.dimensionality,
|
|
424
|
-
filters: data.filters,
|
|
425
|
-
suggestions: data.suggestions,
|
|
426
|
-
savedVisualizationId: data.savedVisualizationId,
|
|
427
|
-
...(Object.keys(config).length > 0 ? { config } : {}),
|
|
428
|
-
};
|
|
429
|
-
}
|
|
430
|
-
function convertChangeAnalysisParams(dateNormalizer, data, locale, timezone) {
|
|
431
|
-
const measure = convertMeasure(data.measure);
|
|
432
|
-
measure.measure.title = data.measureTitle;
|
|
433
|
-
const dateAttribute = convertAttribute(data.dateAttribute);
|
|
434
|
-
const dateGranularity = getFormatByGranularity(dateAttribute);
|
|
435
|
-
return {
|
|
436
|
-
...data,
|
|
437
|
-
measure,
|
|
438
|
-
dateAttribute,
|
|
439
|
-
dateGranularity,
|
|
440
|
-
normalizedAnalyzedPeriod: dateNormalizer(data.analyzedPeriod, dateGranularity, locale, timezone),
|
|
441
|
-
normalizedReferencePeriod: dateNormalizer(data.referencePeriod, dateGranularity, locale, timezone),
|
|
442
|
-
attributes: data.attributes?.map(convertAttribute) ?? [],
|
|
443
|
-
filters: data.filters?.map(convertFilter) ?? [],
|
|
444
|
-
};
|
|
445
|
-
}
|
|
446
|
-
/**
|
|
447
|
-
* Convert SDK model user context (with ObjRef) to the API user context (with plain string IDs).
|
|
448
|
-
*/
|
|
449
|
-
function convertUserContext(userContext) {
|
|
450
|
-
if (!userContext) {
|
|
451
|
-
return undefined;
|
|
452
|
-
}
|
|
453
|
-
return {
|
|
454
|
-
...(userContext.activeObject
|
|
455
|
-
? {
|
|
456
|
-
activeObject: {
|
|
457
|
-
id: objRefToString(userContext.activeObject.ref),
|
|
458
|
-
type: userContext.activeObject.type,
|
|
459
|
-
workspaceId: userContext.activeObject.workspaceId,
|
|
460
|
-
},
|
|
461
|
-
}
|
|
462
|
-
: {}),
|
|
463
|
-
...(userContext.view?.dashboard
|
|
464
|
-
? {
|
|
465
|
-
view: {
|
|
466
|
-
dashboard: {
|
|
467
|
-
id: objRefToString(userContext.view.dashboard.ref),
|
|
468
|
-
widgets: userContext.view.dashboard.widgets.map((w) => ({
|
|
469
|
-
title: w.title,
|
|
470
|
-
widgetId: objRefToString(w.widgetRef),
|
|
471
|
-
widgetType: w.widgetType,
|
|
472
|
-
...(w.insightRef
|
|
473
|
-
? w.widgetType === "visualizationSwitcher"
|
|
474
|
-
? {
|
|
475
|
-
activeVisualizationId: objRefToString(w.insightRef),
|
|
476
|
-
...(w.visualizations
|
|
477
|
-
? {
|
|
478
|
-
visualizationIds: w.visualizations
|
|
479
|
-
.map(({ insightRef }) => insightRef ? objRefToString(insightRef) : null)
|
|
480
|
-
.filter(Boolean),
|
|
481
|
-
}
|
|
482
|
-
: {}),
|
|
483
|
-
}
|
|
484
|
-
: { visualizationId: objRefToString(w.insightRef) }
|
|
485
|
-
: {}),
|
|
486
|
-
...(w.resultId ? { resultId: w.resultId } : {}),
|
|
487
|
-
...(w.content === undefined ? {} : { content: w.content }),
|
|
488
|
-
})),
|
|
489
|
-
},
|
|
490
|
-
},
|
|
491
|
-
}
|
|
492
|
-
: {}),
|
|
493
|
-
...(userContext.referencedObjects
|
|
494
|
-
? {
|
|
495
|
-
referencedObjects: userContext.referencedObjects.map((group) => ({
|
|
496
|
-
...(group.context
|
|
497
|
-
? {
|
|
498
|
-
context: {
|
|
499
|
-
type: group.context.type,
|
|
500
|
-
id: objRefToString(group.context.ref),
|
|
501
|
-
},
|
|
502
|
-
}
|
|
503
|
-
: {}),
|
|
504
|
-
objects: group.objects.map((o) => ({
|
|
505
|
-
type: o.type,
|
|
506
|
-
id: objRefToString(o.ref),
|
|
507
|
-
})),
|
|
508
|
-
})),
|
|
509
|
-
}
|
|
510
|
-
: {}),
|
|
511
|
-
};
|
|
512
|
-
}
|