@fluid-topics/public-api 1.0.83-alpha → 1.0.85-alpha
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/cjs/helpers/GenAIChunkReader.js +1 -2
- package/dist/cjs/index.js +20 -24
- package/dist/cjs/preferences/unauthenticated-preferences.js +61 -34
- package/dist/cjs/roles/roles.js +18 -3
- package/dist/cjs/types/ft-common/public.js +221 -62
- package/dist/cjs/types/ft-server/public.js +6 -27
- package/dist/fluidtopics.min.js +1 -1
- package/dist/mjs/helpers/GenAIChunkReader.js +1 -1
- package/dist/mjs/index.d.ts +11 -10
- package/dist/mjs/index.js +20 -24
- package/dist/mjs/preferences/unauthenticated-preferences.d.ts +6 -0
- package/dist/mjs/preferences/unauthenticated-preferences.js +57 -35
- package/dist/mjs/roles/roles.d.ts +5 -1
- package/dist/mjs/roles/roles.js +14 -2
- package/dist/mjs/types/ft-common/public.d.ts +172 -2
- package/dist/mjs/types/ft-common/public.js +198 -58
- package/dist/mjs/types/ft-server/public.d.ts +1 -17
- package/dist/mjs/types/ft-server/public.js +5 -23
- package/package.json +1 -1
- package/.npmignore +0 -14
- package/yarn.lock +0 -4323
|
@@ -49,10 +49,9 @@ class GenAIChunkReader {
|
|
|
49
49
|
yield* this.parseLine(this.partialChunk);
|
|
50
50
|
}
|
|
51
51
|
*readChunksFromValue(value) {
|
|
52
|
-
var _a;
|
|
53
52
|
const text = this.partialChunk + this.decoder.decode(value);
|
|
54
53
|
const lines = text.split("\n");
|
|
55
|
-
this.partialChunk =
|
|
54
|
+
this.partialChunk = lines.pop();
|
|
56
55
|
for (let line of lines) {
|
|
57
56
|
yield* this.parseLine(line);
|
|
58
57
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -210,12 +210,12 @@ class FluidTopicsApi {
|
|
|
210
210
|
sendFeedback: `api/ai/rate`,
|
|
211
211
|
chat: `/api/ai/rag/chat`,
|
|
212
212
|
translate: `api/ai/translate`,
|
|
213
|
-
destinationLanguages: (profileId) => ({
|
|
214
|
-
endpoint: `api/ai/translate/${profileId}/languages`
|
|
215
|
-
})
|
|
216
213
|
},
|
|
217
214
|
assets: {
|
|
218
215
|
highlightjs: `assets/scripts/highlightjs`,
|
|
216
|
+
},
|
|
217
|
+
analytics: {
|
|
218
|
+
events: 'api/analytics/events'
|
|
219
219
|
}
|
|
220
220
|
};
|
|
221
221
|
//@ts-ignore
|
|
@@ -266,23 +266,20 @@ class FluidTopicsApi {
|
|
|
266
266
|
getReaderConfiguration() {
|
|
267
267
|
return this.get(this.endpoints.configuration.reader);
|
|
268
268
|
}
|
|
269
|
-
getMap(mapId,
|
|
270
|
-
|
|
271
|
-
return this.get(this.withTranslationParameters(endpoint, translationSettings), v);
|
|
269
|
+
getMap(mapId, v) {
|
|
270
|
+
return this.get(this.endpoints.khub.maps.mapId(mapId).info, v);
|
|
272
271
|
}
|
|
273
272
|
getTableOfContent(mapId, v) {
|
|
274
273
|
return this.get(this.endpoints.khub.maps.mapId(mapId).toc, v);
|
|
275
274
|
}
|
|
276
|
-
getPages(mapId, v
|
|
277
|
-
|
|
278
|
-
return this.get(this.withTranslationParameters(endpoint, translationSettings), v);
|
|
275
|
+
getPages(mapId, v) {
|
|
276
|
+
return this.get(this.endpoints.khub.maps.mapId(mapId).pages, v);
|
|
279
277
|
}
|
|
280
278
|
getTopic(mapId, topicContentId, v) {
|
|
281
279
|
return this.get(this.endpoints.khub.maps.mapId(mapId).topics.contentId(topicContentId).info, v);
|
|
282
280
|
}
|
|
283
|
-
getTopicHTMLContent(mapId, topicContentId, target, v
|
|
284
|
-
|
|
285
|
-
return this.get(this.withTranslationParameters(endpoint + (target ? "?target=" + target : ""), translationSettings), v);
|
|
281
|
+
getTopicHTMLContent(mapId, topicContentId, target, v) {
|
|
282
|
+
return this.get(this.endpoints.khub.maps.mapId(mapId).topics.contentId(topicContentId).content + (target ? "?target=" + target : ""), v);
|
|
286
283
|
}
|
|
287
284
|
getMapAttachments(mapId, v) {
|
|
288
285
|
return this.get(this.endpoints.khub.maps.mapId(mapId).attachments.list, v);
|
|
@@ -379,6 +376,12 @@ class FluidTopicsApi {
|
|
|
379
376
|
listMyBookmarks(userId) {
|
|
380
377
|
return this.get(this.endpoints.users.userId(userId).bookmarks.list);
|
|
381
378
|
}
|
|
379
|
+
sendEvents(events) {
|
|
380
|
+
if (events.length) {
|
|
381
|
+
return this.post(this.endpoints.analytics.events, events);
|
|
382
|
+
}
|
|
383
|
+
return Promise.resolve();
|
|
384
|
+
}
|
|
382
385
|
generate(profileId, parameters) {
|
|
383
386
|
return __asyncGenerator(this, arguments, function* generate_1() {
|
|
384
387
|
const response = yield __await(this.fetch(this.endpoints.ai.generate, {
|
|
@@ -412,10 +415,6 @@ class FluidTopicsApi {
|
|
|
412
415
|
translate(input) {
|
|
413
416
|
return this.post(this.endpoints.ai.translate, input);
|
|
414
417
|
}
|
|
415
|
-
getDestinationLanguages(profileId, sourceLanguage) {
|
|
416
|
-
return this.get(this.endpoints.ai.destinationLanguages(profileId).endpoint
|
|
417
|
-
+ (sourceLanguage ? "?sourceLanguage=" + sourceLanguage : ""));
|
|
418
|
-
}
|
|
419
418
|
sendFeedback(rating) {
|
|
420
419
|
return this.post(this.endpoints.ai.sendFeedback, rating);
|
|
421
420
|
}
|
|
@@ -436,6 +435,9 @@ class FluidTopicsApi {
|
|
|
436
435
|
? endpoint
|
|
437
436
|
: (this.tenantBaseUrl + endpoint.replace(/^\//, ""));
|
|
438
437
|
}
|
|
438
|
+
extractEndpoint(url) {
|
|
439
|
+
return url.replace(this.tenantBaseUrlNoTrailingSlash, "").replace(/^\//, "");
|
|
440
|
+
}
|
|
439
441
|
fetch(endpoint, init) {
|
|
440
442
|
var _a;
|
|
441
443
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -492,15 +494,9 @@ class FluidTopicsApi {
|
|
|
492
494
|
}
|
|
493
495
|
return url.toString();
|
|
494
496
|
}
|
|
495
|
-
|
|
497
|
+
withAnalyticsQueryParams(endpoint) {
|
|
496
498
|
let url = new URL(this.makeAbsolute(endpoint));
|
|
497
|
-
|
|
498
|
-
url.searchParams.append("translationProfileId", translationSettings.profileId);
|
|
499
|
-
url.searchParams.append("translationDestinationLanguage", translationSettings.destinationLanguage);
|
|
500
|
-
if (translationSettings.sourceLanguage) {
|
|
501
|
-
url.searchParams.append("translationSourceLanguage", translationSettings.sourceLanguage.slice(0, 2)); // FIX THIS!!
|
|
502
|
-
}
|
|
503
|
-
}
|
|
499
|
+
url.searchParams.append("Ft-Calling-App", this.ftCallingApp);
|
|
504
500
|
return url.toString();
|
|
505
501
|
}
|
|
506
502
|
}
|
|
@@ -1,40 +1,67 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addUnauthenticatedUserSearchPreferencesChangeHandler = exports.getUnauthenticatedUserSearchPreferences = exports.setUnauthenticatedUserSearchPreferences = void 0;
|
|
3
4
|
const wnd = (typeof window === "undefined" ? globalThis : window);
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
5
|
+
function normalizeMetadataPreferences(metadata) {
|
|
6
|
+
let normalized = {};
|
|
7
|
+
for (let key in metadata) {
|
|
8
|
+
let values = metadata[key];
|
|
9
|
+
if (typeof values !== "object" || Array.isArray(values)) {
|
|
10
|
+
values = { prior: values };
|
|
11
|
+
}
|
|
12
|
+
for (let property of ["prior", "filter"]) {
|
|
13
|
+
values[property] = Array.isArray(values[property]) ? values[property] : [values[property]];
|
|
14
|
+
values[property] = values[property]
|
|
15
|
+
.map(v => v != null ? "" + v : "")
|
|
16
|
+
.filter(v => v !== "");
|
|
17
|
+
}
|
|
18
|
+
normalized[key] = values;
|
|
19
|
+
}
|
|
20
|
+
return normalized;
|
|
21
|
+
}
|
|
21
22
|
function getStorageKey(tenantBaseUrl) {
|
|
22
23
|
return `${tenantBaseUrl}-FluidTopicsUnauthenticatedUserSearchPreferences`;
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
25
|
+
function setUnauthenticatedUserSearchPreferences(tenantBaseUrl, input) {
|
|
26
|
+
var _a;
|
|
27
|
+
if (wnd.localStorage) {
|
|
28
|
+
let preferences = Object.assign(Object.assign({}, input), { metadata: normalizeMetadataPreferences((_a = input.metadata) !== null && _a !== void 0 ? _a : {}) });
|
|
29
|
+
const key = getStorageKey(tenantBaseUrl);
|
|
30
|
+
const newValue = JSON.stringify(preferences);
|
|
31
|
+
wnd.localStorage.setItem(key, newValue);
|
|
32
|
+
wnd.dispatchEvent(new StorageEvent("storage", {
|
|
33
|
+
key,
|
|
34
|
+
newValue,
|
|
35
|
+
storageArea: wnd.localStorage,
|
|
36
|
+
url: wnd.location.href
|
|
37
|
+
}));
|
|
38
|
+
return preferences;
|
|
39
|
+
}
|
|
40
|
+
console.error("Cannot set unauthenticated preferences: local storage is unavailable.");
|
|
41
|
+
}
|
|
42
|
+
exports.setUnauthenticatedUserSearchPreferences = setUnauthenticatedUserSearchPreferences;
|
|
43
|
+
function getUnauthenticatedUserSearchPreferences(tenantBaseUrl) {
|
|
44
|
+
var _a;
|
|
45
|
+
if (wnd.localStorage) {
|
|
46
|
+
return JSON.parse((_a = wnd.localStorage.getItem(getStorageKey(tenantBaseUrl))) !== null && _a !== void 0 ? _a : "{}");
|
|
47
|
+
}
|
|
48
|
+
console.error("Cannot get unauthenticated preferences: local storage is unavailable.");
|
|
49
|
+
}
|
|
50
|
+
exports.getUnauthenticatedUserSearchPreferences = getUnauthenticatedUserSearchPreferences;
|
|
51
|
+
function addUnauthenticatedUserSearchPreferencesChangeHandler(tenantBaseUrl, handler) {
|
|
52
|
+
if (wnd.localStorage) {
|
|
53
|
+
const key = getStorageKey(tenantBaseUrl);
|
|
54
|
+
const eventListener = (event) => {
|
|
55
|
+
var _a;
|
|
56
|
+
if (event.storageArea === wnd.localStorage && event.key === key) {
|
|
57
|
+
handler(JSON.parse((_a = event.newValue) !== null && _a !== void 0 ? _a : "{}"));
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
wnd.addEventListener("storage", eventListener);
|
|
61
|
+
return {
|
|
62
|
+
removeHandler: () => wnd.removeEventListener("storage", eventListener)
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
console.error("Cannot handle unauthenticated preferences: local storage is unavailable.");
|
|
66
|
+
}
|
|
67
|
+
exports.addUnauthenticatedUserSearchPreferencesChangeHandler = addUnauthenticatedUserSearchPreferencesChangeHandler;
|
package/dist/cjs/roles/roles.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.userHasRole = void 0;
|
|
3
|
+
exports.userHasAllRoles = exports.userHasAnyRole = exports.userHasRole = void 0;
|
|
4
4
|
const public_js_1 = require("../types/ft-common/public.js");
|
|
5
5
|
const rolesInheritance = {
|
|
6
6
|
[public_js_1.FtUserRole.PERSONAL_BOOK_SHARE_USER]: [public_js_1.FtUserRole.PERSONAL_BOOK_USER],
|
|
@@ -9,10 +9,11 @@ const rolesInheritance = {
|
|
|
9
9
|
[public_js_1.FtUserRole.KHUB_ADMIN]: [public_js_1.FtUserRole.CONTENT_PUBLISHER],
|
|
10
10
|
[public_js_1.FtUserRole.ADMIN]: [public_js_1.FtUserRole.KHUB_ADMIN, public_js_1.FtUserRole.USERS_ADMIN, public_js_1.FtUserRole.PORTAL_ADMIN],
|
|
11
11
|
[public_js_1.FtUserRole.DEVELOPER]: [public_js_1.FtUserRole.BETA_USER, public_js_1.FtUserRole.DEBUG_USER],
|
|
12
|
+
[public_js_1.FtUserRole.GENERATIVE_AI_EXPORT_USER]: [public_js_1.FtUserRole.GENERATIVE_AI_USER],
|
|
12
13
|
};
|
|
13
14
|
function roleMatches(actual, expected) {
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
var _a;
|
|
16
|
+
return actual === expected || ((_a = rolesInheritance[actual]) !== null && _a !== void 0 ? _a : []).some((inherited) => roleMatches(inherited, expected));
|
|
16
17
|
}
|
|
17
18
|
function userHasRole(sessionOrProfileOrRoles, expectedRole) {
|
|
18
19
|
var _a;
|
|
@@ -29,3 +30,17 @@ function userHasRole(sessionOrProfileOrRoles, expectedRole) {
|
|
|
29
30
|
return roles.some(role => roleMatches(role, expectedRole));
|
|
30
31
|
}
|
|
31
32
|
exports.userHasRole = userHasRole;
|
|
33
|
+
function userHasAnyRole(sessionOrProfileOrRoles, ...expectedRoles) {
|
|
34
|
+
if (sessionOrProfileOrRoles == null) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
return expectedRoles.some(role => userHasRole(sessionOrProfileOrRoles, role));
|
|
38
|
+
}
|
|
39
|
+
exports.userHasAnyRole = userHasAnyRole;
|
|
40
|
+
function userHasAllRoles(sessionOrProfileOrRoles, ...expectedRoles) {
|
|
41
|
+
if (sessionOrProfileOrRoles == null) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
return expectedRoles.every(role => userHasRole(sessionOrProfileOrRoles, role));
|
|
45
|
+
}
|
|
46
|
+
exports.userHasAllRoles = userHasAllRoles;
|