@gooddata/sdk-backend-tiger 11.57.0 → 11.58.0-alpha.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"InsightConverter.d.ts","sourceRoot":"","sources":["../../../src/convertors/fromBackend/InsightConverter.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,KAAK,qCAAqC,EAC1C,KAAK,mCAAmC,EACxC,KAAK,6BAA6B,EAClC,KAAK,iCAAiC,EACtC,KAAK,sCAAsC,EAG9C,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,kBAAkB,EAAE,KAAK,KAAK,EAAS,MAAM,qBAAqB,CAAC;AAOhG,eAAO,MAAM,4BAA4B,YAC5B,kBAAkB,MACvB,MAAM,OACL,MAAM,QACL,MAAM,EAAE,GAAG,SAAS,YAChB,OAAO,GAAG,SAAS,YACnB,OAAO,GAAG,SAAS,WACpB,MAAM,GAAG,SAAS,WAClB,MAAM,GAAG,SAAS,aAChB,KAAK,GAAG,SAAS,aACjB,KAAK,GAAG,SAAS,kBACZ,QAAQ,CAAC,SAAS,CAAC,CAAC,eAAe,CAAC,KACrD,QAiBF,CAAC;AAEF,eAAO,MAAM,iCAAiC,wBACrB,6BAA6B,GAAG,sCAAsC,aACjF,CAAC,qCAAqC,GAAG,mCAAmC,CAAC,EAAE,KAC1F,QA2BF,CAAC;AAEF,eAAO,MAAM,qCAAqC,yBACxB,iCAAiC,KACxD,QAAQ,EAIV,CAAC"}
1
+ {"version":3,"file":"InsightConverter.d.ts","sourceRoot":"","sources":["../../../src/convertors/fromBackend/InsightConverter.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,KAAK,qCAAqC,EAC1C,KAAK,mCAAmC,EACxC,KAAK,6BAA6B,EAClC,KAAK,qCAAqC,EAC1C,KAAK,iCAAiC,EACtC,KAAK,sCAAsC,EAG9C,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACH,KAAK,wBAAwB,EAC7B,KAAK,QAAQ,EACb,KAAK,kBAAkB,EACvB,KAAK,KAAK,EAEb,MAAM,qBAAqB,CAAC;AAO7B,eAAO,MAAM,4BAA4B,YAC5B,kBAAkB,MACvB,MAAM,OACL,MAAM,QACL,MAAM,EAAE,GAAG,SAAS,YAChB,OAAO,GAAG,SAAS,YACnB,OAAO,GAAG,SAAS,WACpB,MAAM,GAAG,SAAS,WAClB,MAAM,GAAG,SAAS,aAChB,KAAK,GAAG,SAAS,aACjB,KAAK,GAAG,SAAS,kBACZ,QAAQ,CAAC,SAAS,CAAC,CAAC,eAAe,CAAC,gBACtC,wBAAwB,EAAE,KACzC,QAkBF,CAAC;AAEF,eAAO,MAAM,iCAAiC,wBACrB,6BAA6B,GAAG,sCAAsC,aACjF,CAAC,qCAAqC,GAAG,mCAAmC,CAAC,EAAE,KAC1F,QA4BF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,oCAAoC,+BAI9C,qCAAqC,KAAG,QAG1C,CAAC;AAEF,eAAO,MAAM,qCAAqC,yBACxB,iCAAiC,KACxD,QAAQ,EAIV,CAAC"}
@@ -1,10 +1,10 @@
1
1
  // (C) 2020-2026 GoodData Corporation
2
- import { idRef } from "@gooddata/sdk-model";
2
+ import { idRef, } from "@gooddata/sdk-model";
3
3
  import { convertCertificationFromBackend } from "./CertificationConverter.js";
4
4
  import { isInheritedObject } from "./ObjectInheritance.js";
5
5
  import { convertUserIdentifier } from "./UsersConverter.js";
6
6
  import { convertVisualizationObject } from "./visualizationObjects/VisualizationObjectConverter.js";
7
- export const insightFromInsightDefinition = (insight, id, uri, tags, isLocked, isHidden, created, updated, createdBy, updatedBy, certification) => {
7
+ export const insightFromInsightDefinition = (insight, id, uri, tags, isLocked, isHidden, created, updated, createdBy, updatedBy, certification, permissions) => {
8
8
  return {
9
9
  insight: {
10
10
  ...insight.insight,
@@ -19,6 +19,7 @@ export const insightFromInsightDefinition = (insight, id, uri, tags, isLocked, i
19
19
  updated,
20
20
  updatedBy,
21
21
  ...(certification ? { certification } : {}),
22
+ ...(permissions ? { permissions } : {}),
22
23
  },
23
24
  };
24
25
  };
@@ -29,7 +30,15 @@ export const visualizationObjectsItemToInsight = (visualizationObject, included
29
30
  const links = "links" in visualizationObject ? visualizationObject.links : undefined;
30
31
  return insightFromInsightDefinition(convertVisualizationObject(content, title, description, tags), id, links?.self ?? "", tags,
31
32
  // TODO: TIGER-HACK: inherited objects must be locked; they are read-only for all
32
- isInheritedObject(visualizationObject), isHidden, createdAt ?? undefined, modifiedAt ?? undefined, convertUserIdentifier(createdBy, included), convertUserIdentifier(modifiedBy, included), convertCertificationFromBackend(attributes, convertUserIdentifier(certifiedBy, included)));
33
+ isInheritedObject(visualizationObject), isHidden, createdAt ?? undefined, modifiedAt ?? undefined, convertUserIdentifier(createdBy, included), convertUserIdentifier(modifiedBy, included), convertCertificationFromBackend(attributes, convertUserIdentifier(certifiedBy, included)), visualizationObject.meta?.permissions);
34
+ };
35
+ /**
36
+ * Converts a single visualization object document. The document carries the object's links,
37
+ * the item itself does not, so the uri comes from the document.
38
+ */
39
+ export const visualizationObjectDocumentToInsight = ({ data, links, included, }) => {
40
+ const converted = visualizationObjectsItemToInsight(data, included);
41
+ return { insight: { ...converted.insight, uri: links?.self ?? converted.insight.uri } };
33
42
  };
34
43
  export const convertVisualizationObjectsToInsights = (visualizationObjects) => {
35
44
  return visualizationObjects.data.map((visualizationObject) => visualizationObjectsItemToInsight(visualizationObject, visualizationObjects.included));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gooddata/sdk-backend-tiger",
3
- "version": "11.57.0",
3
+ "version": "11.58.0-alpha.1",
4
4
  "description": "GoodData Backend SPI implementation for GoodData Cloud and GoodData.CN",
5
5
  "license": "MIT",
6
6
  "author": "GoodData",
@@ -34,12 +34,12 @@
34
34
  "ts-invariant": "0.10.3",
35
35
  "tslib": "2.8.1",
36
36
  "uuid": "11.1.1",
37
- "@gooddata/api-client-tiger": "11.57.0",
38
- "@gooddata/sdk-backend-base": "11.57.0",
39
- "@gooddata/sdk-backend-spi": "11.57.0",
40
- "@gooddata/sdk-code-convertors": "11.57.0",
41
- "@gooddata/sdk-model": "11.57.0",
42
- "@gooddata/util": "11.57.0"
37
+ "@gooddata/api-client-tiger": "11.58.0-alpha.1",
38
+ "@gooddata/sdk-code-convertors": "11.58.0-alpha.1",
39
+ "@gooddata/sdk-model": "11.58.0-alpha.1",
40
+ "@gooddata/sdk-backend-base": "11.58.0-alpha.1",
41
+ "@gooddata/util": "11.58.0-alpha.1",
42
+ "@gooddata/sdk-backend-spi": "11.58.0-alpha.1"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@gooddata/fixtures": "3.7.0",
@@ -64,10 +64,10 @@
64
64
  "oxlint-tsgolint": "7.0.2001",
65
65
  "typescript": "7.0.2",
66
66
  "vitest": "4.1.8",
67
- "@gooddata/catalog-export": "11.57.0",
68
- "@gooddata/eslint-config": "11.57.0",
69
- "@gooddata/oxlint-config": "11.57.0",
70
- "@gooddata/reference-workspace": "11.57.0"
67
+ "@gooddata/oxlint-config": "11.58.0-alpha.1",
68
+ "@gooddata/catalog-export": "11.58.0-alpha.1",
69
+ "@gooddata/eslint-config": "11.58.0-alpha.1",
70
+ "@gooddata/reference-workspace": "11.58.0-alpha.1"
71
71
  },
72
72
  "scripts": {
73
73
  "_phase:build": "npm run build",
@@ -1,57 +0,0 @@
1
- import type { CreatedVisualization } from "@gooddata/api-client-tiger";
2
- import type { IChatThread, IChatThreadHistory, IChatThreadQuery, IGenAIChatEvaluation } from "@gooddata/sdk-backend-spi";
3
- import { type GenAIChatInteractionUserFeedback, type GenAIChatInteractionUserVisualisation, type GenAIObjectType, type IAllowedRelationshipType, type IGenAIUserContext, type IGenAIVisualization } from "@gooddata/sdk-model";
4
- import { type DateNormalizer } from "../../../convertors/fromBackend/dateFormatting/types.js";
5
- import { type TigerAuthenticatedCallGuard } from "../../../types/index.js";
6
- /**
7
- * Chat thread service.
8
- * @beta
9
- */
10
- export declare class ChatThreadService implements IChatThread {
11
- private readonly authCall;
12
- private readonly workspaceId;
13
- private readonly dateNormalizer;
14
- constructor(authCall: TigerAuthenticatedCallGuard, workspaceId: string, dateNormalizer: DateNormalizer);
15
- loadHistory(fromInteractionId?: string, options?: {
16
- signal?: AbortSignal;
17
- }): Promise<IChatThreadHistory>;
18
- reset(): Promise<void>;
19
- saveUserFeedback(chatHistoryInteractionId: string, userFeedback: GenAIChatInteractionUserFeedback, userTextFeedback?: string): Promise<void>;
20
- saveUserVisualisation(chatHistoryInteractionId: string, savedVisualization: GenAIChatInteractionUserVisualisation): Promise<void>;
21
- saveRenderVisualisationStatus(chatHistoryInteractionId: string, responseState: "SUCCESSFUL" | "UNEXPECTED_ERROR" | "TOO_MANY_DATA_POINTS" | "NO_DATA" | "NO_RESULTS"): Promise<void>;
22
- query(userMessage: string): IChatThreadQuery;
23
- }
24
- /**
25
- * Chat thread query configuration.
26
- * @beta
27
- */
28
- export type ChatThreadQueryConfig = {
29
- workspaceId: string;
30
- userQuestion: string;
31
- limitSearch?: number;
32
- limitCreate?: number;
33
- userContext?: IGenAIUserContext;
34
- objectTypes?: GenAIObjectType[];
35
- allowedRelationshipTypes?: IAllowedRelationshipType[];
36
- };
37
- /**
38
- * Chat thread query builder.
39
- * @beta
40
- */
41
- export declare class ChatThreadQuery implements IChatThreadQuery {
42
- private readonly authCall;
43
- private readonly dateNormalizer;
44
- private readonly config;
45
- constructor(authCall: TigerAuthenticatedCallGuard, dateNormalizer: DateNormalizer, config: ChatThreadQueryConfig);
46
- withSearchLimit(limitSearch: number): IChatThreadQuery;
47
- withCreateLimit(limitCreate: number): IChatThreadQuery;
48
- withUserContext(userContext: IGenAIUserContext): IChatThreadQuery;
49
- withObjectTypes(objectTypes?: GenAIObjectType[]): IChatThreadQuery;
50
- withAllowedRelationshipTypes(allowedRelationshipTypes?: IAllowedRelationshipType[]): IChatThreadQuery;
51
- query(options?: {
52
- signal?: AbortSignal;
53
- }): Promise<IGenAIChatEvaluation>;
54
- stream(): ReadableStream<IGenAIChatEvaluation>;
55
- }
56
- export declare function convertCreatedVisualization(data: CreatedVisualization): IGenAIVisualization;
57
- //# sourceMappingURL=ChatThread.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ChatThread.d.ts","sourceRoot":"","sources":["../../../../src/backend/workspace/genAI/ChatThread.ts"],"names":[],"mappings":"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"}
@@ -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
- }