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