@fluid-topics/public-api 1.0.57 → 1.0.58

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/index.js CHANGED
@@ -22,9 +22,34 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22
22
  step((generator = generator.apply(thisArg, _arguments || [])).next());
23
23
  });
24
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
+ };
25
49
  Object.defineProperty(exports, "__esModule", { value: true });
26
50
  exports.FluidTopicsApi = exports.HttpErrorEvent = exports.HttpError = void 0;
27
51
  require("cross-fetch/polyfill");
52
+ const GenAIChunkReader_1 = require("./helpers/GenAIChunkReader");
28
53
  const wnd = (typeof window === "undefined" ? globalThis : window);
29
54
  __exportStar(require("./types/ft-common/public"), exports);
30
55
  __exportStar(require("./types/ft-server/public"), exports);
@@ -172,6 +197,9 @@ class FluidTopicsApi {
172
197
  }
173
198
  })
174
199
  },
200
+ ai: {
201
+ generate: `api/ai/generate`
202
+ }
175
203
  };
176
204
  //@ts-ignore
177
205
  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();
@@ -321,6 +349,21 @@ class FluidTopicsApi {
321
349
  listMyBookmarks(userId) {
322
350
  return this.get(this.endpoints.users.userId(userId).bookmarks.list);
323
351
  }
352
+ generate(profileId, parameters) {
353
+ return __asyncGenerator(this, arguments, function* generate_1() {
354
+ const response = yield __await(this.fetch(this.endpoints.ai.generate, {
355
+ method: "POST",
356
+ headers: {
357
+ "Content-Type": "application/json",
358
+ },
359
+ body: JSON.stringify({ profileId, parameters }),
360
+ credentials: this.authorization == null ? "include" : undefined
361
+ }));
362
+ yield __await(handleError("POST", this.endpoints.ai.generate, response));
363
+ const reader = new GenAIChunkReader_1.GenAIChunkReader(response.body.getReader());
364
+ yield __await(yield* __asyncDelegator(__asyncValues(reader.read())));
365
+ });
366
+ }
324
367
  get(endpoint, v) {
325
368
  return this.makeRequest("GET", this.withVersion(endpoint, v));
326
369
  }
@@ -759,6 +759,7 @@ var FtUserRole;
759
759
  FtUserRole["PRINT_USER"] = "PRINT_USER";
760
760
  FtUserRole["RATING_USER"] = "RATING_USER";
761
761
  FtUserRole["FEEDBACK_USER"] = "FEEDBACK_USER";
762
+ FtUserRole["GENERATIVE_AI_USER"] = "GENERATIVE_AI_USER";
762
763
  FtUserRole["CONTENT_PUBLISHER"] = "CONTENT_PUBLISHER";
763
764
  FtUserRole["KHUB_ADMIN"] = "KHUB_ADMIN";
764
765
  FtUserRole["USERS_ADMIN"] = "USERS_ADMIN";
@@ -767,7 +768,7 @@ var FtUserRole;
767
768
  FtUserRole["DEVELOPER"] = "DEVELOPER";
768
769
  })(FtUserRole = exports.FtUserRole || (exports.FtUserRole = {}));
769
770
  const isFtUserRole = (o) => {
770
- return ["PERSONAL_BOOK_USER", "PERSONAL_BOOK_SHARE_USER", "HTML_EXPORT_USER", "PDF_EXPORT_USER", "SAVED_SEARCH_USER", "COLLECTION_USER", "OFFLINE_USER", "ANALYTICS_USER", "BETA_USER", "DEBUG_USER", "PRINT_USER", "RATING_USER", "FEEDBACK_USER", "CONTENT_PUBLISHER", "KHUB_ADMIN", "USERS_ADMIN", "PORTAL_ADMIN", "ADMIN", "DEVELOPER"].includes(o);
771
+ return ["PERSONAL_BOOK_USER", "PERSONAL_BOOK_SHARE_USER", "HTML_EXPORT_USER", "PDF_EXPORT_USER", "SAVED_SEARCH_USER", "COLLECTION_USER", "OFFLINE_USER", "ANALYTICS_USER", "BETA_USER", "DEBUG_USER", "PRINT_USER", "RATING_USER", "FEEDBACK_USER", "GENERATIVE_AI_USER", "CONTENT_PUBLISHER", "KHUB_ADMIN", "USERS_ADMIN", "PORTAL_ADMIN", "ADMIN", "DEVELOPER"].includes(o);
771
772
  };
772
773
  exports.isFtUserRole = isFtUserRole;
773
774
  const isFtAuthenticationIdentifier = (o) => {
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).fluidtopics={})}(this,(function(e){"use strict";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};!function(e){!function(t){var r={searchParams:"URLSearchParams"in e,iterable:"Symbol"in e&&"iterator"in Symbol,blob:"FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),formData:"FormData"in e,arrayBuffer:"ArrayBuffer"in e};if(r.arrayBuffer)var i=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],a=ArrayBuffer.isView||function(e){return e&&i.indexOf(Object.prototype.toString.call(e))>-1};function s(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function n(e){return"string"!=typeof e&&(e=String(e)),e}function o(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return r.iterable&&(t[Symbol.iterator]=function(){return t}),t}function l(e){this.map={},e instanceof l?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function u(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function c(e){return new Promise((function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}}))}function d(e){var t=new FileReader,r=c(t);return t.readAsArrayBuffer(e),r}function p(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function h(){return this.bodyUsed=!1,this._initBody=function(e){var t;this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:r.blob&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:r.formData&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:r.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():r.arrayBuffer&&r.blob&&(t=e)&&DataView.prototype.isPrototypeOf(t)?(this._bodyArrayBuffer=p(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):r.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(e)||a(e))?this._bodyArrayBuffer=p(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},r.blob&&(this.blob=function(){var e=u(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?u(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(d)}),this.text=function(){var e,t,r,i=u(this);if(i)return i;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,r=c(t),t.readAsText(e),r;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),r=new Array(t.length),i=0;i<t.length;i++)r[i]=String.fromCharCode(t[i]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},r.formData&&(this.formData=function(){return this.text().then(A)}),this.json=function(){return this.text().then(JSON.parse)},this}l.prototype.append=function(e,t){e=s(e),t=n(t);var r=this.map[e];this.map[e]=r?r+", "+t:t},l.prototype.delete=function(e){delete this.map[s(e)]},l.prototype.get=function(e){return e=s(e),this.has(e)?this.map[e]:null},l.prototype.has=function(e){return this.map.hasOwnProperty(s(e))},l.prototype.set=function(e,t){this.map[s(e)]=n(t)},l.prototype.forEach=function(e,t){for(var r in this.map)this.map.hasOwnProperty(r)&&e.call(t,this.map[r],r,this)},l.prototype.keys=function(){var e=[];return this.forEach((function(t,r){e.push(r)})),o(e)},l.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),o(e)},l.prototype.entries=function(){var e=[];return this.forEach((function(t,r){e.push([r,t])})),o(e)},r.iterable&&(l.prototype[Symbol.iterator]=l.prototype.entries);var y=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function f(e,t){var r,i,a=(t=t||{}).body;if(e instanceof f){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new l(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,a||null==e._bodyInit||(a=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new l(t.headers)),this.method=(r=t.method||this.method||"GET",i=r.toUpperCase(),y.indexOf(i)>-1?i:r),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&a)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(a)}function A(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var r=e.split("="),i=r.shift().replace(/\+/g," "),a=r.join("=").replace(/\+/g," ");t.append(decodeURIComponent(i),decodeURIComponent(a))}})),t}function m(e,t){t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new l(t.headers),this.url=t.url||"",this._initBody(e)}f.prototype.clone=function(){return new f(this,{body:this._bodyInit})},h.call(f.prototype),h.call(m.prototype),m.prototype.clone=function(){return new m(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new l(this.headers),url:this.url})},m.error=function(){var e=new m(null,{status:0,statusText:""});return e.type="error",e};var E=[301,302,303,307,308];m.redirect=function(e,t){if(-1===E.indexOf(t))throw new RangeError("Invalid status code");return new m(null,{status:t,headers:{location:e}})},t.DOMException=e.DOMException;try{new t.DOMException}catch(e){t.DOMException=function(e,t){this.message=e,this.name=t;var r=Error(e);this.stack=r.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function g(e,i){return new Promise((function(a,s){var n=new f(e,i);if(n.signal&&n.signal.aborted)return s(new t.DOMException("Aborted","AbortError"));var o=new XMLHttpRequest;function u(){o.abort()}o.onload=function(){var e,t,r={status:o.status,statusText:o.statusText,headers:(e=o.getAllResponseHeaders()||"",t=new l,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(e){var r=e.split(":"),i=r.shift().trim();if(i){var a=r.join(":").trim();t.append(i,a)}})),t)};r.url="responseURL"in o?o.responseURL:r.headers.get("X-Request-URL");var i="response"in o?o.response:o.responseText;a(new m(i,r))},o.onerror=function(){s(new TypeError("Network request failed"))},o.ontimeout=function(){s(new TypeError("Network request failed"))},o.onabort=function(){s(new t.DOMException("Aborted","AbortError"))},o.open(n.method,n.url,!0),"include"===n.credentials?o.withCredentials=!0:"omit"===n.credentials&&(o.withCredentials=!1),"responseType"in o&&r.blob&&(o.responseType="blob"),n.headers.forEach((function(e,t){o.setRequestHeader(t,e)})),n.signal&&(n.signal.addEventListener("abort",u),o.onreadystatechange=function(){4===o.readyState&&n.signal.removeEventListener("abort",u)}),o.send(void 0===n._bodyInit?null:n._bodyInit)}))}g.polyfill=!0,e.fetch||(e.fetch=g,e.Headers=l,e.Request=f,e.Response=m),t.Headers=l,t.Request=f,t.Response=m,t.fetch=g,Object.defineProperty(t,"__esModule",{value:!0})}({})}("undefined"!=typeof self?self:t);const r=e=>"object"==typeof e&&null!=e,i=e=>"boolean"==typeof e,a=e=>"number"==typeof e,s=e=>"string"==typeof e;var n;e.FtMyLibraryColors=void 0,(n=e.FtMyLibraryColors||(e.FtMyLibraryColors={})).black="black",n.green="green",n.blue="blue",n.purple="purple",n.red="red",n.orange="orange",n.yellow="yellow";const o=e=>["black","green","blue","purple","red","orange","yellow"].includes(e);var l;e.FtTopicOriginType=void 0,(l=e.FtTopicOriginType||(e.FtTopicOriginType={})).OFFICIAL="OFFICIAL",l.PERSONAL="PERSONAL",l.SHARED="SHARED";const u=e=>["OFFICIAL","PERSONAL","SHARED"].includes(e),c=e=>r(e)&&Array.isArray(e.values)&&e.values.every((e=>Array.isArray(e)&&e.every((e=>s(e)))))&&s(e.key),d=e=>r(e)&&s(e.notes)&&Array.isArray(e.children)&&e.children.every((e=>d(e)))&&(null==e.topicLink||p(e.topicLink))&&s(e.title)&&(null==e.htmlContent||s(e.htmlContent)),p=e=>r(e)&&s(e.tocId)&&s(e.contentId)&&s(e.mapId),h=e=>r(e)&&s(e.topicStylesheetUrl)&&s(e.titleStylesheetUrl)&&Array.isArray(e.customCssClasses)&&e.customCssClasses.every((e=>s(e))),y=e=>r(e)&&(null==e.prettyUrl||s(e.prettyUrl))&&(null==e.hasRating||i(e.hasRating))&&s(e.tocId)&&Array.isArray(e.children)&&e.children.every((e=>y(e)))&&(null==e.origin||f(e.origin))&&s(e.contentId)&&s(e.title),f=e=>r(e)&&s(e.mapTitle)&&Array.isArray(e.breadcrumb)&&e.breadcrumb.every((e=>s(e)))&&s(e.tocId)&&s(e.contentId)&&s(e.mapId)&&u(e.type);var A;e.FtTopicContentTarget=void 0,(A=e.FtTopicContentTarget||(e.FtTopicContentTarget={})).THIRD_PARTY="THIRD_PARTY",A.OFF_THE_GRID="OFF_THE_GRID",A.CONTENT_PACKAGER="CONTENT_PACKAGER",A.PAGES="PAGES",A.DESIGNED_READER="DESIGNED_READER";var m;e.FtMetadataHomeLayout=void 0,(m=e.FtMetadataHomeLayout||(e.FtMetadataHomeLayout={})).CLASSIC="CLASSIC",m.CUSTOM="CUSTOM",m.DESIGNER="DESIGNER";const E=e=>r(e)&&a(e.count)&&s(e.label)&&(null==e.lang||s(e.lang));var g;e.FtFacetType=void 0,(g=e.FtFacetType||(e.FtFacetType={})).AND="AND",g.OR="OR",g.MONOVALUED="MONOVALUED";const b=e=>r(e)&&Array.isArray(e.values)&&e.values.every((e=>s(e)))&&(null==e.hierarchicalValues||Array.isArray(e.hierarchicalValues)&&e.hierarchicalValues.every((e=>Array.isArray(e)&&e.every((e=>s(e))))))&&s(e.label)&&s(e.key);var T;e.FtMetadataSortRule=void 0,(T=e.FtMetadataSortRule||(e.FtMetadataSortRule={})).NONE="NONE",T.ALPHABET="ALPHABET",T.VERSION="VERSION";const S=e=>["NONE","ALPHABET","VERSION"].includes(e),R=e=>r(e)&&S(e.sortRule)&&s(e.label)&&i(e.reverseSort)&&s(e.key),F=e=>r(e)&&(null==e.periodFilter||P(e.periodFilter))&&s(e.query)&&(null==e.scope||oe(e.scope))&&Array.isArray(e.filters)&&e.filters.every((e=>J(e)))&&Array.isArray(e.sort)&&e.sort.every((e=>de(e)))&&(null==e.virtualField||$(e.virtualField))&&(null==e.contentLocale||s(e.contentLocale));var O;e.FtRatingType=void 0,(O=e.FtRatingType||(e.FtRatingType={})).STARS="STARS",O.LIKE="LIKE",O.DICHOTOMOUS="DICHOTOMOUS",O.NO_RATING="NO_RATING";const U=e=>["STARS","LIKE","DICHOTOMOUS","NO_RATING"].includes(e),I=e=>r(e)&&s(e.date)&&U(e.type)&&a(e.value),v=e=>r(e)&&(null==e.rating||I(e.rating))&&U(e.type),_=e=>r(e)&&s(e.date)&&s(e.tocId)&&U(e.type)&&a(e.value),C=e=>r(e)&&Array.isArray(e.ratings)&&e.ratings.every((e=>_(e)))&&U(e.type),L=e=>r(e)&&Array.isArray(e.filter)&&e.filter.every((e=>s(e)))&&Array.isArray(e.prior)&&e.prior.every((e=>s(e))),D=e=>r(e)&&s(e.from)&&s(e.to),P=e=>r(e)&&(null==e.period||D(e.period))&&M(e.periodType);var N;e.FtPeriodFilterType=void 0,(N=e.FtPeriodFilterType||(e.FtPeriodFilterType={})).LAST_WEEK="LAST_WEEK",N.LAST_MONTH="LAST_MONTH",N.LAST_YEAR="LAST_YEAR",N.CUSTOM="CUSTOM";const M=e=>["LAST_WEEK","LAST_MONTH","LAST_YEAR","CUSTOM"].includes(e),k=e=>r(e)&&i(e.negative)&&Array.isArray(e.values)&&e.values.every((e=>s(e)))&&s(e.key);var w;e.FtSearchSortCriterionOrder=void 0,(w=e.FtSearchSortCriterionOrder||(e.FtSearchSortCriterionOrder={})).ASC="ASC",w.DESC="DESC";const B=e=>["ASC","DESC"].includes(e);var H;e.FtSearchSortCriterionType=void 0,(H=e.FtSearchSortCriterionType||(e.FtSearchSortCriterionType={})).ALPHA="ALPHA",H.NATURAL="NATURAL";const x=e=>["ALPHA","NATURAL"].includes(e);var V;e.FtVirtualField=void 0,(V=e.FtVirtualField||(e.FtVirtualField={})).EVERYWHERE="EVERYWHERE",V.TITLE_ONLY="TITLE_ONLY",V.NONE="NONE";const $=e=>["EVERYWHERE","TITLE_ONLY","NONE"].includes(e),K=e=>r(e)&&a(e.totalResultsCount)&&i(e.isLastPage)&&a(e.currentPage)&&a(e.totalClustersCount);var j;e.FtEditorialType=void 0,(j=e.FtEditorialType||(e.FtEditorialType={})).ARTICLE="ARTICLE",j.BOOK="BOOK",j.SHARED_BOOK="SHARED_BOOK";const G=e=>["ARTICLE","BOOK","SHARED_BOOK"].includes(e);var q;e.FtOpenMode=void 0,(q=e.FtOpenMode||(e.FtOpenMode={})).FLUIDTOPICS="FLUIDTOPICS",q.EXTERNAL="EXTERNAL";const X=e=>["FLUIDTOPICS","EXTERNAL"].includes(e),Y=e=>r(e)&&(null==e.perPage||a(e.perPage))&&a(e.page);var z;e.FtCollectionDocumentType=void 0,(z=e.FtCollectionDocumentType||(e.FtCollectionDocumentType={})).MAP="MAP",z.DOCUMENT="DOCUMENT",z.TOPIC="TOPIC",z.PERSONAL_BOOK="PERSONAL_BOOK",z.SHARED_BOOK="SHARED_BOOK";const W=e=>["MAP","DOCUMENT","TOPIC","PERSONAL_BOOK","SHARED_BOOK"].includes(e),J=e=>r(e)&&i(e.negative)&&Array.isArray(e.values)&&e.values.every((e=>s(e)))&&s(e.label)&&s(e.key),Q=e=>r(e)&&a(e.weight)&&s(e.value)&&s(e.key),Z=e=>r(e)&&Array.isArray(e.entries)&&e.entries.every((e=>ee(e)))&&(null==e.metadataVariableAxis||s(e.metadataVariableAxis)),ee=e=>r(e)&&(null==e.document||te(e.document))&&(null==e.topic||ie(e.topic))&&se(e.type)&&(null==e.map||re(e.map)),te=e=>r(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>b(e)))&&X(e.openMode)&&s(e.documentUrl)&&s(e.mimeType)&&s(e.title)&&(null==e.lastPublicationDate||s(e.lastPublicationDate))&&s(e.viewerUrl)&&s(e.contentUrl)&&s(e.filename)&&s(e.htmlTitle)&&(null==e.originUrl||s(e.originUrl))&&s(e.documentId)&&s(e.lastEditionDate)&&s(e.htmlExcerpt),re=e=>r(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>b(e)))&&(null==e.openMode||X(e.openMode))&&G(e.editorialType)&&s(e.title)&&(null==e.lastPublicationDate||s(e.lastPublicationDate))&&s(e.htmlTitle)&&(null==e.originUrl||s(e.originUrl))&&s(e.mapUrl)&&s(e.readerUrl)&&s(e.mapId)&&(null==e.lastEditionDate||s(e.lastEditionDate))&&s(e.htmlExcerpt),ie=e=>r(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>b(e)))&&X(e.openMode)&&s(e.contentId)&&Array.isArray(e.resources)&&e.resources.every((e=>he(e)))&&s(e.title)&&s(e.mapTitle)&&s(e.topicUrl)&&s(e.contentUrl)&&s(e.htmlTitle)&&Array.isArray(e.breadcrumb)&&e.breadcrumb.every((e=>s(e)))&&s(e.tocId)&&(null==e.originUrl||s(e.originUrl))&&s(e.readerUrl)&&s(e.mapId)&&(null==e.lastEditionDate||s(e.lastEditionDate))&&s(e.htmlExcerpt);var ae;e.FtSearchResultType=void 0,(ae=e.FtSearchResultType||(e.FtSearchResultType={})).MAP="MAP",ae.DOCUMENT="DOCUMENT",ae.TOPIC="TOPIC";const se=e=>["MAP","DOCUMENT","TOPIC"].includes(e);var ne;e.FtSearchScope=void 0,(ne=e.FtSearchScope||(e.FtSearchScope={})).DEFAULT="DEFAULT",ne.DOCUMENTS="DOCUMENTS",ne.ALL_TOPICS="ALL_TOPICS";const oe=e=>["DEFAULT","DOCUMENTS","ALL_TOPICS"].includes(e),le=e=>r(e)&&i(e.hierarchical)&&s(e.label)&&i(e.multiSelectionable)&&s(e.key)&&Array.isArray(e.rootNodes)&&e.rootNodes.every((e=>ce(e))),ue=e=>r(e)&&(null==e.maxDepth||a(e.maxDepth))&&s(e.id),ce=e=>r(e)&&a(e.totalResultsCount)&&i(e.descendantSelected)&&Array.isArray(e.childNodes)&&e.childNodes.every((e=>ce(e)))&&s(e.label)&&s(e.value)&&i(e.selected),de=e=>r(e)&&x(e.type)&&s(e.key)&&B(e.order),pe=e=>r(e)&&s(e.suggestedQuery)&&s(e.htmlSuggestedQuery),he=e=>r(e)&&s(e.filename)&&s(e.resourceUrl)&&s(e.id)&&s(e.mimeType)&&s(e.resourceContentUrl)&&s(e.viewerUrl),ye=e=>r(e)&&(null==e.filenameExtension||s(e.filenameExtension))&&(null==e.editorialType||G(e.editorialType))&&(null==e.mimeType||s(e.mimeType))&&se(e.type)&&s(e.value);var fe;e.FtUserRole=void 0,(fe=e.FtUserRole||(e.FtUserRole={})).PERSONAL_BOOK_USER="PERSONAL_BOOK_USER",fe.PERSONAL_BOOK_SHARE_USER="PERSONAL_BOOK_SHARE_USER",fe.HTML_EXPORT_USER="HTML_EXPORT_USER",fe.PDF_EXPORT_USER="PDF_EXPORT_USER",fe.SAVED_SEARCH_USER="SAVED_SEARCH_USER",fe.COLLECTION_USER="COLLECTION_USER",fe.OFFLINE_USER="OFFLINE_USER",fe.ANALYTICS_USER="ANALYTICS_USER",fe.BETA_USER="BETA_USER",fe.DEBUG_USER="DEBUG_USER",fe.PRINT_USER="PRINT_USER",fe.RATING_USER="RATING_USER",fe.FEEDBACK_USER="FEEDBACK_USER",fe.CONTENT_PUBLISHER="CONTENT_PUBLISHER",fe.KHUB_ADMIN="KHUB_ADMIN",fe.USERS_ADMIN="USERS_ADMIN",fe.PORTAL_ADMIN="PORTAL_ADMIN",fe.ADMIN="ADMIN",fe.DEVELOPER="DEVELOPER";const Ae=e=>["PERSONAL_BOOK_USER","PERSONAL_BOOK_SHARE_USER","HTML_EXPORT_USER","PDF_EXPORT_USER","SAVED_SEARCH_USER","COLLECTION_USER","OFFLINE_USER","ANALYTICS_USER","BETA_USER","DEBUG_USER","PRINT_USER","RATING_USER","FEEDBACK_USER","CONTENT_PUBLISHER","KHUB_ADMIN","USERS_ADMIN","PORTAL_ADMIN","ADMIN","DEVELOPER"].includes(e),me=e=>r(e)&&s(e.identifier)&&s(e.realm),Ee=e=>r(e)&&Array.isArray(e.defaultFilters)&&e.defaultFilters.every((e=>k(e))),ge=e=>r(e)&&(null==e.emailAddress||s(e.emailAddress))&&(null==e.displayName||s(e.displayName))&&Array.isArray(e.roles)&&e.roles.every((e=>Ae(e)))&&(null==e.userId||s(e.userId)),be=e=>"object"==typeof e&&null!=e,Te=e=>"boolean"==typeof e,Se=e=>"number"==typeof e,Re=e=>"string"==typeof e;var Fe;e.FtConfigurationHistoryEntryStatus=void 0,(Fe=e.FtConfigurationHistoryEntryStatus||(e.FtConfigurationHistoryEntryStatus={})).VALID="VALID",Fe.INVALID="INVALID";const Oe=e=>be(e)&&Te(e.mailsSentByFluidTopics)&&Te(e.mailsSentByFluidTopicsForUnauthenticatedUsers)&&Array.isArray(e.recipients)&&e.recipients.every((e=>Re(e)))&&Array.isArray(e.bodyMetadataIds)&&e.bodyMetadataIds.every((e=>Re(e)))&&Array.isArray(e.subjectMetadataIds)&&e.subjectMetadataIds.every((e=>Re(e))),Ue=e=>be(e)&&(null==e.parentsVisibility||Array.isArray(e.parentsVisibility)&&e.parentsVisibility.every((e=>Te(e))))&&Te(e.isVisible),Ie=e=>be(e)&&(null==e.prettyUrl||Re(e.prettyUrl))&&(null==e.hasRating||Te(e.hasRating))&&(null==e.pageToc||Array.isArray(e.pageToc))&&(null==e.tocId||Re(e.tocId))&&Array.isArray(e.children)&&e.children.every((e=>Ie(e)))&&(null==e.pageConfiguration||Ue(e.pageConfiguration))&&(null==e.contentId||Re(e.contentId))&&(null==e.title||Re(e.title)),ve=e=>be(e)&&Te(e.splitCurrentPageToc),_e={[e.FtUserRole.PERSONAL_BOOK_SHARE_USER]:[e.FtUserRole.PERSONAL_BOOK_USER],[e.FtUserRole.HTML_EXPORT_USER]:[e.FtUserRole.PERSONAL_BOOK_USER],[e.FtUserRole.PDF_EXPORT_USER]:[e.FtUserRole.PERSONAL_BOOK_USER],[e.FtUserRole.KHUB_ADMIN]:[e.FtUserRole.CONTENT_PUBLISHER],[e.FtUserRole.ADMIN]:[e.FtUserRole.KHUB_ADMIN,e.FtUserRole.USERS_ADMIN,e.FtUserRole.PORTAL_ADMIN],[e.FtUserRole.DEVELOPER]:[e.FtUserRole.BETA_USER,e.FtUserRole.DEBUG_USER]};function Ce(e,t){return e===t||(_e[e]??[]).some((e=>Ce(e,t)))}const Le="undefined"==typeof window?globalThis:window;function De(e){let t={};for(let r in e){let i=e[r];("object"!=typeof i||Array.isArray(i))&&(i={prior:i});for(let e of["prior","filter"])i[e]=Array.isArray(i[e])?i[e]:[i[e]],i[e]=i[e].map((e=>null!=e?""+e:"")).filter((e=>""!==e));t[r]=i}return t}function Pe(e){return`${e}-FluidTopicsUnauthenticatedUserSearchPreferences`}const Ne="undefined"==typeof window?globalThis:window;class Me extends Error{method;endpoint;status;statusText;body;constructor(e,t,r,i,a){super(`${e} ${t} -> ${r} - ${i}: ${a}`),this.method=e,this.endpoint=t,this.status=r,this.statusText=i,this.body=a}}class ke extends CustomEvent{constructor(e){super("ft-api-http-error",{detail:e})}}async function we(e,t,r){if(!r.ok){let i={method:e,endpoint:t,status:r.status,statusText:r.statusText,body:await r.text()};throw"function"==typeof Ne.dispatchEvent&&Ne.dispatchEvent(new ke(i)),new Me(i.method,i.endpoint,i.status,i.statusText,i.body)}return r}function Be(e){return"application/json"===e.headers.get("Content-Type")?e.json():e.text()}class He{tenantBaseUrl;ftCallingApp;authorization;searchLabel;endpoints={authentication:{login:"api/authentication/login",logout:"api/authentication/logout",currentSession:"api/authentication/current-session"},khub:{maps:{mapId:e=>({info:`api/khub/maps/${e}`,toc:`api/khub/maps/${e}/toc`,pages:`api/khub/maps/${e}/pages`,feedback:`api/khub/maps/${e}/feedback`,rating:`api/khub/maps/${e}/rating`,attachments:{list:`api/khub/maps/${e}/attachments`,attachmentId:t=>({content:`api/khub/maps/${e}/attachments/${t}/content`})},resources:{list:`api/khub/maps/${e}/resources`,resourceId:t=>({content:`api/khub/maps/${e}/resources/${t}/content`})},topics:{contentId:t=>({info:`api/khub/maps/${e}/topics/${t}`,content:`api/khub/maps/${e}/topics/${t}/content`}),tocId:t=>({feedback:`api/khub/maps/${e}/topics/${t}/feedback`,rating:`api/khub/maps/${e}/topics/${t}/rating`})}})},documents:{documentId:e=>({info:`api/khub/documents/${e}`,content:`api/khub/documents/${e}/content`,text:`api/khub/documents/${e}/content/text`,feedback:`api/khub/documents/${e}/feedback`,rating:`api/khub/documents/${e}/rating`})},suggest:"api/khub/suggest",clusteredSearch:"api/khub/clustered-search",locales:"api/khub/locales"},users:{userId:e=>({collections:{collectionId:t=>({documents:`api/users/${e}/collections/${t}/documents`})},searches:{list:`api/users/${e}/searches`},bookmarks:{list:`api/users/${e}/bookmarks`}})},stylesheets:{fonts:"api/stylesheets/fonts.css",theme:"api/stylesheets/theme.css",content:{title:"api/stylesheets/content/title.css",topic:"api/stylesheets/content/topic.css"}},configuration:{reader:"api/configuration/reader",metadata:"api/configuration/metadata"},locales:{ui:"api/locales/ui"},messages:{locale:e=>({fluidTopics:{contextName:t=>({endpoint:`api/messages/${e}/fluid-topics/${t}`})},custom:{contextName:t=>({endpoint:`api/messages/${e}/custom/${t}`})}})}};get defaultHeaders(){return{...this.authorization,...this.searchLabel,"Ft-Calling-App":this.ftCallingApp}}constructor(e,t,r){e=(e??Ne.fluidTopicsBaseUrl??Ne.__gwt_ft_moduleBase??"").trim(),this.tenantBaseUrl=e.endsWith("/")?e:e+"/",r&&void 0!==Ne.location&&Ne.location.href.startsWith(this.tenantBaseUrl)?this.ftCallingApp=t:this.ftCallingApp=`ft-public-api/${t}`}setApiKey(e){this.authorization={Authorization:"Bearer "+e}}setCredentials(e,t){var r;this.authorization={Authorization:"Basic "+(r=`${e}:${t}`,"undefined"!=typeof Buffer?Buffer.from(r).toString("base64"):btoa(r))}}clearAuthentication(){this.authorization=void 0}setSearchLabel(e){this.searchLabel={"FT-search-label":e}}clearSearchLabel(){this.searchLabel=void 0}login(e,t){let r={login:e,password:t,rememberMe:!0};return this.post(this.endpoints.authentication.login,r).then((r=>(this.setCredentials(e,t),r)))}logout(){return this.post(this.endpoints.authentication.logout).then((()=>this.clearAuthentication()))}getCurrentSession(){return this.get(this.endpoints.authentication.currentSession)}getReaderConfiguration(){return this.get(this.endpoints.configuration.reader)}getMap(e,t){return this.get(this.endpoints.khub.maps.mapId(e).info,t)}getTableOfContent(e,t){return this.get(this.endpoints.khub.maps.mapId(e).toc,t)}getPages(e,t){return this.get(this.endpoints.khub.maps.mapId(e).pages,t)}getTopic(e,t,r){return this.get(this.endpoints.khub.maps.mapId(e).topics.contentId(t).info,r)}getTopicHTMLContent(e,t,r,i){return this.get(this.endpoints.khub.maps.mapId(e).topics.contentId(t).content+(r?"?target="+r:""),i)}getMapAttachments(e,t){return this.get(this.endpoints.khub.maps.mapId(e).attachments.list,t)}getMapAttachmentContent(e,t,r){return this.fetchRawData(this.endpoints.khub.maps.mapId(e).attachments.attachmentId(t).content,r)}getMapResources(e,t){return this.get(this.endpoints.khub.maps.mapId(e).resources.list,t)}getMapResourceContent(e,t,r){return this.fetchRawData(this.endpoints.khub.maps.mapId(e).resources.resourceId(t).content,r)}getUnstructuredDocument(e,t){return this.get(this.endpoints.khub.documents.documentId(e).info,t)}getUnstructuredDocumentContent(e,t){return this.fetchRawData(this.endpoints.khub.documents.documentId(e).content,t)}getUnstructuredDocumentTextContent(e,t){return this.get(this.endpoints.khub.documents.documentId(e).text,t)}getCollectionDocuments(e,t){return this.get(this.endpoints.users.userId(e).collections.collectionId(t).documents)}getSuggestions(e){return this.post(this.endpoints.khub.suggest,e)}search(e){return this.post(this.endpoints.khub.clusteredSearch,e)}getAvailableSearchLocales(){return this.get(this.endpoints.khub.locales)}getAvailableUiLocales(){return this.get(this.endpoints.khub.locales)}getMetadataConfiguration(){return this.get(this.endpoints.configuration.metadata)}getMapRating(e){return this.get(this.endpoints.khub.maps.mapId(e).rating)}rateMap(e,t,r){return this.post(this.endpoints.khub.maps.mapId(e).rating,{type:t,value:r})}unrateMap(e){return this.delete(this.endpoints.khub.maps.mapId(e).rating)}sendMapFeedback(e,t,r){return this.post(this.endpoints.khub.maps.mapId(e).feedback,{message:t,from:r})}rateTopic(e,t,r,i){return this.post(this.endpoints.khub.maps.mapId(e).topics.tocId(t).rating,{type:r,value:i})}unrateTopic(e,t){return this.delete(this.endpoints.khub.maps.mapId(e).topics.tocId(t).rating)}sendTopicFeedback(e,t,r,i){return this.post(this.endpoints.khub.maps.mapId(e).topics.tocId(t).feedback,{message:r,from:i})}getDocumentRating(e){return this.get(this.endpoints.khub.documents.documentId(e).rating)}rateDocument(e,t,r){return this.post(this.endpoints.khub.documents.documentId(e).rating,{type:t,value:r})}unrateDocument(e){return this.delete(this.endpoints.khub.documents.documentId(e).rating)}sendDocumentFeedback(e,t,r){return this.post(this.endpoints.khub.documents.documentId(e).feedback,{message:t,from:r})}getFluidTopicsMessageContext(e,t){return this.get(this.endpoints.messages.locale(e).fluidTopics.contextName(t).endpoint)}getCustomMessageContext(e,t){return this.get(this.endpoints.messages.locale(e).custom.contextName(t).endpoint)}listMySearches(e){return this.get(this.endpoints.users.userId(e).searches.list)}listMyBookmarks(e){return this.get(this.endpoints.users.userId(e).bookmarks.list)}get(e,t){return this.makeRequest("GET",this.withVersion(e,t))}post(e,t){return this.makeRequest("POST",e,t)}put(e,t){return this.makeRequest("PUT",e,t)}delete(e){return this.makeRequest("DELETE",e)}makeAbsolute(e){return e.startsWith(this.tenantBaseUrl)?e:this.tenantBaseUrl+e.replace(/^\//,"")}async fetch(e,t){const r=t;return await fetch(this.makeAbsolute(e),{...r??{},headers:{...this.defaultHeaders,...r?.headers??{}}})}upload(e,t,r,i=(()=>{})){return"undefined"!=typeof XMLHttpRequest?new Promise(((a,s)=>{let n=new XMLHttpRequest;n.onload=()=>{if(n.status>=200&&n.status<300){let e="application/json"===n.getResponseHeader("Content-Type")?JSON.parse(n.responseText):n.responseText;a(e)}else s(new Me("GET",t,n.status,n.statusText,n.responseText))},n.upload.onprogress=e=>i(e),n.open(e,this.makeAbsolute(t),!0),n.send(r)})):this.fetch(t,{method:e,body:r}).then((r=>we(e,t,r))).then(Be)}makeRequest(e,t,r){return this.fetch(t,{method:e,headers:{...null!=r?{"Content-Type":"application/json"}:{}},body:null!=r?JSON.stringify(r):void 0,credentials:null==this.authorization?"include":void 0}).then((r=>we(e,t,r))).then(Be)}fetchRawData(e,t){return fetch(this.withVersion(e,t),{headers:this.defaultHeaders,credentials:null==this.authorization?"include":void 0}).then((t=>we("GET",e,t))).then((e=>e.arrayBuffer()))}withVersion(e,t){let r=new URL(this.makeAbsolute(e));return t&&r.searchParams.append("v",t),r.toString()}}e.FluidTopicsApi=He,e.HttpError=Me,e.HttpErrorEvent=ke,e.addUnauthenticatedUserSearchPreferencesChangeHandler=function(e,t){if(Le.localStorage){const r=Pe(e),i=e=>{e.storageArea===Le.localStorage&&e.key===r&&t(JSON.parse(e.newValue??"{}"))};return Le.addEventListener("storage",i),{removeHandler:()=>Le.removeEventListener("storage",i)}}console.error("Cannot handle unauthenticated preferences: local storage is unavailable.")},e.default=He,e.getUnauthenticatedUserSearchPreferences=function(e){if(Le.localStorage)return JSON.parse(Le.localStorage.getItem(Pe(e))??"{}");console.error("Cannot get unauthenticated preferences: local storage is unavailable.")},e.isFtAuthenticatedSession=e=>r(e)&&me(e.authenticationIdentifier)&&ge(e.profile),e.isFtAuthenticationIdentifier=me,e.isFtBookmark=e=>r(e)&&s(e.mapTitle)&&o(e.color)&&Array.isArray(e.breadcrumb)&&e.breadcrumb.every((e=>s(e)))&&s(e.tocId)&&s(e.lastUpdate)&&s(e.readerUrl)&&s(e.mapId)&&s(e.id)&&s(e.title)&&s(e.creationDate),e.isFtCollectionDocument=e=>r(e)&&i(e.deleted)&&(null==e.apiUrl||s(e.apiUrl))&&(null==e.portalUrl||s(e.portalUrl))&&s(e.id)&&s(e.title)&&W(e.type),e.isFtCollectionDocumentType=W,e.isFtConfigurationHistoryEntryStatus=e=>["VALID","INVALID"].includes(e),e.isFtCredentials=e=>r(e)&&s(e.password)&&(null==e.newPassword||s(e.newPassword))&&i(e.rememberMe)&&s(e.login),e.isFtEditorialType=G,e.isFtFacetType=e=>["AND","OR","MONOVALUED"].includes(e),e.isFtFeedbackCreation=e=>r(e)&&(null==e.from||s(e.from))&&s(e.message),e.isFtHttpErrorDetails=e=>r(e)&&s(e.endpoint)&&s(e.method)&&s(e.statusText)&&s(e.body)&&a(e.status),e.isFtLabeledSearchFilter=J,e.isFtMap=e=>r(e)&&(null==e.prettyUrl||s(e.prettyUrl))&&Array.isArray(e.metadata)&&e.metadata.every((e=>b(e)))&&X(e.openMode)&&(null==e.topicsApiEndpoint||s(e.topicsApiEndpoint))&&(null==e.description||s(e.description))&&(null==e.attachmentsApiEndpoint||s(e.attachmentsApiEndpoint))&&G(e.editorialType)&&s(e.baseId)&&s(e.clusterId)&&s(e.title)&&s(e.lastPublication)&&s(e.lastEdition)&&s(e.originId)&&(null==e.rightsApiEndpoint||s(e.rightsApiEndpoint))&&h(e.contentStyles)&&(null==e.originUrl||s(e.originUrl))&&s(e.fingerprint)&&s(e.readerUrl)&&(null==e.khubVersion||s(e.khubVersion))&&s(e.id)&&(null==e.lang||s(e.lang)),e.isFtMapAttachment=e=>be(e)&&Re(e.file)&&(null==e.size||Se(e.size))&&Te(e.externalLink)&&Re(e.name)&&Re(e.id)&&(null==e.mimeType||Re(e.mimeType))&&(null==e.viewerUrl||Re(e.viewerUrl)),e.isFtMapResource=e=>r(e)&&s(e.contentUrl)&&s(e.filename)&&s(e.id)&&s(e.mimeType),e.isFtMapStyles=h,e.isFtMessageContext=e=>r(e)&&s(e.name)&&r(e.messages)&&Object.keys(e.messages).every((e=>s(e)))&&Object.values(e.messages).every((e=>s(e)))&&s(e.locale),e.isFtMetadata=b,e.isFtMetadataConfiguration=e=>r(e)&&Array.isArray(e.descriptors)&&e.descriptors.every((e=>R(e))),e.isFtMetadataDescriptor=R,e.isFtMetadataHomeLayout=e=>["CLASSIC","CUSTOM","DESIGNER"].includes(e),e.isFtMetadataPreferenceConfiguration=L,e.isFtMetadataSortRule=S,e.isFtMyLibraryColors=o,e.isFtMySearch=e=>r(e)&&F(e.searchRequest)&&o(e.color)&&i(e.alert)&&s(e.description)&&s(e.id)&&s(e.ownerId)&&s(e.title)&&s(e.creationDate),e.isFtMySearchRequest=F,e.isFtOpenMode=X,e.isFtPageConfiguration=Ue,e.isFtPageRequest=Y,e.isFtPaginatedToc=e=>be(e)&&ve(e.configuration)&&Array.isArray(e.paginatedToc)&&e.paginatedToc.every((e=>Ie(e))),e.isFtPaginatedTocNode=Ie,e.isFtPaginationConfiguration=ve,e.isFtPeriod=D,e.isFtPeriodFilter=P,e.isFtPeriodFilterType=M,e.isFtPersonalBookCreation=e=>r(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>c(e)))&&Array.isArray(e.nodes)&&e.nodes.every((e=>d(e)))&&s(e.description)&&s(e.title),e.isFtPersonalBookMetadataUpdate=c,e.isFtPersonalBookNodeCreation=d,e.isFtPersonalBookTopicLinkCreation=p,e.isFtPublicationRating=I,e.isFtPublicationRatingSummary=v,e.isFtRatingCreation=e=>r(e)&&U(e.type)&&a(e.value),e.isFtRatingSummary=e=>r(e)&&(null==e.topics||C(e.topics))&&v(e.publication),e.isFtRatingType=U,e.isFtReaderConfiguration=e=>be(e)&&Oe(e.feedback)&&Se(e.loadAfterLastVisibleTopic)&&Re(e.relativeTopicPivotMetadata)&&Se(e.loadBeforeFirstVisibleTopic)&&Re(e.relativePivotMetadata),e.isFtReaderFeedbackConfiguration=Oe,e.isFtSearchFacet=le,e.isFtSearchFacetConf=ue,e.isFtSearchFacetEntry=ce,e.isFtSearchFilter=k,e.isFtSearchLocale=E,e.isFtSearchLocales=e=>r(e)&&Array.isArray(e.contentLocales)&&e.contentLocales.every((e=>E(e))),e.isFtSearchPreferences=Ee,e.isFtSearchPreferencesConfiguration=e=>r(e)&&r(e.metadata)&&Object.keys(e.metadata).every((e=>s(e)))&&Object.values(e.metadata).every((e=>L(e))),e.isFtSearchPreset=e=>r(e)&&s(e.name)&&Array.isArray(e.filters)&&e.filters.every((e=>k(e)))&&a(e.priority)&&(null==e.contentLocale||s(e.contentLocale)),e.isFtSearchPrior=Q,e.isFtSearchRequest=e=>r(e)&&(null==e.periodFilter||P(e.periodFilter))&&s(e.query)&&(null==e.scope||oe(e.scope))&&Y(e.paging)&&Array.isArray(e.filters)&&e.filters.every((e=>k(e)))&&Array.isArray(e.sort)&&e.sort.every((e=>de(e)))&&(null==e.uiLocale||s(e.uiLocale))&&(null==e.virtualField||$(e.virtualField))&&(null==e.contentLocale||s(e.contentLocale))&&(null==e.priors||Array.isArray(e.priors)&&e.priors.every((e=>Q(e))))&&Array.isArray(e.facets)&&e.facets.every((e=>ue(e))),e.isFtSearchResultCluster=Z,e.isFtSearchResultClusterEntry=ee,e.isFtSearchResultMap=re,e.isFtSearchResultTopic=ie,e.isFtSearchResultType=se,e.isFtSearchResultUnstructuredDocument=te,e.isFtSearchResults=e=>r(e)&&(null==e.spellcheck||pe(e.spellcheck))&&K(e.paging)&&Array.isArray(e.results)&&e.results.every((e=>Z(e)))&&Array.isArray(e.facets)&&e.facets.every((e=>le(e))),e.isFtSearchResultsPageInfo=K,e.isFtSearchScope=oe,e.isFtSearchSortCriterion=de,e.isFtSearchSortCriterionOrder=B,e.isFtSearchSortCriterionType=x,e.isFtSession=e=>r(e)&&(null==e.authenticationIdentifier||me(e.authenticationIdentifier))&&a(e.idleTimeoutInMillis)&&ge(e.profile)&&i(e.sessionAuthenticated)&&Ee(e.searchPreferences),e.isFtSpellcheck=pe,e.isFtSuggestRequest=e=>r(e)&&s(e.input)&&(null==e.scope||oe(e.scope))&&Array.isArray(e.filters)&&e.filters.every((e=>k(e)))&&Array.isArray(e.sort)&&e.sort.every((e=>de(e)))&&(null==e.maxCount||a(e.maxCount))&&(null==e.contentLocale||s(e.contentLocale)),e.isFtSuggestResult=ye,e.isFtSuggestResults=e=>r(e)&&Array.isArray(e.suggestions)&&e.suggestions.every((e=>ye(e))),e.isFtTocNode=y,e.isFtTopic=e=>r(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>b(e)))&&s(e.id)&&s(e.contentApiEndpoint)&&s(e.title),e.isFtTopicContentTarget=e=>["THIRD_PARTY","OFF_THE_GRID","CONTENT_PACKAGER","PAGES","DESIGNED_READER"].includes(e),e.isFtTopicOrigin=f,e.isFtTopicOriginType=u,e.isFtTopicRating=_,e.isFtTopicResource=he,e.isFtTopicsRatingSummary=C,e.isFtUiLocale=e=>r(e)&&s(e.displayName)&&s(e.languageTag)&&i(e.translated),e.isFtUnstructuredDocument=e=>r(e)&&(null==e.prettyUrl||s(e.prettyUrl))&&Array.isArray(e.metadata)&&e.metadata.every((e=>b(e)))&&s(e.openMode)&&(null==e.description||s(e.description))&&s(e.mimeType)&&(null==e.baseId||s(e.baseId))&&(null==e.clusterId||s(e.clusterId))&&s(e.contentApiEndpoint)&&s(e.title)&&(null==e.lastPublication||s(e.lastPublication))&&s(e.viewerUrl)&&s(e.lastEdition)&&s(e.filename)&&(null==e.originId||s(e.originId))&&s(e.rightsApiEndpoint)&&(null==e.originUrl||s(e.originUrl))&&(null==e.khubVersion||s(e.khubVersion))&&s(e.id)&&(null==e.lang||s(e.lang)),e.isFtUserProfile=ge,e.isFtUserRole=Ae,e.isFtVirtualField=$,e.setUnauthenticatedUserSearchPreferences=function(e,t){if(Le.localStorage){let r={...t,metadata:De(t.metadata??{})};const i=Pe(e),a=JSON.stringify(r);return Le.localStorage.setItem(i,a),Le.dispatchEvent(new StorageEvent("storage",{key:i,newValue:a,storageArea:Le.localStorage,url:Le.location.href})),r}console.error("Cannot set unauthenticated preferences: local storage is unavailable.")},e.userHasRole=function(e,t){return null!=e&&(Array.isArray(e)?e:Array.isArray(e.roles)?e.roles:Array.isArray(e.profile?.roles)?e.profile.roles:[]).some((e=>Ce(e,t)))}}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).fluidtopics={})}(this,(function(e){"use strict";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};!function(e){!function(t){var r={searchParams:"URLSearchParams"in e,iterable:"Symbol"in e&&"iterator"in Symbol,blob:"FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),formData:"FormData"in e,arrayBuffer:"ArrayBuffer"in e};if(r.arrayBuffer)var i=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],a=ArrayBuffer.isView||function(e){return e&&i.indexOf(Object.prototype.toString.call(e))>-1};function s(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function n(e){return"string"!=typeof e&&(e=String(e)),e}function o(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return r.iterable&&(t[Symbol.iterator]=function(){return t}),t}function l(e){this.map={},e instanceof l?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function u(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function c(e){return new Promise((function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}}))}function d(e){var t=new FileReader,r=c(t);return t.readAsArrayBuffer(e),r}function p(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function h(){return this.bodyUsed=!1,this._initBody=function(e){var t;this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:r.blob&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:r.formData&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:r.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():r.arrayBuffer&&r.blob&&(t=e)&&DataView.prototype.isPrototypeOf(t)?(this._bodyArrayBuffer=p(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):r.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(e)||a(e))?this._bodyArrayBuffer=p(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},r.blob&&(this.blob=function(){var e=u(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?u(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(d)}),this.text=function(){var e,t,r,i=u(this);if(i)return i;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,r=c(t),t.readAsText(e),r;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),r=new Array(t.length),i=0;i<t.length;i++)r[i]=String.fromCharCode(t[i]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},r.formData&&(this.formData=function(){return this.text().then(A)}),this.json=function(){return this.text().then(JSON.parse)},this}l.prototype.append=function(e,t){e=s(e),t=n(t);var r=this.map[e];this.map[e]=r?r+", "+t:t},l.prototype.delete=function(e){delete this.map[s(e)]},l.prototype.get=function(e){return e=s(e),this.has(e)?this.map[e]:null},l.prototype.has=function(e){return this.map.hasOwnProperty(s(e))},l.prototype.set=function(e,t){this.map[s(e)]=n(t)},l.prototype.forEach=function(e,t){for(var r in this.map)this.map.hasOwnProperty(r)&&e.call(t,this.map[r],r,this)},l.prototype.keys=function(){var e=[];return this.forEach((function(t,r){e.push(r)})),o(e)},l.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),o(e)},l.prototype.entries=function(){var e=[];return this.forEach((function(t,r){e.push([r,t])})),o(e)},r.iterable&&(l.prototype[Symbol.iterator]=l.prototype.entries);var y=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function f(e,t){var r,i,a=(t=t||{}).body;if(e instanceof f){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new l(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,a||null==e._bodyInit||(a=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new l(t.headers)),this.method=(r=t.method||this.method||"GET",i=r.toUpperCase(),y.indexOf(i)>-1?i:r),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&a)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(a)}function A(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var r=e.split("="),i=r.shift().replace(/\+/g," "),a=r.join("=").replace(/\+/g," ");t.append(decodeURIComponent(i),decodeURIComponent(a))}})),t}function m(e,t){t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new l(t.headers),this.url=t.url||"",this._initBody(e)}f.prototype.clone=function(){return new f(this,{body:this._bodyInit})},h.call(f.prototype),h.call(m.prototype),m.prototype.clone=function(){return new m(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new l(this.headers),url:this.url})},m.error=function(){var e=new m(null,{status:0,statusText:""});return e.type="error",e};var E=[301,302,303,307,308];m.redirect=function(e,t){if(-1===E.indexOf(t))throw new RangeError("Invalid status code");return new m(null,{status:t,headers:{location:e}})},t.DOMException=e.DOMException;try{new t.DOMException}catch(e){t.DOMException=function(e,t){this.message=e,this.name=t;var r=Error(e);this.stack=r.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function g(e,i){return new Promise((function(a,s){var n=new f(e,i);if(n.signal&&n.signal.aborted)return s(new t.DOMException("Aborted","AbortError"));var o=new XMLHttpRequest;function u(){o.abort()}o.onload=function(){var e,t,r={status:o.status,statusText:o.statusText,headers:(e=o.getAllResponseHeaders()||"",t=new l,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(e){var r=e.split(":"),i=r.shift().trim();if(i){var a=r.join(":").trim();t.append(i,a)}})),t)};r.url="responseURL"in o?o.responseURL:r.headers.get("X-Request-URL");var i="response"in o?o.response:o.responseText;a(new m(i,r))},o.onerror=function(){s(new TypeError("Network request failed"))},o.ontimeout=function(){s(new TypeError("Network request failed"))},o.onabort=function(){s(new t.DOMException("Aborted","AbortError"))},o.open(n.method,n.url,!0),"include"===n.credentials?o.withCredentials=!0:"omit"===n.credentials&&(o.withCredentials=!1),"responseType"in o&&r.blob&&(o.responseType="blob"),n.headers.forEach((function(e,t){o.setRequestHeader(t,e)})),n.signal&&(n.signal.addEventListener("abort",u),o.onreadystatechange=function(){4===o.readyState&&n.signal.removeEventListener("abort",u)}),o.send(void 0===n._bodyInit?null:n._bodyInit)}))}g.polyfill=!0,e.fetch||(e.fetch=g,e.Headers=l,e.Request=f,e.Response=m),t.Headers=l,t.Request=f,t.Response=m,t.fetch=g,Object.defineProperty(t,"__esModule",{value:!0})}({})}("undefined"!=typeof self?self:t);class r{reader;decoder=new TextDecoder;partialChunk="";constructor(e){this.reader=e}async*read(){for(;;){const{done:e,value:t}=await this.reader.read();if(e)return void(yield*this.readRemainingChunks());yield*this.readChunksFromValue(t)}}*readRemainingChunks(){yield*this.parseLine(this.partialChunk)}*readChunksFromValue(e){const t=(this.partialChunk+this.decoder.decode(e)).split("\n");this.partialChunk=t.pop();for(let e of t)yield*this.parseLine(e)}*parseLine(e){const[t,r]=e.split(/:(.*)/);"data"==t&&r.length>0&&(yield JSON.parse(r))}}const i=e=>"object"==typeof e&&null!=e,a=e=>"boolean"==typeof e,s=e=>"number"==typeof e,n=e=>"string"==typeof e;var o;e.FtMyLibraryColors=void 0,(o=e.FtMyLibraryColors||(e.FtMyLibraryColors={})).black="black",o.green="green",o.blue="blue",o.purple="purple",o.red="red",o.orange="orange",o.yellow="yellow";const l=e=>["black","green","blue","purple","red","orange","yellow"].includes(e);var u;e.FtTopicOriginType=void 0,(u=e.FtTopicOriginType||(e.FtTopicOriginType={})).OFFICIAL="OFFICIAL",u.PERSONAL="PERSONAL",u.SHARED="SHARED";const c=e=>["OFFICIAL","PERSONAL","SHARED"].includes(e),d=e=>i(e)&&Array.isArray(e.values)&&e.values.every((e=>Array.isArray(e)&&e.every((e=>n(e)))))&&n(e.key),p=e=>i(e)&&n(e.notes)&&Array.isArray(e.children)&&e.children.every((e=>p(e)))&&(null==e.topicLink||h(e.topicLink))&&n(e.title)&&(null==e.htmlContent||n(e.htmlContent)),h=e=>i(e)&&n(e.tocId)&&n(e.contentId)&&n(e.mapId),y=e=>i(e)&&n(e.topicStylesheetUrl)&&n(e.titleStylesheetUrl)&&Array.isArray(e.customCssClasses)&&e.customCssClasses.every((e=>n(e))),f=e=>i(e)&&(null==e.prettyUrl||n(e.prettyUrl))&&(null==e.hasRating||a(e.hasRating))&&n(e.tocId)&&Array.isArray(e.children)&&e.children.every((e=>f(e)))&&(null==e.origin||A(e.origin))&&n(e.contentId)&&n(e.title),A=e=>i(e)&&n(e.mapTitle)&&Array.isArray(e.breadcrumb)&&e.breadcrumb.every((e=>n(e)))&&n(e.tocId)&&n(e.contentId)&&n(e.mapId)&&c(e.type);var m;e.FtTopicContentTarget=void 0,(m=e.FtTopicContentTarget||(e.FtTopicContentTarget={})).THIRD_PARTY="THIRD_PARTY",m.OFF_THE_GRID="OFF_THE_GRID",m.CONTENT_PACKAGER="CONTENT_PACKAGER",m.PAGES="PAGES",m.DESIGNED_READER="DESIGNED_READER";var E;e.FtMetadataHomeLayout=void 0,(E=e.FtMetadataHomeLayout||(e.FtMetadataHomeLayout={})).CLASSIC="CLASSIC",E.CUSTOM="CUSTOM",E.DESIGNER="DESIGNER";const g=e=>i(e)&&s(e.count)&&n(e.label)&&(null==e.lang||n(e.lang));var T;e.FtFacetType=void 0,(T=e.FtFacetType||(e.FtFacetType={})).AND="AND",T.OR="OR",T.MONOVALUED="MONOVALUED";const S=e=>i(e)&&Array.isArray(e.values)&&e.values.every((e=>n(e)))&&(null==e.hierarchicalValues||Array.isArray(e.hierarchicalValues)&&e.hierarchicalValues.every((e=>Array.isArray(e)&&e.every((e=>n(e))))))&&n(e.label)&&n(e.key);var b;e.FtMetadataSortRule=void 0,(b=e.FtMetadataSortRule||(e.FtMetadataSortRule={})).NONE="NONE",b.ALPHABET="ALPHABET",b.VERSION="VERSION";const R=e=>["NONE","ALPHABET","VERSION"].includes(e),F=e=>i(e)&&R(e.sortRule)&&n(e.label)&&a(e.reverseSort)&&n(e.key),O=e=>i(e)&&(null==e.periodFilter||N(e.periodFilter))&&n(e.query)&&(null==e.scope||le(e.scope))&&Array.isArray(e.filters)&&e.filters.every((e=>Q(e)))&&Array.isArray(e.sort)&&e.sort.every((e=>pe(e)))&&(null==e.virtualField||K(e.virtualField))&&(null==e.contentLocale||n(e.contentLocale));var U;e.FtRatingType=void 0,(U=e.FtRatingType||(e.FtRatingType={})).STARS="STARS",U.LIKE="LIKE",U.DICHOTOMOUS="DICHOTOMOUS",U.NO_RATING="NO_RATING";const I=e=>["STARS","LIKE","DICHOTOMOUS","NO_RATING"].includes(e),v=e=>i(e)&&n(e.date)&&I(e.type)&&s(e.value),_=e=>i(e)&&(null==e.rating||v(e.rating))&&I(e.type),C=e=>i(e)&&n(e.date)&&n(e.tocId)&&I(e.type)&&s(e.value),L=e=>i(e)&&Array.isArray(e.ratings)&&e.ratings.every((e=>C(e)))&&I(e.type),D=e=>i(e)&&Array.isArray(e.filter)&&e.filter.every((e=>n(e)))&&Array.isArray(e.prior)&&e.prior.every((e=>n(e))),P=e=>i(e)&&n(e.from)&&n(e.to),N=e=>i(e)&&(null==e.period||P(e.period))&&M(e.periodType);var k;e.FtPeriodFilterType=void 0,(k=e.FtPeriodFilterType||(e.FtPeriodFilterType={})).LAST_WEEK="LAST_WEEK",k.LAST_MONTH="LAST_MONTH",k.LAST_YEAR="LAST_YEAR",k.CUSTOM="CUSTOM";const M=e=>["LAST_WEEK","LAST_MONTH","LAST_YEAR","CUSTOM"].includes(e),w=e=>i(e)&&a(e.negative)&&Array.isArray(e.values)&&e.values.every((e=>n(e)))&&n(e.key);var B;e.FtSearchSortCriterionOrder=void 0,(B=e.FtSearchSortCriterionOrder||(e.FtSearchSortCriterionOrder={})).ASC="ASC",B.DESC="DESC";const H=e=>["ASC","DESC"].includes(e);var x;e.FtSearchSortCriterionType=void 0,(x=e.FtSearchSortCriterionType||(e.FtSearchSortCriterionType={})).ALPHA="ALPHA",x.NATURAL="NATURAL";const V=e=>["ALPHA","NATURAL"].includes(e);var $;e.FtVirtualField=void 0,($=e.FtVirtualField||(e.FtVirtualField={})).EVERYWHERE="EVERYWHERE",$.TITLE_ONLY="TITLE_ONLY",$.NONE="NONE";const K=e=>["EVERYWHERE","TITLE_ONLY","NONE"].includes(e),G=e=>i(e)&&s(e.totalResultsCount)&&a(e.isLastPage)&&s(e.currentPage)&&s(e.totalClustersCount);var j;e.FtEditorialType=void 0,(j=e.FtEditorialType||(e.FtEditorialType={})).ARTICLE="ARTICLE",j.BOOK="BOOK",j.SHARED_BOOK="SHARED_BOOK";const q=e=>["ARTICLE","BOOK","SHARED_BOOK"].includes(e);var X;e.FtOpenMode=void 0,(X=e.FtOpenMode||(e.FtOpenMode={})).FLUIDTOPICS="FLUIDTOPICS",X.EXTERNAL="EXTERNAL";const Y=e=>["FLUIDTOPICS","EXTERNAL"].includes(e),z=e=>i(e)&&(null==e.perPage||s(e.perPage))&&s(e.page);var W;e.FtCollectionDocumentType=void 0,(W=e.FtCollectionDocumentType||(e.FtCollectionDocumentType={})).MAP="MAP",W.DOCUMENT="DOCUMENT",W.TOPIC="TOPIC",W.PERSONAL_BOOK="PERSONAL_BOOK",W.SHARED_BOOK="SHARED_BOOK";const J=e=>["MAP","DOCUMENT","TOPIC","PERSONAL_BOOK","SHARED_BOOK"].includes(e),Q=e=>i(e)&&a(e.negative)&&Array.isArray(e.values)&&e.values.every((e=>n(e)))&&n(e.label)&&n(e.key),Z=e=>i(e)&&s(e.weight)&&n(e.value)&&n(e.key),ee=e=>i(e)&&Array.isArray(e.entries)&&e.entries.every((e=>te(e)))&&(null==e.metadataVariableAxis||n(e.metadataVariableAxis)),te=e=>i(e)&&(null==e.document||re(e.document))&&(null==e.topic||ae(e.topic))&&ne(e.type)&&(null==e.map||ie(e.map)),re=e=>i(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>S(e)))&&Y(e.openMode)&&n(e.documentUrl)&&n(e.mimeType)&&n(e.title)&&(null==e.lastPublicationDate||n(e.lastPublicationDate))&&n(e.viewerUrl)&&n(e.contentUrl)&&n(e.filename)&&n(e.htmlTitle)&&(null==e.originUrl||n(e.originUrl))&&n(e.documentId)&&n(e.lastEditionDate)&&n(e.htmlExcerpt),ie=e=>i(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>S(e)))&&(null==e.openMode||Y(e.openMode))&&q(e.editorialType)&&n(e.title)&&(null==e.lastPublicationDate||n(e.lastPublicationDate))&&n(e.htmlTitle)&&(null==e.originUrl||n(e.originUrl))&&n(e.mapUrl)&&n(e.readerUrl)&&n(e.mapId)&&(null==e.lastEditionDate||n(e.lastEditionDate))&&n(e.htmlExcerpt),ae=e=>i(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>S(e)))&&Y(e.openMode)&&n(e.contentId)&&Array.isArray(e.resources)&&e.resources.every((e=>ye(e)))&&n(e.title)&&n(e.mapTitle)&&n(e.topicUrl)&&n(e.contentUrl)&&n(e.htmlTitle)&&Array.isArray(e.breadcrumb)&&e.breadcrumb.every((e=>n(e)))&&n(e.tocId)&&(null==e.originUrl||n(e.originUrl))&&n(e.readerUrl)&&n(e.mapId)&&(null==e.lastEditionDate||n(e.lastEditionDate))&&n(e.htmlExcerpt);var se;e.FtSearchResultType=void 0,(se=e.FtSearchResultType||(e.FtSearchResultType={})).MAP="MAP",se.DOCUMENT="DOCUMENT",se.TOPIC="TOPIC";const ne=e=>["MAP","DOCUMENT","TOPIC"].includes(e);var oe;e.FtSearchScope=void 0,(oe=e.FtSearchScope||(e.FtSearchScope={})).DEFAULT="DEFAULT",oe.DOCUMENTS="DOCUMENTS",oe.ALL_TOPICS="ALL_TOPICS";const le=e=>["DEFAULT","DOCUMENTS","ALL_TOPICS"].includes(e),ue=e=>i(e)&&a(e.hierarchical)&&n(e.label)&&a(e.multiSelectionable)&&n(e.key)&&Array.isArray(e.rootNodes)&&e.rootNodes.every((e=>de(e))),ce=e=>i(e)&&(null==e.maxDepth||s(e.maxDepth))&&n(e.id),de=e=>i(e)&&s(e.totalResultsCount)&&a(e.descendantSelected)&&Array.isArray(e.childNodes)&&e.childNodes.every((e=>de(e)))&&n(e.label)&&n(e.value)&&a(e.selected),pe=e=>i(e)&&V(e.type)&&n(e.key)&&H(e.order),he=e=>i(e)&&n(e.suggestedQuery)&&n(e.htmlSuggestedQuery),ye=e=>i(e)&&n(e.filename)&&n(e.resourceUrl)&&n(e.id)&&n(e.mimeType)&&n(e.resourceContentUrl)&&n(e.viewerUrl),fe=e=>i(e)&&(null==e.filenameExtension||n(e.filenameExtension))&&(null==e.editorialType||q(e.editorialType))&&(null==e.mimeType||n(e.mimeType))&&ne(e.type)&&n(e.value);var Ae;e.FtUserRole=void 0,(Ae=e.FtUserRole||(e.FtUserRole={})).PERSONAL_BOOK_USER="PERSONAL_BOOK_USER",Ae.PERSONAL_BOOK_SHARE_USER="PERSONAL_BOOK_SHARE_USER",Ae.HTML_EXPORT_USER="HTML_EXPORT_USER",Ae.PDF_EXPORT_USER="PDF_EXPORT_USER",Ae.SAVED_SEARCH_USER="SAVED_SEARCH_USER",Ae.COLLECTION_USER="COLLECTION_USER",Ae.OFFLINE_USER="OFFLINE_USER",Ae.ANALYTICS_USER="ANALYTICS_USER",Ae.BETA_USER="BETA_USER",Ae.DEBUG_USER="DEBUG_USER",Ae.PRINT_USER="PRINT_USER",Ae.RATING_USER="RATING_USER",Ae.FEEDBACK_USER="FEEDBACK_USER",Ae.GENERATIVE_AI_USER="GENERATIVE_AI_USER",Ae.CONTENT_PUBLISHER="CONTENT_PUBLISHER",Ae.KHUB_ADMIN="KHUB_ADMIN",Ae.USERS_ADMIN="USERS_ADMIN",Ae.PORTAL_ADMIN="PORTAL_ADMIN",Ae.ADMIN="ADMIN",Ae.DEVELOPER="DEVELOPER";const me=e=>["PERSONAL_BOOK_USER","PERSONAL_BOOK_SHARE_USER","HTML_EXPORT_USER","PDF_EXPORT_USER","SAVED_SEARCH_USER","COLLECTION_USER","OFFLINE_USER","ANALYTICS_USER","BETA_USER","DEBUG_USER","PRINT_USER","RATING_USER","FEEDBACK_USER","GENERATIVE_AI_USER","CONTENT_PUBLISHER","KHUB_ADMIN","USERS_ADMIN","PORTAL_ADMIN","ADMIN","DEVELOPER"].includes(e),Ee=e=>i(e)&&n(e.identifier)&&n(e.realm),ge=e=>i(e)&&Array.isArray(e.defaultFilters)&&e.defaultFilters.every((e=>w(e))),Te=e=>i(e)&&(null==e.emailAddress||n(e.emailAddress))&&(null==e.displayName||n(e.displayName))&&Array.isArray(e.roles)&&e.roles.every((e=>me(e)))&&(null==e.userId||n(e.userId)),Se=e=>"object"==typeof e&&null!=e,be=e=>"boolean"==typeof e,Re=e=>"number"==typeof e,Fe=e=>"string"==typeof e;var Oe;e.FtConfigurationHistoryEntryStatus=void 0,(Oe=e.FtConfigurationHistoryEntryStatus||(e.FtConfigurationHistoryEntryStatus={})).VALID="VALID",Oe.INVALID="INVALID";const Ue=e=>Se(e)&&be(e.mailsSentByFluidTopics)&&be(e.mailsSentByFluidTopicsForUnauthenticatedUsers)&&Array.isArray(e.recipients)&&e.recipients.every((e=>Fe(e)))&&Array.isArray(e.bodyMetadataIds)&&e.bodyMetadataIds.every((e=>Fe(e)))&&Array.isArray(e.subjectMetadataIds)&&e.subjectMetadataIds.every((e=>Fe(e))),Ie=e=>Se(e)&&(null==e.parentsVisibility||Array.isArray(e.parentsVisibility)&&e.parentsVisibility.every((e=>be(e))))&&be(e.isVisible),ve=e=>Se(e)&&(null==e.prettyUrl||Fe(e.prettyUrl))&&(null==e.hasRating||be(e.hasRating))&&(null==e.pageToc||Array.isArray(e.pageToc))&&(null==e.tocId||Fe(e.tocId))&&Array.isArray(e.children)&&e.children.every((e=>ve(e)))&&(null==e.pageConfiguration||Ie(e.pageConfiguration))&&(null==e.contentId||Fe(e.contentId))&&(null==e.title||Fe(e.title)),_e=e=>Se(e)&&be(e.splitCurrentPageToc),Ce={[e.FtUserRole.PERSONAL_BOOK_SHARE_USER]:[e.FtUserRole.PERSONAL_BOOK_USER],[e.FtUserRole.HTML_EXPORT_USER]:[e.FtUserRole.PERSONAL_BOOK_USER],[e.FtUserRole.PDF_EXPORT_USER]:[e.FtUserRole.PERSONAL_BOOK_USER],[e.FtUserRole.KHUB_ADMIN]:[e.FtUserRole.CONTENT_PUBLISHER],[e.FtUserRole.ADMIN]:[e.FtUserRole.KHUB_ADMIN,e.FtUserRole.USERS_ADMIN,e.FtUserRole.PORTAL_ADMIN],[e.FtUserRole.DEVELOPER]:[e.FtUserRole.BETA_USER,e.FtUserRole.DEBUG_USER]};function Le(e,t){return e===t||(Ce[e]??[]).some((e=>Le(e,t)))}const De="undefined"==typeof window?globalThis:window;function Pe(e){let t={};for(let r in e){let i=e[r];("object"!=typeof i||Array.isArray(i))&&(i={prior:i});for(let e of["prior","filter"])i[e]=Array.isArray(i[e])?i[e]:[i[e]],i[e]=i[e].map((e=>null!=e?""+e:"")).filter((e=>""!==e));t[r]=i}return t}function Ne(e){return`${e}-FluidTopicsUnauthenticatedUserSearchPreferences`}const ke="undefined"==typeof window?globalThis:window;class Me extends Error{method;endpoint;status;statusText;body;constructor(e,t,r,i,a){super(`${e} ${t} -> ${r} - ${i}: ${a}`),this.method=e,this.endpoint=t,this.status=r,this.statusText=i,this.body=a}}class we extends CustomEvent{constructor(e){super("ft-api-http-error",{detail:e})}}async function Be(e,t,r){if(!r.ok){let i={method:e,endpoint:t,status:r.status,statusText:r.statusText,body:await r.text()};throw"function"==typeof ke.dispatchEvent&&ke.dispatchEvent(new we(i)),new Me(i.method,i.endpoint,i.status,i.statusText,i.body)}return r}function He(e){return"application/json"===e.headers.get("Content-Type")?e.json():e.text()}class xe{tenantBaseUrl;ftCallingApp;authorization;searchLabel;endpoints={authentication:{login:"api/authentication/login",logout:"api/authentication/logout",currentSession:"api/authentication/current-session"},khub:{maps:{mapId:e=>({info:`api/khub/maps/${e}`,toc:`api/khub/maps/${e}/toc`,pages:`api/khub/maps/${e}/pages`,feedback:`api/khub/maps/${e}/feedback`,rating:`api/khub/maps/${e}/rating`,attachments:{list:`api/khub/maps/${e}/attachments`,attachmentId:t=>({content:`api/khub/maps/${e}/attachments/${t}/content`})},resources:{list:`api/khub/maps/${e}/resources`,resourceId:t=>({content:`api/khub/maps/${e}/resources/${t}/content`})},topics:{contentId:t=>({info:`api/khub/maps/${e}/topics/${t}`,content:`api/khub/maps/${e}/topics/${t}/content`}),tocId:t=>({feedback:`api/khub/maps/${e}/topics/${t}/feedback`,rating:`api/khub/maps/${e}/topics/${t}/rating`})}})},documents:{documentId:e=>({info:`api/khub/documents/${e}`,content:`api/khub/documents/${e}/content`,text:`api/khub/documents/${e}/content/text`,feedback:`api/khub/documents/${e}/feedback`,rating:`api/khub/documents/${e}/rating`})},suggest:"api/khub/suggest",clusteredSearch:"api/khub/clustered-search",locales:"api/khub/locales"},users:{userId:e=>({collections:{collectionId:t=>({documents:`api/users/${e}/collections/${t}/documents`})},searches:{list:`api/users/${e}/searches`},bookmarks:{list:`api/users/${e}/bookmarks`}})},stylesheets:{fonts:"api/stylesheets/fonts.css",theme:"api/stylesheets/theme.css",content:{title:"api/stylesheets/content/title.css",topic:"api/stylesheets/content/topic.css"}},configuration:{reader:"api/configuration/reader",metadata:"api/configuration/metadata"},locales:{ui:"api/locales/ui"},messages:{locale:e=>({fluidTopics:{contextName:t=>({endpoint:`api/messages/${e}/fluid-topics/${t}`})},custom:{contextName:t=>({endpoint:`api/messages/${e}/custom/${t}`})}})},ai:{generate:"api/ai/generate"}};get defaultHeaders(){return{...this.authorization,...this.searchLabel,"Ft-Calling-App":this.ftCallingApp}}constructor(e,t,r){e=(e??ke.fluidTopicsBaseUrl??ke.__gwt_ft_moduleBase??"").trim(),this.tenantBaseUrl=e.endsWith("/")?e:e+"/",r&&void 0!==ke.location&&ke.location.href.startsWith(this.tenantBaseUrl)?this.ftCallingApp=t:this.ftCallingApp=`ft-public-api/${t}`}setApiKey(e){this.authorization={Authorization:"Bearer "+e}}setCredentials(e,t){var r;this.authorization={Authorization:"Basic "+(r=`${e}:${t}`,"undefined"!=typeof Buffer?Buffer.from(r).toString("base64"):btoa(r))}}clearAuthentication(){this.authorization=void 0}setSearchLabel(e){this.searchLabel={"FT-search-label":e}}clearSearchLabel(){this.searchLabel=void 0}login(e,t){let r={login:e,password:t,rememberMe:!0};return this.post(this.endpoints.authentication.login,r).then((r=>(this.setCredentials(e,t),r)))}logout(){return this.post(this.endpoints.authentication.logout).then((()=>this.clearAuthentication()))}getCurrentSession(){return this.get(this.endpoints.authentication.currentSession)}getReaderConfiguration(){return this.get(this.endpoints.configuration.reader)}getMap(e,t){return this.get(this.endpoints.khub.maps.mapId(e).info,t)}getTableOfContent(e,t){return this.get(this.endpoints.khub.maps.mapId(e).toc,t)}getPages(e,t){return this.get(this.endpoints.khub.maps.mapId(e).pages,t)}getTopic(e,t,r){return this.get(this.endpoints.khub.maps.mapId(e).topics.contentId(t).info,r)}getTopicHTMLContent(e,t,r,i){return this.get(this.endpoints.khub.maps.mapId(e).topics.contentId(t).content+(r?"?target="+r:""),i)}getMapAttachments(e,t){return this.get(this.endpoints.khub.maps.mapId(e).attachments.list,t)}getMapAttachmentContent(e,t,r){return this.fetchRawData(this.endpoints.khub.maps.mapId(e).attachments.attachmentId(t).content,r)}getMapResources(e,t){return this.get(this.endpoints.khub.maps.mapId(e).resources.list,t)}getMapResourceContent(e,t,r){return this.fetchRawData(this.endpoints.khub.maps.mapId(e).resources.resourceId(t).content,r)}getUnstructuredDocument(e,t){return this.get(this.endpoints.khub.documents.documentId(e).info,t)}getUnstructuredDocumentContent(e,t){return this.fetchRawData(this.endpoints.khub.documents.documentId(e).content,t)}getUnstructuredDocumentTextContent(e,t){return this.get(this.endpoints.khub.documents.documentId(e).text,t)}getCollectionDocuments(e,t){return this.get(this.endpoints.users.userId(e).collections.collectionId(t).documents)}getSuggestions(e){return this.post(this.endpoints.khub.suggest,e)}search(e){return this.post(this.endpoints.khub.clusteredSearch,e)}getAvailableSearchLocales(){return this.get(this.endpoints.khub.locales)}getAvailableUiLocales(){return this.get(this.endpoints.khub.locales)}getMetadataConfiguration(){return this.get(this.endpoints.configuration.metadata)}getMapRating(e){return this.get(this.endpoints.khub.maps.mapId(e).rating)}rateMap(e,t,r){return this.post(this.endpoints.khub.maps.mapId(e).rating,{type:t,value:r})}unrateMap(e){return this.delete(this.endpoints.khub.maps.mapId(e).rating)}sendMapFeedback(e,t,r){return this.post(this.endpoints.khub.maps.mapId(e).feedback,{message:t,from:r})}rateTopic(e,t,r,i){return this.post(this.endpoints.khub.maps.mapId(e).topics.tocId(t).rating,{type:r,value:i})}unrateTopic(e,t){return this.delete(this.endpoints.khub.maps.mapId(e).topics.tocId(t).rating)}sendTopicFeedback(e,t,r,i){return this.post(this.endpoints.khub.maps.mapId(e).topics.tocId(t).feedback,{message:r,from:i})}getDocumentRating(e){return this.get(this.endpoints.khub.documents.documentId(e).rating)}rateDocument(e,t,r){return this.post(this.endpoints.khub.documents.documentId(e).rating,{type:t,value:r})}unrateDocument(e){return this.delete(this.endpoints.khub.documents.documentId(e).rating)}sendDocumentFeedback(e,t,r){return this.post(this.endpoints.khub.documents.documentId(e).feedback,{message:t,from:r})}getFluidTopicsMessageContext(e,t){return this.get(this.endpoints.messages.locale(e).fluidTopics.contextName(t).endpoint)}getCustomMessageContext(e,t){return this.get(this.endpoints.messages.locale(e).custom.contextName(t).endpoint)}listMySearches(e){return this.get(this.endpoints.users.userId(e).searches.list)}listMyBookmarks(e){return this.get(this.endpoints.users.userId(e).bookmarks.list)}async*generate(e,t){const i=await this.fetch(this.endpoints.ai.generate,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({profileId:e,parameters:t}),credentials:null==this.authorization?"include":void 0});await Be("POST",this.endpoints.ai.generate,i);const a=new r(i.body.getReader());yield*a.read()}get(e,t){return this.makeRequest("GET",this.withVersion(e,t))}post(e,t){return this.makeRequest("POST",e,t)}put(e,t){return this.makeRequest("PUT",e,t)}delete(e){return this.makeRequest("DELETE",e)}makeAbsolute(e){return e.startsWith(this.tenantBaseUrl)?e:this.tenantBaseUrl+e.replace(/^\//,"")}async fetch(e,t){const r=t;return await fetch(this.makeAbsolute(e),{...r??{},headers:{...this.defaultHeaders,...r?.headers??{}}})}upload(e,t,r,i=(()=>{})){return"undefined"!=typeof XMLHttpRequest?new Promise(((a,s)=>{let n=new XMLHttpRequest;n.onload=()=>{if(n.status>=200&&n.status<300){let e="application/json"===n.getResponseHeader("Content-Type")?JSON.parse(n.responseText):n.responseText;a(e)}else s(new Me("GET",t,n.status,n.statusText,n.responseText))},n.upload.onprogress=e=>i(e),n.open(e,this.makeAbsolute(t),!0),n.send(r)})):this.fetch(t,{method:e,body:r}).then((r=>Be(e,t,r))).then(He)}makeRequest(e,t,r){return this.fetch(t,{method:e,headers:{...null!=r?{"Content-Type":"application/json"}:{}},body:null!=r?JSON.stringify(r):void 0,credentials:null==this.authorization?"include":void 0}).then((r=>Be(e,t,r))).then(He)}fetchRawData(e,t){return fetch(this.withVersion(e,t),{headers:this.defaultHeaders,credentials:null==this.authorization?"include":void 0}).then((t=>Be("GET",e,t))).then((e=>e.arrayBuffer()))}withVersion(e,t){let r=new URL(this.makeAbsolute(e));return t&&r.searchParams.append("v",t),r.toString()}}e.FluidTopicsApi=xe,e.HttpError=Me,e.HttpErrorEvent=we,e.addUnauthenticatedUserSearchPreferencesChangeHandler=function(e,t){if(De.localStorage){const r=Ne(e),i=e=>{e.storageArea===De.localStorage&&e.key===r&&t(JSON.parse(e.newValue??"{}"))};return De.addEventListener("storage",i),{removeHandler:()=>De.removeEventListener("storage",i)}}console.error("Cannot handle unauthenticated preferences: local storage is unavailable.")},e.default=xe,e.getUnauthenticatedUserSearchPreferences=function(e){if(De.localStorage)return JSON.parse(De.localStorage.getItem(Ne(e))??"{}");console.error("Cannot get unauthenticated preferences: local storage is unavailable.")},e.isFtAuthenticatedSession=e=>i(e)&&Ee(e.authenticationIdentifier)&&Te(e.profile),e.isFtAuthenticationIdentifier=Ee,e.isFtBookmark=e=>i(e)&&n(e.mapTitle)&&l(e.color)&&Array.isArray(e.breadcrumb)&&e.breadcrumb.every((e=>n(e)))&&n(e.tocId)&&n(e.lastUpdate)&&n(e.readerUrl)&&n(e.mapId)&&n(e.id)&&n(e.title)&&n(e.creationDate),e.isFtCollectionDocument=e=>i(e)&&a(e.deleted)&&(null==e.apiUrl||n(e.apiUrl))&&(null==e.portalUrl||n(e.portalUrl))&&n(e.id)&&n(e.title)&&J(e.type),e.isFtCollectionDocumentType=J,e.isFtConfigurationHistoryEntryStatus=e=>["VALID","INVALID"].includes(e),e.isFtCredentials=e=>i(e)&&n(e.password)&&(null==e.newPassword||n(e.newPassword))&&a(e.rememberMe)&&n(e.login),e.isFtEditorialType=q,e.isFtFacetType=e=>["AND","OR","MONOVALUED"].includes(e),e.isFtFeedbackCreation=e=>i(e)&&(null==e.from||n(e.from))&&n(e.message),e.isFtHttpErrorDetails=e=>i(e)&&n(e.endpoint)&&n(e.method)&&n(e.statusText)&&n(e.body)&&s(e.status),e.isFtLabeledSearchFilter=Q,e.isFtMap=e=>i(e)&&(null==e.prettyUrl||n(e.prettyUrl))&&Array.isArray(e.metadata)&&e.metadata.every((e=>S(e)))&&Y(e.openMode)&&(null==e.topicsApiEndpoint||n(e.topicsApiEndpoint))&&(null==e.description||n(e.description))&&(null==e.attachmentsApiEndpoint||n(e.attachmentsApiEndpoint))&&q(e.editorialType)&&n(e.baseId)&&n(e.clusterId)&&n(e.title)&&n(e.lastPublication)&&n(e.lastEdition)&&n(e.originId)&&(null==e.rightsApiEndpoint||n(e.rightsApiEndpoint))&&y(e.contentStyles)&&(null==e.originUrl||n(e.originUrl))&&n(e.fingerprint)&&n(e.readerUrl)&&(null==e.khubVersion||n(e.khubVersion))&&n(e.id)&&(null==e.lang||n(e.lang)),e.isFtMapAttachment=e=>Se(e)&&Fe(e.file)&&(null==e.size||Re(e.size))&&be(e.externalLink)&&Fe(e.name)&&Fe(e.id)&&(null==e.mimeType||Fe(e.mimeType))&&(null==e.viewerUrl||Fe(e.viewerUrl)),e.isFtMapResource=e=>i(e)&&n(e.contentUrl)&&n(e.filename)&&n(e.id)&&n(e.mimeType),e.isFtMapStyles=y,e.isFtMessageContext=e=>i(e)&&n(e.name)&&i(e.messages)&&Object.keys(e.messages).every((e=>n(e)))&&Object.values(e.messages).every((e=>n(e)))&&n(e.locale),e.isFtMetadata=S,e.isFtMetadataConfiguration=e=>i(e)&&Array.isArray(e.descriptors)&&e.descriptors.every((e=>F(e))),e.isFtMetadataDescriptor=F,e.isFtMetadataHomeLayout=e=>["CLASSIC","CUSTOM","DESIGNER"].includes(e),e.isFtMetadataPreferenceConfiguration=D,e.isFtMetadataSortRule=R,e.isFtMyLibraryColors=l,e.isFtMySearch=e=>i(e)&&O(e.searchRequest)&&l(e.color)&&a(e.alert)&&n(e.description)&&n(e.id)&&n(e.ownerId)&&n(e.title)&&n(e.creationDate),e.isFtMySearchRequest=O,e.isFtOpenMode=Y,e.isFtPageConfiguration=Ie,e.isFtPageRequest=z,e.isFtPaginatedToc=e=>Se(e)&&_e(e.configuration)&&Array.isArray(e.paginatedToc)&&e.paginatedToc.every((e=>ve(e))),e.isFtPaginatedTocNode=ve,e.isFtPaginationConfiguration=_e,e.isFtPeriod=P,e.isFtPeriodFilter=N,e.isFtPeriodFilterType=M,e.isFtPersonalBookCreation=e=>i(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>d(e)))&&Array.isArray(e.nodes)&&e.nodes.every((e=>p(e)))&&n(e.description)&&n(e.title),e.isFtPersonalBookMetadataUpdate=d,e.isFtPersonalBookNodeCreation=p,e.isFtPersonalBookTopicLinkCreation=h,e.isFtPublicationRating=v,e.isFtPublicationRatingSummary=_,e.isFtRatingCreation=e=>i(e)&&I(e.type)&&s(e.value),e.isFtRatingSummary=e=>i(e)&&(null==e.topics||L(e.topics))&&_(e.publication),e.isFtRatingType=I,e.isFtReaderConfiguration=e=>Se(e)&&Ue(e.feedback)&&Re(e.loadAfterLastVisibleTopic)&&Fe(e.relativeTopicPivotMetadata)&&Re(e.loadBeforeFirstVisibleTopic)&&Fe(e.relativePivotMetadata),e.isFtReaderFeedbackConfiguration=Ue,e.isFtSearchFacet=ue,e.isFtSearchFacetConf=ce,e.isFtSearchFacetEntry=de,e.isFtSearchFilter=w,e.isFtSearchLocale=g,e.isFtSearchLocales=e=>i(e)&&Array.isArray(e.contentLocales)&&e.contentLocales.every((e=>g(e))),e.isFtSearchPreferences=ge,e.isFtSearchPreferencesConfiguration=e=>i(e)&&i(e.metadata)&&Object.keys(e.metadata).every((e=>n(e)))&&Object.values(e.metadata).every((e=>D(e))),e.isFtSearchPreset=e=>i(e)&&n(e.name)&&Array.isArray(e.filters)&&e.filters.every((e=>w(e)))&&s(e.priority)&&(null==e.contentLocale||n(e.contentLocale)),e.isFtSearchPrior=Z,e.isFtSearchRequest=e=>i(e)&&(null==e.periodFilter||N(e.periodFilter))&&n(e.query)&&(null==e.scope||le(e.scope))&&z(e.paging)&&Array.isArray(e.filters)&&e.filters.every((e=>w(e)))&&Array.isArray(e.sort)&&e.sort.every((e=>pe(e)))&&(null==e.uiLocale||n(e.uiLocale))&&(null==e.virtualField||K(e.virtualField))&&(null==e.contentLocale||n(e.contentLocale))&&(null==e.priors||Array.isArray(e.priors)&&e.priors.every((e=>Z(e))))&&Array.isArray(e.facets)&&e.facets.every((e=>ce(e))),e.isFtSearchResultCluster=ee,e.isFtSearchResultClusterEntry=te,e.isFtSearchResultMap=ie,e.isFtSearchResultTopic=ae,e.isFtSearchResultType=ne,e.isFtSearchResultUnstructuredDocument=re,e.isFtSearchResults=e=>i(e)&&(null==e.spellcheck||he(e.spellcheck))&&G(e.paging)&&Array.isArray(e.results)&&e.results.every((e=>ee(e)))&&Array.isArray(e.facets)&&e.facets.every((e=>ue(e))),e.isFtSearchResultsPageInfo=G,e.isFtSearchScope=le,e.isFtSearchSortCriterion=pe,e.isFtSearchSortCriterionOrder=H,e.isFtSearchSortCriterionType=V,e.isFtSession=e=>i(e)&&(null==e.authenticationIdentifier||Ee(e.authenticationIdentifier))&&s(e.idleTimeoutInMillis)&&Te(e.profile)&&a(e.sessionAuthenticated)&&ge(e.searchPreferences),e.isFtSpellcheck=he,e.isFtSuggestRequest=e=>i(e)&&n(e.input)&&(null==e.scope||le(e.scope))&&Array.isArray(e.filters)&&e.filters.every((e=>w(e)))&&Array.isArray(e.sort)&&e.sort.every((e=>pe(e)))&&(null==e.maxCount||s(e.maxCount))&&(null==e.contentLocale||n(e.contentLocale)),e.isFtSuggestResult=fe,e.isFtSuggestResults=e=>i(e)&&Array.isArray(e.suggestions)&&e.suggestions.every((e=>fe(e))),e.isFtTocNode=f,e.isFtTopic=e=>i(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>S(e)))&&n(e.id)&&n(e.contentApiEndpoint)&&n(e.title),e.isFtTopicContentTarget=e=>["THIRD_PARTY","OFF_THE_GRID","CONTENT_PACKAGER","PAGES","DESIGNED_READER"].includes(e),e.isFtTopicOrigin=A,e.isFtTopicOriginType=c,e.isFtTopicRating=C,e.isFtTopicResource=ye,e.isFtTopicsRatingSummary=L,e.isFtUiLocale=e=>i(e)&&n(e.displayName)&&n(e.languageTag)&&a(e.translated),e.isFtUnstructuredDocument=e=>i(e)&&(null==e.prettyUrl||n(e.prettyUrl))&&Array.isArray(e.metadata)&&e.metadata.every((e=>S(e)))&&n(e.openMode)&&(null==e.description||n(e.description))&&n(e.mimeType)&&(null==e.baseId||n(e.baseId))&&(null==e.clusterId||n(e.clusterId))&&n(e.contentApiEndpoint)&&n(e.title)&&(null==e.lastPublication||n(e.lastPublication))&&n(e.viewerUrl)&&n(e.lastEdition)&&n(e.filename)&&(null==e.originId||n(e.originId))&&n(e.rightsApiEndpoint)&&(null==e.originUrl||n(e.originUrl))&&(null==e.khubVersion||n(e.khubVersion))&&n(e.id)&&(null==e.lang||n(e.lang)),e.isFtUserProfile=Te,e.isFtUserRole=me,e.isFtVirtualField=K,e.setUnauthenticatedUserSearchPreferences=function(e,t){if(De.localStorage){let r={...t,metadata:Pe(t.metadata??{})};const i=Ne(e),a=JSON.stringify(r);return De.localStorage.setItem(i,a),De.dispatchEvent(new StorageEvent("storage",{key:i,newValue:a,storageArea:De.localStorage,url:De.location.href})),r}console.error("Cannot set unauthenticated preferences: local storage is unavailable.")},e.userHasRole=function(e,t){return null!=e&&(Array.isArray(e)?e:Array.isArray(e.roles)?e.roles:Array.isArray(e.profile?.roles)?e.profile.roles:[]).some((e=>Le(e,t)))}}));
@@ -0,0 +1,15 @@
1
+ export interface GenAIChunk {
2
+ id?: string;
3
+ message?: string;
4
+ error?: string;
5
+ }
6
+ export declare class GenAIChunkReader {
7
+ private readonly reader;
8
+ private decoder;
9
+ private partialChunk;
10
+ constructor(reader: ReadableStreamDefaultReader<Uint8Array>);
11
+ read(): AsyncGenerator<GenAIChunk>;
12
+ private readRemainingChunks;
13
+ private readChunksFromValue;
14
+ private parseLine;
15
+ }
@@ -0,0 +1,37 @@
1
+ export class GenAIChunkReader {
2
+ reader;
3
+ decoder = new TextDecoder();
4
+ partialChunk = "";
5
+ constructor(reader) {
6
+ this.reader = reader;
7
+ }
8
+ async *read() {
9
+ while (true) {
10
+ const { done, value } = await this.reader.read();
11
+ if (done) {
12
+ yield* this.readRemainingChunks();
13
+ return;
14
+ }
15
+ else {
16
+ yield* this.readChunksFromValue(value);
17
+ }
18
+ }
19
+ }
20
+ *readRemainingChunks() {
21
+ yield* this.parseLine(this.partialChunk);
22
+ }
23
+ *readChunksFromValue(value) {
24
+ const text = this.partialChunk + this.decoder.decode(value);
25
+ const lines = text.split("\n");
26
+ this.partialChunk = lines.pop();
27
+ for (let line of lines) {
28
+ yield* this.parseLine(line);
29
+ }
30
+ }
31
+ *parseLine(line) {
32
+ const [type, content] = line.split(/:(.*)/);
33
+ if (type == "data" && content.length > 0) {
34
+ yield JSON.parse(content);
35
+ }
36
+ }
37
+ }
@@ -1,6 +1,7 @@
1
1
  import "cross-fetch/polyfill";
2
2
  import { FtAuthenticatedSession, FtBookmark, FtCollectionDocument, FtHttpErrorDetails, FtMap, FtMapResource, FtMessageContext, FtMetadataConfiguration, FtMySearch, FtRatingSummary, FtRatingType, FtRatingTypeKeys, FtSearchLocales, FtSearchRequest, FtSearchResults, FtSession, FtSuggestRequest, FtSuggestResults, FtTocNode, FtTopic, FtTopicContentTarget, FtTopicContentTargetKeys, FtUiLocale, FtUnstructuredDocument } from "./types/ft-common/public";
3
3
  import { FtMapAttachment, FtPaginatedToc, FtReaderConfiguration } from "./types/ft-server/public";
4
+ import { GenAIChunk } from "./helpers/GenAIChunkReader";
4
5
  export * from "./types/ft-common/public";
5
6
  export * from "./types/ft-server/public";
6
7
  export * from "./roles/roles";
@@ -116,6 +117,9 @@ export declare class FluidTopicsApi {
116
117
  };
117
118
  };
118
119
  };
120
+ ai: {
121
+ generate: string;
122
+ };
119
123
  };
120
124
  private get defaultHeaders();
121
125
  constructor(tenantBaseUrl: string, integrationIdentifier: string, overrideIdentifierIfOnTenant?: boolean);
@@ -161,6 +165,7 @@ export declare class FluidTopicsApi {
161
165
  getCustomMessageContext(locale: string, name: string): Promise<FtMessageContext>;
162
166
  listMySearches(userId: string): Promise<FtMySearch[]>;
163
167
  listMyBookmarks(userId: string): Promise<FtBookmark[]>;
168
+ generate(profileId: string, parameters?: Record<string, string>): AsyncGenerator<GenAIChunk>;
164
169
  get<T>(endpoint: string, v?: string): Promise<T>;
165
170
  post<T>(endpoint: string, data?: any): Promise<T>;
166
171
  put<T>(endpoint: string, data?: any): Promise<T>;
package/dist/mjs/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import "cross-fetch/polyfill";
2
+ import { GenAIChunkReader } from "./helpers/GenAIChunkReader";
2
3
  const wnd = (typeof window === "undefined" ? globalThis : window);
3
4
  export * from "./types/ft-common/public";
4
5
  export * from "./types/ft-server/public";
@@ -146,6 +147,9 @@ export class FluidTopicsApi {
146
147
  }
147
148
  })
148
149
  },
150
+ ai: {
151
+ generate: `api/ai/generate`
152
+ }
149
153
  };
150
154
  get defaultHeaders() {
151
155
  return {
@@ -303,6 +307,19 @@ export class FluidTopicsApi {
303
307
  listMyBookmarks(userId) {
304
308
  return this.get(this.endpoints.users.userId(userId).bookmarks.list);
305
309
  }
310
+ async *generate(profileId, parameters) {
311
+ const response = await this.fetch(this.endpoints.ai.generate, {
312
+ method: "POST",
313
+ headers: {
314
+ "Content-Type": "application/json",
315
+ },
316
+ body: JSON.stringify({ profileId, parameters }),
317
+ credentials: this.authorization == null ? "include" : undefined
318
+ });
319
+ await handleError("POST", this.endpoints.ai.generate, response);
320
+ const reader = new GenAIChunkReader(response.body.getReader());
321
+ yield* reader.read();
322
+ }
306
323
  get(endpoint, v) {
307
324
  return this.makeRequest("GET", this.withVersion(endpoint, v));
308
325
  }
@@ -587,6 +587,7 @@ export declare enum FtUserRole {
587
587
  PRINT_USER = "PRINT_USER",
588
588
  RATING_USER = "RATING_USER",
589
589
  FEEDBACK_USER = "FEEDBACK_USER",
590
+ GENERATIVE_AI_USER = "GENERATIVE_AI_USER",
590
591
  CONTENT_PUBLISHER = "CONTENT_PUBLISHER",
591
592
  KHUB_ADMIN = "KHUB_ADMIN",
592
593
  USERS_ADMIN = "USERS_ADMIN",
@@ -682,6 +682,7 @@ export var FtUserRole;
682
682
  FtUserRole["PRINT_USER"] = "PRINT_USER";
683
683
  FtUserRole["RATING_USER"] = "RATING_USER";
684
684
  FtUserRole["FEEDBACK_USER"] = "FEEDBACK_USER";
685
+ FtUserRole["GENERATIVE_AI_USER"] = "GENERATIVE_AI_USER";
685
686
  FtUserRole["CONTENT_PUBLISHER"] = "CONTENT_PUBLISHER";
686
687
  FtUserRole["KHUB_ADMIN"] = "KHUB_ADMIN";
687
688
  FtUserRole["USERS_ADMIN"] = "USERS_ADMIN";
@@ -690,7 +691,7 @@ export var FtUserRole;
690
691
  FtUserRole["DEVELOPER"] = "DEVELOPER";
691
692
  })(FtUserRole || (FtUserRole = {}));
692
693
  export const isFtUserRole = (o) => {
693
- return ["PERSONAL_BOOK_USER", "PERSONAL_BOOK_SHARE_USER", "HTML_EXPORT_USER", "PDF_EXPORT_USER", "SAVED_SEARCH_USER", "COLLECTION_USER", "OFFLINE_USER", "ANALYTICS_USER", "BETA_USER", "DEBUG_USER", "PRINT_USER", "RATING_USER", "FEEDBACK_USER", "CONTENT_PUBLISHER", "KHUB_ADMIN", "USERS_ADMIN", "PORTAL_ADMIN", "ADMIN", "DEVELOPER"].includes(o);
694
+ return ["PERSONAL_BOOK_USER", "PERSONAL_BOOK_SHARE_USER", "HTML_EXPORT_USER", "PDF_EXPORT_USER", "SAVED_SEARCH_USER", "COLLECTION_USER", "OFFLINE_USER", "ANALYTICS_USER", "BETA_USER", "DEBUG_USER", "PRINT_USER", "RATING_USER", "FEEDBACK_USER", "GENERATIVE_AI_USER", "CONTENT_PUBLISHER", "KHUB_ADMIN", "USERS_ADMIN", "PORTAL_ADMIN", "ADMIN", "DEVELOPER"].includes(o);
694
695
  };
695
696
  export const isFtAuthenticationIdentifier = (o) => {
696
697
  return isObject(o)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/public-api",
3
- "version": "1.0.57",
3
+ "version": "1.0.58",
4
4
  "description": "Fluid Topics Public API",
5
5
  "author": "Fluid Topics dev team <opensource@antidot.net>",
6
6
  "license": "LGPL-3.0-only",
@@ -24,6 +24,7 @@
24
24
  },
25
25
  "devDependencies": {
26
26
  "@cyclonedx/bom": "^3.10.6",
27
+ "@open-wc/testing": "3.0.4",
27
28
  "@rollup/plugin-commonjs": "24.1.0",
28
29
  "@rollup/plugin-json": "6.0.0",
29
30
  "@rollup/plugin-node-resolve": "15.0.2",
@@ -31,6 +32,9 @@
31
32
  "@types/chai": "4.3.5",
32
33
  "@types/mocha": "10.0.1",
33
34
  "@types/node": "20.0.0",
35
+ "@web/test-runner": "0.15.3",
36
+ "@web/test-runner-junit-reporter": "0.5.2",
37
+ "@web/test-runner-playwright": "0.10.0",
34
38
  "chai": "4.3.7",
35
39
  "fetch-mock": "9.11.0",
36
40
  "mocha": "10.2.0",
@@ -38,6 +42,7 @@
38
42
  "rollup-plugin-terser": "7.0.2",
39
43
  "rollup-plugin-typescript2": "0.34.1",
40
44
  "ts-node": "10.9.1",
41
- "typescript": "5.0.4"
45
+ "typescript": "5.0.4",
46
+ "vite": "4.3.1"
42
47
  }
43
48
  }
@@ -0,0 +1,54 @@
1
+ import { expect } from "@open-wc/testing"
2
+ import { GenAIChunkReader } from "../../src/helpers/GenAIChunkReader"
3
+
4
+ class FakeStream implements ReadableStreamDefaultReader<Uint8Array> {
5
+ readonly closed: Promise<undefined>
6
+ readonly encoder = new TextEncoder()
7
+
8
+ constructor(readonly chunks: string[]) {
9
+ }
10
+
11
+ cancel(reason?: any): Promise<void> {
12
+ return Promise.resolve(undefined)
13
+ }
14
+
15
+ read() {
16
+ if (this.chunks.length === 0) {
17
+ return Promise.resolve({ done: true, value: undefined })
18
+ }
19
+ const chunk = this.chunks.shift()
20
+ let value: Uint8Array = this.encoder.encode(chunk)
21
+ return Promise.resolve({ done: false, value })
22
+ }
23
+
24
+ releaseLock(): void {
25
+ }
26
+
27
+ }
28
+
29
+ describe(GenAIChunkReader.name, () => {
30
+ it("should wait for complete chunks", async () => {
31
+ const stream = new FakeStream([
32
+ `data:{`,
33
+ `"foo`,
34
+ `":"bar"}\n`,
35
+ `data:{"foo":"quz"}\n`
36
+ ])
37
+ const generator = new GenAIChunkReader(stream).read()
38
+
39
+ expect((await generator.next()).value).to.deep.equal({ "foo": "bar" })
40
+ expect((await generator.next()).value).to.deep.equal({ "foo": "quz" })
41
+ expect((await generator.next()).done).to.be.true
42
+ })
43
+
44
+ it("should ignore non-data chunks", async () => {
45
+ const stream = new FakeStream([
46
+ `patate:{"foo":"bar"}\n`,
47
+ `data:{"foo":"quz"}\n`
48
+ ])
49
+ const generator = new GenAIChunkReader(stream).read()
50
+
51
+ expect((await generator.next()).value).to.deep.equal({ "foo": "quz" })
52
+ expect((await generator.next()).done).to.be.true
53
+ })
54
+ })
@@ -0,0 +1,95 @@
1
+ import http from "node:http"
2
+ import {existsSync} from "node:fs"
3
+ import {createServer} from "vite"
4
+
5
+ const callWithFileNames = (callback) => ({
6
+ name: "file-name",
7
+ transform(src, id) {
8
+ callback(id)
9
+ },
10
+ })
11
+
12
+ const markExternal = (options) => ({
13
+ name: "mark-external",
14
+ resolveId(path) {
15
+ if (!options.includes(path)) {
16
+ return
17
+ }
18
+
19
+ return {
20
+ id: path,
21
+ external: true
22
+ }
23
+ },
24
+ })
25
+
26
+ const get = url => new Promise((resolve, reject) => {
27
+ const request = http.get(url, (response) => {
28
+ const buffers = []
29
+ let bufferLen = 0
30
+
31
+ response.on("data", chunk => {
32
+ bufferLen += chunk.length
33
+ buffers.push(chunk)
34
+ })
35
+
36
+ response.on("end", () => resolve({
37
+ body: Buffer.concat(buffers, bufferLen),
38
+ headers: response.headers,
39
+ status: response.statusCode,
40
+ }))
41
+ })
42
+
43
+ request.on("error", (err) => reject(err))
44
+ })
45
+
46
+ const proxy = (url) => async ctx => {
47
+ const {body, headers, status} = await get(url + ctx.originalUrl)
48
+ ctx.set(headers)
49
+ ctx.body = body
50
+ ctx.status = status
51
+ }
52
+
53
+ export const vitePlugin = (conf) => {
54
+ let viteServer
55
+
56
+ return {
57
+ name: "vite-plugin",
58
+
59
+ async serverStart({app, fileWatcher}) {
60
+ const plugins = [
61
+ callWithFileNames(id => {
62
+ const file = id.split("?")[0]
63
+ if (!file.startsWith("\0") && existsSync(file)) {
64
+ fileWatcher.add(id)
65
+ }
66
+ }),
67
+ markExternal([
68
+ /* @web/test-runner-commands needs to establish a web-socket
69
+ * connection. It expects a file to be served from the
70
+ * @web/dev-server. So it should be ignored by Vite */
71
+ "/__web-dev-server__web-socket.js",
72
+ ]),
73
+ ]
74
+
75
+ viteServer = await createServer({
76
+ clearScreen: false,
77
+ plugins,
78
+ /* Disable hmr in favor of the @web/test-runner to take care of
79
+ * restarts. */
80
+ server: {hmr: false},
81
+ ...conf
82
+ })
83
+ await viteServer.listen()
84
+
85
+ const vitePort = viteServer.config.server.port
86
+ const viteProtocol = viteServer.config.server.https ? "https" : "http"
87
+
88
+ app.use(proxy(`${viteProtocol}://localhost:${vitePort}`))
89
+ },
90
+
91
+ async serverStop() {
92
+ return viteServer.close()
93
+ },
94
+ }
95
+ }