@fluid-topics/public-api 1.0.87 → 1.0.88

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/dist/mjs/index.js CHANGED
@@ -83,6 +83,7 @@ export class FluidTopicsApi {
83
83
  contentId: (contentId) => ({
84
84
  info: `api/khub/maps/${mapId}/topics/${contentId}`,
85
85
  content: `api/khub/maps/${mapId}/topics/${contentId}/content`,
86
+ translation: `api/khub/maps/${mapId}/topics/${contentId}/content/translation`,
86
87
  }),
87
88
  tocId: (tocId) => ({
88
89
  feedback: `api/khub/maps/${mapId}/topics/${tocId}/feedback`,
@@ -158,12 +159,15 @@ export class FluidTopicsApi {
158
159
  sendFeedback: `api/ai/rate`,
159
160
  chat: `/api/ai/rag/chat`,
160
161
  translate: `api/ai/translate`,
162
+ destinationLanguages: (profileId) => ({
163
+ endpoint: `api/ai/translate/${profileId}/languages`
164
+ })
161
165
  },
162
166
  assets: {
163
167
  highlightjs: `assets/scripts/highlightjs`,
164
168
  },
165
169
  analytics: {
166
- events: 'api/analytics/events'
170
+ events: "api/analytics/events"
167
171
  }
168
172
  };
169
173
  get defaultHeaders() {
@@ -222,14 +226,18 @@ export class FluidTopicsApi {
222
226
  getReaderConfiguration() {
223
227
  return this.get(this.endpoints.configuration.reader);
224
228
  }
225
- getMap(mapId, v) {
226
- return this.get(this.endpoints.khub.maps.mapId(mapId).info, v);
229
+ getMap(mapId, translationSettings, v) {
230
+ const endpoint = this.endpoints.khub.maps.mapId(mapId).info;
231
+ const queryParams = { ...this.buildTranslationParameters(translationSettings), v };
232
+ return this.get(this.buildUrlFromParams(endpoint, queryParams));
227
233
  }
228
234
  getTableOfContent(mapId, v) {
229
235
  return this.get(this.endpoints.khub.maps.mapId(mapId).toc, v);
230
236
  }
231
- getPages(mapId, v) {
232
- return this.get(this.endpoints.khub.maps.mapId(mapId).pages, v);
237
+ getPages(mapId, v, translationSettings) {
238
+ const endpoint = this.endpoints.khub.maps.mapId(mapId).pages;
239
+ const queryParams = { ...this.buildTranslationParameters(translationSettings), v };
240
+ return this.get(this.buildUrlFromParams(endpoint, queryParams));
233
241
  }
234
242
  getTopic(mapId, topicContentId, v) {
235
243
  return this.get(this.endpoints.khub.maps.mapId(mapId).topics.contentId(topicContentId).info, v);
@@ -237,6 +245,11 @@ export class FluidTopicsApi {
237
245
  getTopicHTMLContent(mapId, topicContentId, target, v) {
238
246
  return this.get(this.endpoints.khub.maps.mapId(mapId).topics.contentId(topicContentId).content + (target ? "?target=" + target : ""), v);
239
247
  }
248
+ getTranslatedTopicHTMLContent(mapId, topicContentId, target, v, translationSettings) {
249
+ const endpoint = this.endpoints.khub.maps.mapId(mapId).topics.contentId(topicContentId).translation;
250
+ const queryParams = { ...this.buildTranslationParameters(translationSettings), target, v };
251
+ return this.get(this.buildUrlFromParams(endpoint, queryParams));
252
+ }
240
253
  getMapAttachments(mapId, v) {
241
254
  return this.get(this.endpoints.khub.maps.mapId(mapId).attachments.list, v);
242
255
  }
@@ -367,6 +380,11 @@ export class FluidTopicsApi {
367
380
  translate(input) {
368
381
  return this.post(this.endpoints.ai.translate, input);
369
382
  }
383
+ getDestinationLanguages(profileId, sourceLanguage) {
384
+ const endpoint = this.endpoints.ai.destinationLanguages(profileId).endpoint;
385
+ const queryParams = { sourceLanguage };
386
+ return this.get(this.buildUrlFromParams(endpoint, queryParams));
387
+ }
370
388
  sendFeedback(rating) {
371
389
  return this.post(this.endpoints.ai.sendFeedback, rating);
372
390
  }
@@ -456,5 +474,25 @@ export class FluidTopicsApi {
456
474
  url.searchParams.append("Ft-Calling-App", this.ftCallingApp);
457
475
  return url.toString();
458
476
  }
477
+ buildUrlFromParams(baseEndpoint, params) {
478
+ const url = new URL(this.makeAbsolute(baseEndpoint));
479
+ if (params) {
480
+ Object.entries(params).forEach(([key, value]) => {
481
+ if (value) {
482
+ url.searchParams.append(key, value);
483
+ }
484
+ });
485
+ }
486
+ return url.toString();
487
+ }
488
+ buildTranslationParameters(translationSettings) {
489
+ if (translationSettings) {
490
+ return {
491
+ translationProfileId: translationSettings.profileId,
492
+ translationDestinationLanguage: translationSettings.destinationLanguage,
493
+ translationSourceLanguage: translationSettings.sourceLanguage?.slice(0, 2)
494
+ };
495
+ }
496
+ }
459
497
  }
460
498
  export default FluidTopicsApi;
@@ -134,7 +134,6 @@ export interface FtAnalyticsEvent {
134
134
  appVersion: string;
135
135
  appName: string;
136
136
  name: FtAnalyticsEventNameKeys;
137
- version: string;
138
137
  }
139
138
  export declare const isFtAnalyticsEvent: (o: any) => o is FtAnalyticsEvent;
140
139
  export declare enum FtAnalyticsEventName {
@@ -359,6 +358,7 @@ export interface FtMap {
359
358
  originUrl?: string;
360
359
  fingerprint: string;
361
360
  readerUrl: string;
361
+ untranslatedTitle?: string;
362
362
  khubVersion?: string;
363
363
  id: string;
364
364
  lang?: string;
@@ -377,6 +377,7 @@ export interface FtTocNode {
377
377
  children: Array<FtTocNode>;
378
378
  origin?: FtTopicOrigin;
379
379
  contentId: string;
380
+ untranslatedTitle?: string;
380
381
  title: string;
381
382
  }
382
383
  export declare const isFtTocNode: (o: any) => o is FtTocNode;
@@ -427,6 +428,11 @@ export declare enum FtTopicContentTarget {
427
428
  }
428
429
  export type FtTopicContentTargetKeys = keyof typeof FtTopicContentTarget;
429
430
  export declare const isFtTopicContentTarget: (o: any) => o is FtTopicContentTarget;
431
+ export interface FtTranslationContent {
432
+ isTranslationError: boolean;
433
+ content: string;
434
+ }
435
+ export declare const isFtTranslationContent: (o: any) => o is FtTranslationContent;
430
436
  export declare enum FtExternalWebComponentContext {
431
437
  HOMEPAGE = "HOMEPAGE",
432
438
  CUSTOM = "CUSTOM",
@@ -147,8 +147,7 @@ export const isFtAnalyticsEvent = (o) => {
147
147
  && (isBoolean(o.offline))
148
148
  && (isString(o.appVersion))
149
149
  && (isString(o.appName))
150
- && (isFtAnalyticsEventName(o.name))
151
- && (isString(o.version));
150
+ && (isFtAnalyticsEventName(o.name));
152
151
  };
153
152
  // From: WsAnalyticsEventName
154
153
  export var FtAnalyticsEventName;
@@ -386,6 +385,7 @@ export const isFtMap = (o) => {
386
385
  && (o.originUrl == null || isString(o.originUrl))
387
386
  && (isString(o.fingerprint))
388
387
  && (isString(o.readerUrl))
388
+ && (o.untranslatedTitle == null || o.untranslatedTitle == null || isString(o.untranslatedTitle))
389
389
  && (o.khubVersion == null || isString(o.khubVersion))
390
390
  && (isString(o.id))
391
391
  && (o.lang == null || isString(o.lang));
@@ -406,6 +406,7 @@ export const isFtTocNode = (o) => {
406
406
  && o.children.every((v) => isFtTocNode(v))))
407
407
  && (o.origin == null || isFtTopicOrigin(o.origin))
408
408
  && (isString(o.contentId))
409
+ && (o.untranslatedTitle == null || o.untranslatedTitle == null || isString(o.untranslatedTitle))
409
410
  && (isString(o.title));
410
411
  };
411
412
  export const isFtTopic = (o) => {
@@ -459,6 +460,11 @@ export var FtTopicContentTarget;
459
460
  FtTopicContentTarget["DESIGNED_READER"] = "DESIGNED_READER";
460
461
  })(FtTopicContentTarget || (FtTopicContentTarget = {}));
461
462
  export const isFtTopicContentTarget = (o) => Object.keys(FtTopicContentTarget).includes(o);
463
+ export const isFtTranslationContent = (o) => {
464
+ return isObject(o)
465
+ && (isBoolean(o.isTranslationError))
466
+ && (isString(o.content));
467
+ };
462
468
  // From: ExternalWebComponentContext
463
469
  export var FtExternalWebComponentContext;
464
470
  (function (FtExternalWebComponentContext) {
@@ -50,14 +50,27 @@ export declare enum TranslationFormat {
50
50
  }
51
51
  export type TranslationFormatKeys = keyof typeof TranslationFormat;
52
52
  export declare const isTranslationFormat: (o: any) => o is TranslationFormat;
53
- export interface FtTranslationInput {
53
+ export interface FtTranslationLanguagesResponse {
54
+ items: Array<FtTranslationLocale>;
55
+ }
56
+ export declare const isFtTranslationLanguagesResponse: (o: any) => o is FtTranslationLanguagesResponse;
57
+ export interface FtTranslationRequest {
54
58
  profileId: string;
55
59
  format?: TranslationFormatKeys;
56
60
  destinationLanguage: string;
57
- content: string;
61
+ content: Array<string>;
58
62
  sourceLanguage?: string;
59
63
  }
60
- export declare const isFtTranslationInput: (o: any) => o is FtTranslationInput;
64
+ export declare const isFtTranslationRequest: (o: any) => o is FtTranslationRequest;
65
+ export interface FtTranslationResponse {
66
+ items: Array<string>;
67
+ }
68
+ export declare const isFtTranslationResponse: (o: any) => o is FtTranslationResponse;
69
+ export interface FtTranslationLocale {
70
+ code: string;
71
+ label: string;
72
+ }
73
+ export declare const isFtTranslationLocale: (o: any) => o is FtTranslationLocale;
61
74
  export interface FtMapAttachment {
62
75
  file: string;
63
76
  size?: number;
@@ -76,6 +89,7 @@ export declare const isFtPageConfiguration: (o: any) => o is FtPageConfiguration
76
89
  export interface FtPaginatedToc {
77
90
  configuration: FtPaginationConfiguration;
78
91
  paginatedToc: Array<FtPaginatedTocNode>;
92
+ translationError: boolean;
79
93
  }
80
94
  export declare const isFtPaginatedToc: (o: any) => o is FtPaginatedToc;
81
95
  export interface FtPaginatedTocNode {
@@ -87,9 +101,15 @@ export interface FtPaginatedTocNode {
87
101
  pageConfiguration?: FtPageConfiguration;
88
102
  origin?: any;
89
103
  contentId?: string;
104
+ untranslatedTitle?: string;
90
105
  title?: string;
91
106
  }
92
107
  export declare const isFtPaginatedTocNode: (o: any) => o is FtPaginatedTocNode;
108
+ export interface FtPaginatedTocNodeWithTranslationFailure {
109
+ paginatedToc: FtPaginatedTocNode;
110
+ translationError: boolean;
111
+ }
112
+ export declare const isFtPaginatedTocNodeWithTranslationFailure: (o: any) => o is FtPaginatedTocNodeWithTranslationFailure;
93
113
  export interface FtPaginationConfiguration {
94
114
  splitCurrentPageToc: boolean;
95
115
  }
@@ -62,14 +62,30 @@ export var TranslationFormat;
62
62
  TranslationFormat["HTML"] = "HTML";
63
63
  })(TranslationFormat || (TranslationFormat = {}));
64
64
  export const isTranslationFormat = (o) => Object.keys(TranslationFormat).includes(o);
65
- export const isFtTranslationInput = (o) => {
65
+ export const isFtTranslationLanguagesResponse = (o) => {
66
+ return isObject(o)
67
+ && ((Array.isArray(o.items)
68
+ && o.items.every((v) => isFtTranslationLocale(v))));
69
+ };
70
+ export const isFtTranslationRequest = (o) => {
66
71
  return isObject(o)
67
72
  && (isString(o.profileId))
68
73
  && (o.format == null || isTranslationFormat(o.format))
69
74
  && (isString(o.destinationLanguage))
70
- && (isString(o.content))
75
+ && ((Array.isArray(o.content)
76
+ && o.content.every((v) => isString(v))))
71
77
  && (o.sourceLanguage == null || isString(o.sourceLanguage));
72
78
  };
79
+ export const isFtTranslationResponse = (o) => {
80
+ return isObject(o)
81
+ && ((Array.isArray(o.items)
82
+ && o.items.every((v) => isString(v))));
83
+ };
84
+ export const isFtTranslationLocale = (o) => {
85
+ return isObject(o)
86
+ && (isString(o.code))
87
+ && (isString(o.label));
88
+ };
73
89
  export const isFtMapAttachment = (o) => {
74
90
  return isObject(o)
75
91
  && (isString(o.file))
@@ -90,7 +106,8 @@ export const isFtPaginatedToc = (o) => {
90
106
  return isObject(o)
91
107
  && (isFtPaginationConfiguration(o.configuration))
92
108
  && ((Array.isArray(o.paginatedToc)
93
- && o.paginatedToc.every((v) => isFtPaginatedTocNode(v))));
109
+ && o.paginatedToc.every((v) => isFtPaginatedTocNode(v))))
110
+ && (isBoolean(o.translationError));
94
111
  };
95
112
  export const isFtPaginatedTocNode = (o) => {
96
113
  return isObject(o)
@@ -102,8 +119,14 @@ export const isFtPaginatedTocNode = (o) => {
102
119
  && o.children.every((v) => isFtPaginatedTocNode(v))))
103
120
  && (o.pageConfiguration == null || isFtPageConfiguration(o.pageConfiguration))
104
121
  && (o.contentId == null || isString(o.contentId))
122
+ && (o.untranslatedTitle == null || isString(o.untranslatedTitle))
105
123
  && (o.title == null || isString(o.title));
106
124
  };
125
+ export const isFtPaginatedTocNodeWithTranslationFailure = (o) => {
126
+ return isObject(o)
127
+ && (isFtPaginatedTocNode(o.paginatedToc))
128
+ && (isBoolean(o.translationError));
129
+ };
107
130
  export const isFtPaginationConfiguration = (o) => {
108
131
  return isObject(o)
109
132
  && (isBoolean(o.splitCurrentPageToc));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/public-api",
3
- "version": "1.0.87",
3
+ "version": "1.0.88",
4
4
  "description": "Fluid Topics Public API",
5
5
  "author": "Fluid Topics dev team <opensource@antidot.net>",
6
6
  "license": "LGPL-3.0-only",