@fluid-topics/public-api 1.0.75 → 1.0.76

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 (34) hide show
  1. package/.npmignore +13 -0
  2. package/dist/cjs/types/ft-common/public.js +83 -29
  3. package/dist/fluidtopics.min.js +1 -1
  4. package/dist/mjs/types/ft-common/public.d.ts +57 -17
  5. package/dist/mjs/types/ft-common/public.js +72 -25
  6. package/package.json +1 -1
  7. package/yarn.lock +4146 -0
  8. package/.yarnrc +0 -1
  9. package/build/cjs/helpers/GenAIChunkReader.js +0 -66
  10. package/build/cjs/index.js +0 -476
  11. package/build/cjs/preferences/unauthenticated-preferences.js +0 -67
  12. package/build/cjs/roles/roles.js +0 -31
  13. package/build/cjs/types/ft-common/public.js +0 -848
  14. package/build/cjs/types/ft-server/public.js +0 -146
  15. package/build/mjs/helpers/GenAIChunkReader.d.ts +0 -19
  16. package/build/mjs/helpers/GenAIChunkReader.js +0 -37
  17. package/build/mjs/index.d.ts +0 -190
  18. package/build/mjs/index.js +0 -432
  19. package/build/mjs/preferences/unauthenticated-preferences.d.ts +0 -9
  20. package/build/mjs/preferences/unauthenticated-preferences.js +0 -61
  21. package/build/mjs/roles/roles.d.ts +0 -2
  22. package/build/mjs/roles/roles.js +0 -25
  23. package/build/mjs/types/ft-common/public.d.ts +0 -657
  24. package/build/mjs/types/ft-common/public.js +0 -762
  25. package/build/mjs/types/ft-server/public.d.ts +0 -104
  26. package/build/mjs/types/ft-server/public.js +0 -127
  27. package/build/rollup/fluidtopics.min.js +0 -1
  28. package/build/test-results/public-api.xml +0 -18
  29. package/build/test-results/web-components.xml +0 -12
  30. package/packages/cjs/package.json +0 -3
  31. package/packages/mjs/package.json +0 -3
  32. package/test-browser/helpers/GenAIChunkReader.test.ts +0 -54
  33. package/vite-plugin.mjs +0 -95
  34. package/web-test-runner.config.mjs +0 -58
package/.yarnrc DELETED
@@ -1 +0,0 @@
1
- --frozen-lockfile false
@@ -1,66 +0,0 @@
1
- "use strict";
2
- var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
3
- var __asyncValues = (this && this.__asyncValues) || function (o) {
4
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
5
- var m = o[Symbol.asyncIterator], i;
6
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
7
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
8
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
9
- };
10
- var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
11
- var i, p;
12
- return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
13
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
14
- };
15
- var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
16
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
17
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
18
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
19
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
20
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
21
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
22
- function fulfill(value) { resume("next", value); }
23
- function reject(value) { resume("throw", value); }
24
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
25
- };
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.GenAIChunkReader = void 0;
28
- class GenAIChunkReader {
29
- constructor(reader) {
30
- this.reader = reader;
31
- this.decoder = new TextDecoder();
32
- this.partialChunk = "";
33
- }
34
- read() {
35
- return __asyncGenerator(this, arguments, function* read_1() {
36
- while (true) {
37
- const { done, value } = yield __await(this.reader.read());
38
- if (done) {
39
- yield __await(yield* __asyncDelegator(__asyncValues(this.readRemainingChunks())));
40
- return yield __await(void 0);
41
- }
42
- else {
43
- yield __await(yield* __asyncDelegator(__asyncValues(this.readChunksFromValue(value))));
44
- }
45
- }
46
- });
47
- }
48
- *readRemainingChunks() {
49
- yield* this.parseLine(this.partialChunk);
50
- }
51
- *readChunksFromValue(value) {
52
- const text = this.partialChunk + this.decoder.decode(value);
53
- const lines = text.split("\n");
54
- this.partialChunk = lines.pop();
55
- for (let line of lines) {
56
- yield* this.parseLine(line);
57
- }
58
- }
59
- *parseLine(line) {
60
- const [type, content] = line.split(/:(.*)/);
61
- if (type == "data" && content.length > 0) {
62
- yield JSON.parse(content);
63
- }
64
- }
65
- }
66
- exports.GenAIChunkReader = GenAIChunkReader;
@@ -1,476 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
- return new (P || (P = Promise))(function (resolve, reject) {
19
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
- step((generator = generator.apply(thisArg, _arguments || [])).next());
23
- });
24
- };
25
- var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
26
- var __asyncValues = (this && this.__asyncValues) || function (o) {
27
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
28
- var m = o[Symbol.asyncIterator], i;
29
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
30
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
31
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
32
- };
33
- var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
34
- var i, p;
35
- return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
36
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
37
- };
38
- var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
39
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
40
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
41
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
42
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
43
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
44
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
45
- function fulfill(value) { resume("next", value); }
46
- function reject(value) { resume("throw", value); }
47
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
48
- };
49
- var __importDefault = (this && this.__importDefault) || function (mod) {
50
- return (mod && mod.__esModule) ? mod : { "default": mod };
51
- };
52
- Object.defineProperty(exports, "__esModule", { value: true });
53
- exports.FluidTopicsApi = exports.HttpErrorEvent = exports.HttpError = void 0;
54
- const cross_fetch_1 = __importDefault(require("cross-fetch"));
55
- const GenAIChunkReader_1 = require("./helpers/GenAIChunkReader");
56
- const wnd = (typeof window === "undefined" ? globalThis : window);
57
- __exportStar(require("./types/ft-common/public"), exports);
58
- __exportStar(require("./types/ft-server/public"), exports);
59
- __exportStar(require("./roles/roles"), exports);
60
- __exportStar(require("./preferences/unauthenticated-preferences"), exports);
61
- function toBase64(s) {
62
- return typeof Buffer !== "undefined" ? Buffer.from(s).toString("base64") : btoa(s);
63
- }
64
- class HttpError extends Error {
65
- constructor(method, endpoint, status, statusText, body) {
66
- super(`${method} ${endpoint} -> ${status} - ${statusText}: ${body}`);
67
- this.method = method;
68
- this.endpoint = endpoint;
69
- this.status = status;
70
- this.statusText = statusText;
71
- this.body = body;
72
- }
73
- }
74
- exports.HttpError = HttpError;
75
- class HttpErrorEvent extends CustomEvent {
76
- constructor(e) {
77
- super("ft-api-http-error", { detail: e });
78
- }
79
- }
80
- exports.HttpErrorEvent = HttpErrorEvent;
81
- function handleError(method, endpoint, response) {
82
- return __awaiter(this, void 0, void 0, function* () {
83
- if (!response.ok) {
84
- let details = {
85
- method,
86
- endpoint,
87
- status: response.status,
88
- statusText: response.statusText,
89
- body: yield response.text()
90
- };
91
- if (typeof wnd.dispatchEvent === "function") {
92
- wnd.dispatchEvent(new HttpErrorEvent(details));
93
- }
94
- throw new HttpError(details.method, details.endpoint, details.status, details.statusText, details.body);
95
- }
96
- return response;
97
- });
98
- }
99
- function getBody(response) {
100
- return response.headers.get("Content-Type") === "application/json" ? response.json() : response.text();
101
- }
102
- class FluidTopicsApi {
103
- get defaultHeaders() {
104
- return Object.assign(Object.assign(Object.assign({}, this.authorization), this.searchLabel), { "Ft-Calling-App": this.ftCallingApp });
105
- }
106
- constructor(tenantBaseUrl, integrationIdentifier, overrideIdentifierIfOnTenant) {
107
- var _a, _b;
108
- this.endpoints = {
109
- authentication: {
110
- login: `api/authentication/login`,
111
- logout: `api/authentication/logout`,
112
- currentSession: `api/authentication/current-session`,
113
- },
114
- khub: {
115
- maps: {
116
- mapId: (mapId) => ({
117
- info: `api/khub/maps/${mapId}`,
118
- toc: `api/khub/maps/${mapId}/toc`,
119
- pages: `api/khub/maps/${mapId}/pages`,
120
- feedback: `api/khub/maps/${mapId}/feedback`,
121
- rating: `api/khub/maps/${mapId}/rating`,
122
- attachments: {
123
- list: `api/khub/maps/${mapId}/attachments`,
124
- attachmentId: (attachmentId) => ({
125
- content: `api/khub/maps/${mapId}/attachments/${attachmentId}/content`,
126
- })
127
- },
128
- resources: {
129
- list: `api/khub/maps/${mapId}/resources`,
130
- resourceId: (resourceId) => ({
131
- content: `api/khub/maps/${mapId}/resources/${resourceId}/content`,
132
- })
133
- },
134
- topics: {
135
- contentId: (contentId) => ({
136
- info: `api/khub/maps/${mapId}/topics/${contentId}`,
137
- content: `api/khub/maps/${mapId}/topics/${contentId}/content`,
138
- }),
139
- tocId: (tocId) => ({
140
- feedback: `api/khub/maps/${mapId}/topics/${tocId}/feedback`,
141
- rating: `api/khub/maps/${mapId}/topics/${tocId}/rating`,
142
- })
143
- },
144
- })
145
- },
146
- documents: {
147
- documentId: (documentId) => ({
148
- info: `api/khub/documents/${documentId}`,
149
- content: `api/khub/documents/${documentId}/content`,
150
- text: `api/khub/documents/${documentId}/content/text`,
151
- feedback: `api/khub/documents/${documentId}/feedback`,
152
- rating: `api/khub/documents/${documentId}/rating`,
153
- })
154
- },
155
- semantic: {
156
- search: `api/khub/semantic/search`,
157
- clusteredSearch: `api/khub/semantic/clustered-search`
158
- },
159
- suggest: `api/khub/suggest`,
160
- clusteredSearch: `api/khub/clustered-search`,
161
- locales: `api/khub/locales`,
162
- },
163
- users: {
164
- userId: (userId) => ({
165
- collections: {
166
- collectionId: (collectionId) => ({
167
- documents: `api/users/${userId}/collections/${collectionId}/documents`,
168
- })
169
- },
170
- searches: {
171
- list: `api/users/${userId}/searches`
172
- },
173
- bookmarks: {
174
- list: `api/users/${userId}/bookmarks`
175
- }
176
- }),
177
- },
178
- stylesheets: {
179
- fonts: `stylesheets/fonts.css`,
180
- theme: `stylesheets/theme.css`,
181
- content: {
182
- title: `stylesheets/content/title.css`,
183
- topic: `stylesheets/content/topic.css`,
184
- },
185
- },
186
- configuration: {
187
- reader: `api/configuration/reader`,
188
- metadata: `api/configuration/metadata`
189
- },
190
- locales: {
191
- ui: `api/locales/ui`
192
- },
193
- messages: {
194
- locale: (locale) => ({
195
- fluidTopics: {
196
- contextName: (contextName) => ({
197
- endpoint: `api/messages/${locale}/fluid-topics/${contextName}`,
198
- })
199
- },
200
- custom: {
201
- contextName: (contextName) => ({
202
- endpoint: `api/messages/${locale}/custom/${contextName}`,
203
- })
204
- }
205
- })
206
- },
207
- ai: {
208
- generate: `api/ai/generate`,
209
- sendFeedback: `api/ai/rate`,
210
- chat: `/api/ai/rag/chat`
211
- }
212
- };
213
- //@ts-ignore
214
- tenantBaseUrl = ((_b = (_a = tenantBaseUrl !== null && tenantBaseUrl !== void 0 ? tenantBaseUrl : wnd.fluidTopicsBaseUrl) !== null && _a !== void 0 ? _a : wnd.__gwt_ft_moduleBase) !== null && _b !== void 0 ? _b : "").trim();
215
- this.tenantBaseUrl = tenantBaseUrl.endsWith("/") ? tenantBaseUrl : tenantBaseUrl + "/";
216
- this.tenantBaseUrlNoTrailingSlash = this.tenantBaseUrl.replace(/\/$/, "");
217
- if (overrideIdentifierIfOnTenant && typeof wnd.location !== "undefined" && wnd.location.href.startsWith(this.tenantBaseUrl)) {
218
- this.ftCallingApp = integrationIdentifier;
219
- }
220
- else {
221
- this.ftCallingApp = `ft-public-api/${integrationIdentifier}`;
222
- }
223
- }
224
- setApiKey(apiKey) {
225
- this.authorization = { "Authorization": "Bearer " + apiKey };
226
- }
227
- setCredentials(login, password) {
228
- this.authorization = { "Authorization": "Basic " + toBase64(`${login}:${password}`) };
229
- }
230
- clearAuthentication() {
231
- this.authorization = undefined;
232
- }
233
- setSearchLabel(searchLabel) {
234
- this.searchLabel = { "FT-search-label": searchLabel };
235
- }
236
- clearSearchLabel() {
237
- this.searchLabel = undefined;
238
- }
239
- login(login, password) {
240
- let credentials = {
241
- login: login,
242
- password: password,
243
- rememberMe: true
244
- };
245
- return this.post(this.endpoints.authentication.login, credentials)
246
- .then(result => {
247
- this.setCredentials(login, password);
248
- return result;
249
- });
250
- }
251
- logout() {
252
- return this.post(this.endpoints.authentication.logout)
253
- .then(() => this.clearAuthentication());
254
- }
255
- getCurrentSession() {
256
- return this.get(this.endpoints.authentication.currentSession);
257
- }
258
- getReaderConfiguration() {
259
- return this.get(this.endpoints.configuration.reader);
260
- }
261
- getMap(mapId, v) {
262
- return this.get(this.endpoints.khub.maps.mapId(mapId).info, v);
263
- }
264
- getTableOfContent(mapId, v) {
265
- return this.get(this.endpoints.khub.maps.mapId(mapId).toc, v);
266
- }
267
- getPages(mapId, v) {
268
- return this.get(this.endpoints.khub.maps.mapId(mapId).pages, v);
269
- }
270
- getTopic(mapId, topicContentId, v) {
271
- return this.get(this.endpoints.khub.maps.mapId(mapId).topics.contentId(topicContentId).info, v);
272
- }
273
- getTopicHTMLContent(mapId, topicContentId, target, v) {
274
- return this.get(this.endpoints.khub.maps.mapId(mapId).topics.contentId(topicContentId).content + (target ? "?target=" + target : ""), v);
275
- }
276
- getMapAttachments(mapId, v) {
277
- return this.get(this.endpoints.khub.maps.mapId(mapId).attachments.list, v);
278
- }
279
- getMapAttachmentContent(mapId, attachmentId, v) {
280
- return this.fetchRawData(this.endpoints.khub.maps.mapId(mapId).attachments.attachmentId(attachmentId).content, v);
281
- }
282
- getMapResources(mapId, v) {
283
- return this.get(this.endpoints.khub.maps.mapId(mapId).resources.list, v);
284
- }
285
- getMapResourceContent(mapId, resourceId, v) {
286
- return this.fetchRawData(this.endpoints.khub.maps.mapId(mapId).resources.resourceId(resourceId).content, v);
287
- }
288
- getUnstructuredDocument(documentId, v) {
289
- return this.get(this.endpoints.khub.documents.documentId(documentId).info, v);
290
- }
291
- getUnstructuredDocumentContent(documentId, v) {
292
- return this.fetchRawData(this.endpoints.khub.documents.documentId(documentId).content, v);
293
- }
294
- getUnstructuredDocumentTextContent(documentId, v) {
295
- return this.get(this.endpoints.khub.documents.documentId(documentId).text, v);
296
- }
297
- getCollectionDocuments(userId, collectionId) {
298
- return this.get(this.endpoints.users.userId(userId).collections.collectionId(collectionId).documents);
299
- }
300
- getSuggestions(request) {
301
- return this.post(this.endpoints.khub.suggest, request);
302
- }
303
- search(request) {
304
- return this.post(this.endpoints.khub.clusteredSearch, request);
305
- }
306
- getAvailableSearchLocales() {
307
- return this.get(this.endpoints.khub.locales);
308
- }
309
- getAvailableUiLocales() {
310
- return this.get(this.endpoints.locales.ui);
311
- }
312
- getMetadataConfiguration() {
313
- return this.get(this.endpoints.configuration.metadata);
314
- }
315
- getMapRating(mapId) {
316
- return this.get(this.endpoints.khub.maps.mapId(mapId).rating);
317
- }
318
- rateMap(mapId, type, value) {
319
- return this.post(this.endpoints.khub.maps.mapId(mapId).rating, { type, value });
320
- }
321
- unrateMap(mapId) {
322
- return this.delete(this.endpoints.khub.maps.mapId(mapId).rating);
323
- }
324
- sendMapFeedback(mapId, message, from) {
325
- return this.post(this.endpoints.khub.maps.mapId(mapId).feedback, { message, from });
326
- }
327
- rateTopic(mapId, tocId, type, value) {
328
- return this.post(this.endpoints.khub.maps.mapId(mapId).topics.tocId(tocId).rating, {
329
- type, value
330
- });
331
- }
332
- unrateTopic(mapId, tocId) {
333
- return this.delete(this.endpoints.khub.maps.mapId(mapId).topics.tocId(tocId).rating);
334
- }
335
- sendTopicFeedback(mapId, tocId, message, from) {
336
- return this.post(this.endpoints.khub.maps.mapId(mapId).topics.tocId(tocId).feedback, { message, from });
337
- }
338
- getDocumentRating(docId) {
339
- return this.get(this.endpoints.khub.documents.documentId(docId).rating);
340
- }
341
- rateDocument(docId, type, value) {
342
- return this.post(this.endpoints.khub.documents.documentId(docId).rating, { type, value });
343
- }
344
- unrateDocument(docId) {
345
- return this.delete(this.endpoints.khub.documents.documentId(docId).rating);
346
- }
347
- sendDocumentFeedback(docId, message, from) {
348
- return this.post(this.endpoints.khub.documents.documentId(docId).feedback, { message, from });
349
- }
350
- semanticSearch(request) {
351
- return this.post(this.endpoints.khub.semantic.search, { request });
352
- }
353
- clusteredSemanticSearch(request) {
354
- return this.post(this.endpoints.khub.semantic.clusteredSearch, { request });
355
- }
356
- getFluidTopicsMessageContext(locale, name) {
357
- return this.get(this.endpoints.messages.locale(locale).fluidTopics.contextName(name).endpoint);
358
- }
359
- getCustomMessageContext(locale, name) {
360
- return this.get(this.endpoints.messages.locale(locale).custom.contextName(name).endpoint);
361
- }
362
- listMySearches(userId) {
363
- return this.get(this.endpoints.users.userId(userId).searches.list);
364
- }
365
- listMyBookmarks(userId) {
366
- return this.get(this.endpoints.users.userId(userId).bookmarks.list);
367
- }
368
- generate(profileId, parameters) {
369
- return __asyncGenerator(this, arguments, function* generate_1() {
370
- const response = yield __await(this.fetch(this.endpoints.ai.generate, {
371
- method: "POST",
372
- headers: {
373
- "Content-Type": "application/json",
374
- },
375
- body: JSON.stringify({ profileId, parameters }),
376
- credentials: this.authorization == null ? "include" : undefined
377
- }));
378
- yield __await(handleError("POST", this.endpoints.ai.generate, response));
379
- const reader = new GenAIChunkReader_1.GenAIChunkReader(response.body.getReader());
380
- yield __await(yield* __asyncDelegator(__asyncValues(reader.read())));
381
- });
382
- }
383
- chat(input) {
384
- return __asyncGenerator(this, arguments, function* chat_1() {
385
- const response = yield __await(this.fetch(this.endpoints.ai.chat, {
386
- method: "POST",
387
- headers: {
388
- "Content-Type": "application/json",
389
- },
390
- body: JSON.stringify(input),
391
- credentials: this.authorization == null ? "include" : undefined
392
- }));
393
- yield __await(handleError("POST", this.endpoints.ai.chat, response));
394
- const reader = new GenAIChunkReader_1.GenAIChunkReader(response.body.getReader());
395
- yield __await(yield* __asyncDelegator(__asyncValues(reader.read())));
396
- });
397
- }
398
- sendFeedback(rating) {
399
- return this.post(this.endpoints.ai.sendFeedback, rating);
400
- }
401
- get(endpoint, v) {
402
- return this.makeRequest("GET", this.withVersion(endpoint, v));
403
- }
404
- post(endpoint, data) {
405
- return this.makeRequest("POST", endpoint, data);
406
- }
407
- put(endpoint, data) {
408
- return this.makeRequest("PUT", endpoint, data);
409
- }
410
- delete(endpoint) {
411
- return this.makeRequest("DELETE", endpoint);
412
- }
413
- makeAbsolute(endpoint) {
414
- return endpoint.startsWith(this.tenantBaseUrl) || endpoint === this.tenantBaseUrlNoTrailingSlash
415
- ? endpoint
416
- : (this.tenantBaseUrl + endpoint.replace(/^\//, ""));
417
- }
418
- fetch(endpoint, init) {
419
- var _a;
420
- return __awaiter(this, void 0, void 0, function* () {
421
- const requestInit = init;
422
- return yield (0, cross_fetch_1.default)(this.makeAbsolute(endpoint), Object.assign(Object.assign({}, (requestInit !== null && requestInit !== void 0 ? requestInit : {})), { headers: Object.assign(Object.assign({}, this.defaultHeaders), ((_a = requestInit === null || requestInit === void 0 ? void 0 : requestInit.headers) !== null && _a !== void 0 ? _a : {})) }));
423
- });
424
- }
425
- upload(method, endpoint, body, onProgress = () => undefined) {
426
- if (typeof XMLHttpRequest !== "undefined") {
427
- return new Promise((resolve, reject) => {
428
- let xhr = new XMLHttpRequest();
429
- xhr.onload = () => {
430
- if (xhr.status >= 200 && xhr.status < 300) {
431
- let data = xhr.getResponseHeader("Content-Type") === "application/json" ? JSON.parse(xhr.responseText) : xhr.responseText;
432
- resolve(data);
433
- }
434
- else {
435
- reject(new HttpError("GET", endpoint, xhr.status, xhr.statusText, xhr.responseText));
436
- }
437
- };
438
- xhr.upload.onprogress = (e) => onProgress(e);
439
- xhr.open(method, this.makeAbsolute(endpoint), true);
440
- xhr.send(body);
441
- });
442
- }
443
- else {
444
- return this.fetch(endpoint, { method, body })
445
- .then((r) => handleError(method, endpoint, r))
446
- .then(getBody);
447
- }
448
- }
449
- makeRequest(method, endpoint, data) {
450
- return this.fetch(endpoint, {
451
- method: method,
452
- headers: Object.assign({}, (data != null ? { "Content-Type": "application/json" } : {})),
453
- body: data != null ? JSON.stringify(data) : undefined,
454
- credentials: this.authorization == null ? "include" : undefined
455
- })
456
- .then((r) => handleError(method, endpoint, r))
457
- .then(getBody);
458
- }
459
- fetchRawData(endpoint, v) {
460
- return (0, cross_fetch_1.default)(this.withVersion(endpoint, v), {
461
- headers: this.defaultHeaders,
462
- credentials: this.authorization == null ? "include" : undefined
463
- })
464
- .then((r) => handleError("GET", endpoint, r))
465
- .then(response => response.arrayBuffer());
466
- }
467
- withVersion(endpoint, v) {
468
- let url = new URL(this.makeAbsolute(endpoint));
469
- if (v) {
470
- url.searchParams.append("v", v);
471
- }
472
- return url.toString();
473
- }
474
- }
475
- exports.FluidTopicsApi = FluidTopicsApi;
476
- exports.default = FluidTopicsApi;
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addUnauthenticatedUserSearchPreferencesChangeHandler = exports.getUnauthenticatedUserSearchPreferences = exports.setUnauthenticatedUserSearchPreferences = void 0;
4
- const wnd = (typeof window === "undefined" ? globalThis : window);
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
- }
22
- function getStorageKey(tenantBaseUrl) {
23
- return `${tenantBaseUrl}-FluidTopicsUnauthenticatedUserSearchPreferences`;
24
- }
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;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.userHasRole = void 0;
4
- const public_1 = require("../types/ft-common/public");
5
- const rolesInheritance = {
6
- [public_1.FtUserRole.PERSONAL_BOOK_SHARE_USER]: [public_1.FtUserRole.PERSONAL_BOOK_USER],
7
- [public_1.FtUserRole.HTML_EXPORT_USER]: [public_1.FtUserRole.PERSONAL_BOOK_USER],
8
- [public_1.FtUserRole.PDF_EXPORT_USER]: [public_1.FtUserRole.PERSONAL_BOOK_USER],
9
- [public_1.FtUserRole.KHUB_ADMIN]: [public_1.FtUserRole.CONTENT_PUBLISHER],
10
- [public_1.FtUserRole.ADMIN]: [public_1.FtUserRole.KHUB_ADMIN, public_1.FtUserRole.USERS_ADMIN, public_1.FtUserRole.PORTAL_ADMIN],
11
- [public_1.FtUserRole.DEVELOPER]: [public_1.FtUserRole.BETA_USER, public_1.FtUserRole.DEBUG_USER],
12
- };
13
- function roleMatches(actual, expected) {
14
- var _a;
15
- return actual === expected || ((_a = rolesInheritance[actual]) !== null && _a !== void 0 ? _a : []).some((inherited) => roleMatches(inherited, expected));
16
- }
17
- function userHasRole(sessionOrProfileOrRoles, expectedRole) {
18
- var _a;
19
- if (sessionOrProfileOrRoles == null) {
20
- return false;
21
- }
22
- const roles = Array.isArray(sessionOrProfileOrRoles)
23
- ? sessionOrProfileOrRoles
24
- : Array.isArray(sessionOrProfileOrRoles.roles)
25
- ? sessionOrProfileOrRoles.roles
26
- : Array.isArray((_a = sessionOrProfileOrRoles.profile) === null || _a === void 0 ? void 0 : _a.roles)
27
- ? sessionOrProfileOrRoles.profile.roles
28
- : [];
29
- return roles.some(role => roleMatches(role, expectedRole));
30
- }
31
- exports.userHasRole = userHasRole;