@fluid-topics/public-api 1.0.16 → 1.0.17

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
@@ -19,8 +19,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
19
19
  });
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.FluidTopicsApi = exports.HttpError = void 0;
22
+ exports.getUnauthenticatedUserSearchPreferences = exports.setUnauthenticatedUserSearchPreferences = exports.FluidTopicsApi = exports.HttpError = void 0;
23
23
  require("cross-fetch/polyfill");
24
+ const wnd = (typeof window === "undefined" ? globalThis : window);
24
25
  __exportStar(require("./types/ft-common/public"), exports);
25
26
  __exportStar(require("./types/ft-server/public"), exports);
26
27
  function toBase64(s) {
@@ -50,7 +51,7 @@ class FluidTopicsApi {
50
51
  constructor(tenantBaseUrl, integrationIdentifier, overrideIdentifierIfOnTenant) {
51
52
  this.authorization = {};
52
53
  this.tenantBaseUrl = tenantBaseUrl.trim().replace(/\/$/, "");
53
- if (overrideIdentifierIfOnTenant && typeof window !== "undefined" && window.location.href.startsWith(tenantBaseUrl)) {
54
+ if (overrideIdentifierIfOnTenant && typeof wnd.location !== "undefined" && wnd.location.href.startsWith(this.tenantBaseUrl + "/")) {
54
55
  this.ftCallingApp = integrationIdentifier;
55
56
  }
56
57
  else {
@@ -85,6 +86,9 @@ class FluidTopicsApi {
85
86
  return this.post(`/api/authentication/logout`)
86
87
  .then(() => this.clearAuthentication());
87
88
  }
89
+ getCurrentSession() {
90
+ return this.get(`/api/authentication/current-session`);
91
+ }
88
92
  getMap(mapId) {
89
93
  return this.get(`/api/khub/maps/${mapId}`);
90
94
  }
@@ -152,7 +156,7 @@ class FluidTopicsApi {
152
156
  return yield fetch(this.tenantBaseUrl + 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 : {})) }));
153
157
  });
154
158
  }
155
- upload(method, endpoint, body, onProgress = () => { }) {
159
+ upload(method, endpoint, body, onProgress = () => undefined) {
156
160
  return __awaiter(this, void 0, void 0, function* () {
157
161
  return new Promise((resolve, reject) => {
158
162
  let xhr = new XMLHttpRequest();
@@ -188,3 +192,50 @@ class FluidTopicsApi {
188
192
  }
189
193
  exports.FluidTopicsApi = FluidTopicsApi;
190
194
  exports.default = FluidTopicsApi;
195
+ function normalizeMetadataPreferences(metadata) {
196
+ let normalized = {};
197
+ for (let key in metadata) {
198
+ let values = metadata[key];
199
+ if (typeof values !== "object" || Array.isArray(values)) {
200
+ values = { prior: values };
201
+ }
202
+ for (let property of ["prior", "filter"]) {
203
+ values[property] = Array.isArray(values[property]) ? values[property] : [values[property]];
204
+ values[property] = values[property]
205
+ .map(v => v != null ? "" + v : "")
206
+ .filter(v => v !== "");
207
+ }
208
+ normalized[key] = values;
209
+ }
210
+ return normalized;
211
+ }
212
+ function setUnauthenticatedUserSearchPreferences(input, tenantBaseUrl) {
213
+ var _a, _b, _c, _d, _e, _f;
214
+ if (wnd.localStorage) {
215
+ //@ts-ignore
216
+ tenantBaseUrl = (_c = (_a = tenantBaseUrl !== null && tenantBaseUrl !== void 0 ? tenantBaseUrl : wnd.__gwt_ft_moduleBase) !== null && _a !== void 0 ? _a : (_b = wnd.fluidtopicsclient) === null || _b === void 0 ? void 0 : _b.__moduleBase) !== null && _c !== void 0 ? _c : (_e = (_d = wnd.__gwt_activeModules) === null || _d === void 0 ? void 0 : _d.fluidtopicsclient) === null || _e === void 0 ? void 0 : _e.moduleBase;
217
+ let preferences = Object.assign(Object.assign({}, input), { metadata: normalizeMetadataPreferences((_f = input.metadata) !== null && _f !== void 0 ? _f : {}) });
218
+ const key = `${tenantBaseUrl}-FluidTopicsUnauthenticatedUserSearchPreferences`;
219
+ const newValue = JSON.stringify(preferences);
220
+ wnd.localStorage.setItem(key, newValue);
221
+ wnd.dispatchEvent(new StorageEvent("storage", {
222
+ key,
223
+ newValue,
224
+ storageArea: wnd.localStorage,
225
+ url: wnd.location.href
226
+ }));
227
+ return preferences;
228
+ }
229
+ console.error("Cannot set unauthenticated preferences: local storage is unavailable.");
230
+ }
231
+ exports.setUnauthenticatedUserSearchPreferences = setUnauthenticatedUserSearchPreferences;
232
+ function getUnauthenticatedUserSearchPreferences(tenantBaseUrl) {
233
+ var _a, _b, _c, _d, _e, _f;
234
+ if (wnd.localStorage) {
235
+ //@ts-ignore
236
+ tenantBaseUrl = (_c = (_a = tenantBaseUrl !== null && tenantBaseUrl !== void 0 ? tenantBaseUrl : wnd.__gwt_ft_moduleBase) !== null && _a !== void 0 ? _a : (_b = wnd.fluidtopicsclient) === null || _b === void 0 ? void 0 : _b.__moduleBase) !== null && _c !== void 0 ? _c : (_e = (_d = wnd.__gwt_activeModules) === null || _d === void 0 ? void 0 : _d.fluidtopicsclient) === null || _e === void 0 ? void 0 : _e.moduleBase;
237
+ return JSON.parse((_f = wnd.localStorage.getItem(`${tenantBaseUrl}-FluidTopicsUnauthenticatedUserSearchPreferences`)) !== null && _f !== void 0 ? _f : "{}");
238
+ }
239
+ console.error("Cannot get unauthenticated preferences: local storage is unavailable.");
240
+ }
241
+ exports.getUnauthenticatedUserSearchPreferences = getUnauthenticatedUserSearchPreferences;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isFtAuthenticationIdentifier = exports.isFtSuggestResults = exports.isFtSuggestResult = exports.isFtSuggestRequest = exports.isFtTopicResource = exports.isFtSpellcheck = exports.isFtSearchSortCriterion = exports.isFtSearchFacetEntry = exports.isFtSearchFacetConf = exports.isFtSearchFacet = exports.isFtSearchResultType = exports.FtSearchResultType = exports.isFtSearchResultTopic = exports.isFtSearchResultMap = exports.isFtSearchResultUnstructuredDocument = exports.isFtSearchResultClusterEntry = exports.isFtSearchResultCluster = exports.isFtSearchRequest = exports.isFtSearchResults = exports.isFtCollectionDocumentType = exports.FtCollectionDocumentType = exports.isFtPageRequest = exports.isFtOpenMode = exports.FtOpenMode = exports.isFtEditorialType = exports.FtEditorialType = exports.isFtSearchResultsPageInfo = exports.isFtSearchPreset = exports.isFtSearchFilter = exports.isFtMapResource = exports.isFtMetadata = exports.isFtSearchLocales = exports.isFtSearchLocale = exports.isFtTopicContentTarget = exports.FtTopicContentTarget = exports.isFtUnstructuredDocument = exports.isFtTopic = exports.isFtTocNode = exports.isFtMap = exports.isFtCollectionDocument = exports.isFtCredentials = void 0;
3
+ exports.isFtAuthenticationIdentifier = exports.isFtSuggestResults = exports.isFtSuggestResult = exports.isFtSuggestRequest = exports.isFtTopicResource = exports.isFtSpellcheck = exports.isFtSearchSortCriterion = exports.isFtSearchFacetEntry = exports.isFtSearchFacetConf = exports.isFtSearchFacet = exports.isFtSearchResultType = exports.FtSearchResultType = exports.isFtSearchResultTopic = exports.isFtSearchResultMap = exports.isFtSearchResultUnstructuredDocument = exports.isFtSearchResultClusterEntry = exports.isFtSearchResultCluster = exports.isFtSearchRequest = exports.isFtSearchPrior = exports.isFtSearchResults = exports.isFtCollectionDocumentType = exports.FtCollectionDocumentType = exports.isFtPageRequest = exports.isFtOpenMode = exports.FtOpenMode = exports.isFtEditorialType = exports.FtEditorialType = exports.isFtSearchResultsPageInfo = exports.isFtSearchPreset = exports.isFtSearchFilter = exports.isFtSearchPreferencesConfiguration = exports.isFtMetadataPreferenceConfiguration = exports.isFtMapResource = exports.isFtMetadata = exports.isFtSearchLocales = exports.isFtSearchLocale = exports.isFtTopicContentTarget = exports.FtTopicContentTarget = exports.isFtUnstructuredDocument = exports.isFtTopic = exports.isFtTocNode = exports.isFtMap = exports.isFtCollectionDocument = exports.isFtCredentials = void 0;
4
4
  const isObject = (o) => typeof o === "object" && o != null;
5
5
  const isBoolean = (o) => typeof o === "boolean";
6
6
  const isNumber = (o) => typeof o === "number";
@@ -128,6 +128,21 @@ const isFtMapResource = (o) => {
128
128
  && (isString(o.mimeType));
129
129
  };
130
130
  exports.isFtMapResource = isFtMapResource;
131
+ const isFtMetadataPreferenceConfiguration = (o) => {
132
+ return isObject(o)
133
+ && ((Array.isArray(o.filter)
134
+ && o.filter.every((v) => isString(v))))
135
+ && ((Array.isArray(o.prior)
136
+ && o.prior.every((v) => isString(v))));
137
+ };
138
+ exports.isFtMetadataPreferenceConfiguration = isFtMetadataPreferenceConfiguration;
139
+ const isFtSearchPreferencesConfiguration = (o) => {
140
+ return isObject(o)
141
+ && ((isObject(o.metadata)
142
+ && Object.keys(o.metadata).every((k) => isString(k))
143
+ && Object.values(o.metadata).every((v) => (0, exports.isFtMetadataPreferenceConfiguration)(v))));
144
+ };
145
+ exports.isFtSearchPreferencesConfiguration = isFtSearchPreferencesConfiguration;
131
146
  const isFtSearchFilter = (o) => {
132
147
  return isObject(o)
133
148
  && (isBoolean(o.negative))
@@ -201,6 +216,13 @@ const isFtSearchResults = (o) => {
201
216
  && o.facets.every((v) => (0, exports.isFtSearchFacet)(v))));
202
217
  };
203
218
  exports.isFtSearchResults = isFtSearchResults;
219
+ const isFtSearchPrior = (o) => {
220
+ return isObject(o)
221
+ && (isNumber(o.weight))
222
+ && (isString(o.value))
223
+ && (isString(o.key));
224
+ };
225
+ exports.isFtSearchPrior = isFtSearchPrior;
204
226
  const isFtSearchRequest = (o) => {
205
227
  return isObject(o)
206
228
  && (isString(o.query))
@@ -211,6 +233,8 @@ const isFtSearchRequest = (o) => {
211
233
  && o.sort.every((v) => (0, exports.isFtSearchSortCriterion)(v))))
212
234
  && (o.uiLocale == null || isString(o.uiLocale))
213
235
  && (o.contentLocale == null || isString(o.contentLocale))
236
+ && (o.priors == null || (Array.isArray(o.priors)
237
+ && o.priors.every((v) => (0, exports.isFtSearchPrior)(v))))
214
238
  && ((Array.isArray(o.facets)
215
239
  && o.facets.every((v) => (0, exports.isFtSearchFacetConf)(v))));
216
240
  };
@@ -253,7 +277,7 @@ const isFtSearchResultMap = (o) => {
253
277
  return isObject(o)
254
278
  && ((Array.isArray(o.metadata)
255
279
  && o.metadata.every((v) => (0, exports.isFtMetadata)(v))))
256
- && ((0, exports.isFtOpenMode)(o.openMode))
280
+ && (o.openMode == null || (0, exports.isFtOpenMode)(o.openMode))
257
281
  && ((0, exports.isFtEditorialType)(o.editorialType))
258
282
  && (isString(o.title))
259
283
  && (o.lastPublicationDate == null || isString(o.lastPublicationDate))
@@ -356,7 +380,9 @@ const isFtSuggestRequest = (o) => {
356
380
  && ((Array.isArray(o.sort)
357
381
  && o.sort.every((v) => (0, exports.isFtSearchSortCriterion)(v))))
358
382
  && (o.maxCount == null || isNumber(o.maxCount))
359
- && (o.contentLocale == null || isString(o.contentLocale));
383
+ && (o.contentLocale == null || isString(o.contentLocale))
384
+ && (o.priors == null || (Array.isArray(o.priors)
385
+ && o.priors.every((v) => (0, exports.isFtSearchPrior)(v))));
360
386
  };
361
387
  exports.isFtSuggestRequest = isFtSuggestRequest;
362
388
  const isFtSuggestResult = (o) => {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isFtMapAttachment = exports.isFtUserProfile = exports.isFtAuthenticatedSession = void 0;
3
+ exports.isFtMapAttachment = exports.isFtUserProfile = exports.isFtSession = exports.isFtAuthenticatedSession = void 0;
4
4
  const isObject = (o) => typeof o === "object" && o != null;
5
5
  const isBoolean = (o) => typeof o === "boolean";
6
6
  const isNumber = (o) => typeof o === "number";
@@ -10,6 +10,13 @@ const isFtAuthenticatedSession = (o) => {
10
10
  && ((0, exports.isFtUserProfile)(o.profile));
11
11
  };
12
12
  exports.isFtAuthenticatedSession = isFtAuthenticatedSession;
13
+ const isFtSession = (o) => {
14
+ return isObject(o)
15
+ && (isNumber(o.idleTimeoutInMillis))
16
+ && (o.profile == null || (0, exports.isFtUserProfile)(o.profile))
17
+ && (isBoolean(o.sessionAuthenticated));
18
+ };
19
+ exports.isFtSession = isFtSession;
13
20
  const isFtUserProfile = (o) => {
14
21
  return isObject(o)
15
22
  && (o.emailAddress == null || isString(o.emailAddress))
@@ -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:{},r={exports:{}},i={exports:{}};!function(e,t){var r=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==r)return r;throw new Error("unable to locate global object")}();e.exports=t=r.fetch,r.fetch&&(t.default=r.fetch.bind(r)),t.Headers=r.Headers,t.Request=r.Request,t.Response=r.Response}(i,i.exports),function(e,t){const r=i.exports,a=r.default||r,n=function(e,t){return/^\/\//.test(e)&&(e="https:"+e),a.call(this,e,t)};n.ponyfill=!0,e.exports=t=n,t.fetch=n,t.Headers=r.Headers,t.Request=r.Request,t.Response=r.Response,t.default=n}(r,r.exports);const a=r.exports,n=a.fetch.bind({});n.polyfill=!0,t.fetch||(t.fetch=n,t.Response=a.Response,t.Headers=a.Headers,t.Request=a.Request);const s=e=>"object"==typeof e&&null!=e,l=e=>"boolean"==typeof e,o=e=>"number"==typeof e,u=e=>"string"==typeof e,c=e=>s(e)&&u(e.tocId)&&Array.isArray(e.children)&&e.children.every((e=>c(e)))&&u(e.contentId)&&u(e.title);var p;e.FtTopicContentTarget=void 0,(p=e.FtTopicContentTarget||(e.FtTopicContentTarget={})).THIRD_PARTY="THIRD_PARTY",p.OFF_THE_GRID="OFF_THE_GRID";const d=e=>s(e)&&o(e.count)&&u(e.label)&&(null==e.lang||u(e.lang)),h=e=>s(e)&&Array.isArray(e.values)&&e.values.every((e=>u(e)))&&u(e.label)&&u(e.key),y=e=>s(e)&&l(e.negative)&&Array.isArray(e.values)&&e.values.every((e=>u(e)))&&u(e.key),f=e=>s(e)&&o(e.totalResultsCount)&&l(e.lastPage)&&o(e.currentPage)&&o(e.totalClustersCount);var m;e.FtEditorialType=void 0,(m=e.FtEditorialType||(e.FtEditorialType={})).ARTICLE="ARTICLE",m.BOOK="BOOK";const g=e=>["ARTICLE","BOOK"].includes(e);var A;e.FtOpenMode=void 0,(A=e.FtOpenMode||(e.FtOpenMode={})).FLUIDTOPICS="FLUIDTOPICS",A.EXTERNAL="EXTERNAL";const T=e=>["FLUIDTOPICS","EXTERNAL"].includes(e),F=e=>s(e)&&(null==e.perPage||o(e.perPage))&&o(e.page);var b;e.FtCollectionDocumentType=void 0,(b=e.FtCollectionDocumentType||(e.FtCollectionDocumentType={})).MAP="MAP",b.DOCUMENT="DOCUMENT",b.TOPIC="TOPIC",b.PERSONAL_BOOK="PERSONAL_BOOK",b.SHARED_BOOK="SHARED_BOOK";const R=e=>["MAP","DOCUMENT","TOPIC","PERSONAL_BOOK","SHARED_BOOK"].includes(e),C=e=>s(e)&&Array.isArray(e.entries)&&e.entries.every((e=>E(e)))&&(null==e.metadataVariableAxis||u(e.metadataVariableAxis)),E=e=>s(e)&&(null==e.document||U(e.document))&&(null==e.topic||O(e.topic))&&S(e.type)&&(null==e.map||v(e.map)),U=e=>s(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>h(e)))&&T(e.openMode)&&u(e.documentUrl)&&u(e.mimeType)&&u(e.title)&&(null==e.lastPublicationDate||u(e.lastPublicationDate))&&u(e.viewerUrl)&&u(e.contentUrl)&&u(e.filename)&&u(e.htmlTitle)&&(null==e.originUrl||u(e.originUrl))&&u(e.documentId)&&u(e.lastEditionDate)&&u(e.htmlExcerpt),v=e=>s(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>h(e)))&&T(e.openMode)&&g(e.editorialType)&&u(e.title)&&(null==e.lastPublicationDate||u(e.lastPublicationDate))&&u(e.htmlTitle)&&(null==e.originUrl||u(e.originUrl))&&u(e.mapUrl)&&u(e.readerUrl)&&u(e.mapId)&&(null==e.lastEditionDate||u(e.lastEditionDate))&&u(e.htmlExcerpt),O=e=>s(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>h(e)))&&T(e.openMode)&&u(e.contentId)&&Array.isArray(e.resources)&&e.resources.every((e=>k(e)))&&u(e.title)&&u(e.mapTitle)&&u(e.topicUrl)&&u(e.contentUrl)&&u(e.htmlTitle)&&Array.isArray(e.breadcrumb)&&e.breadcrumb.every((e=>u(e)))&&u(e.tocId)&&(null==e.originUrl||u(e.originUrl))&&u(e.readerUrl)&&u(e.mapId)&&(null==e.lastEditionDate||u(e.lastEditionDate))&&u(e.htmlExcerpt);var D;e.FtSearchResultType=void 0,(D=e.FtSearchResultType||(e.FtSearchResultType={})).MAP="MAP",D.DOCUMENT="DOCUMENT",D.TOPIC="TOPIC";const S=e=>["MAP","DOCUMENT","TOPIC"].includes(e),P=e=>s(e)&&l(e.hierarchical)&&u(e.label)&&l(e.multiSelectionable)&&u(e.key)&&Array.isArray(e.rootNodes)&&e.rootNodes.every((e=>w(e))),I=e=>s(e)&&(null==e.maxDepth||o(e.maxDepth))&&u(e.id),w=e=>s(e)&&o(e.totalResultsCount)&&l(e.descendantSelected)&&Array.isArray(e.childNodes)&&e.childNodes.every((e=>w(e)))&&u(e.label)&&u(e.value)&&l(e.selected),x=e=>s(e)&&u(e.key),M=e=>s(e)&&u(e.suggestedQuery)&&u(e.htmlSuggestedQuery),k=e=>s(e)&&u(e.filename)&&u(e.resourceUrl)&&u(e.id)&&u(e.mimeType)&&u(e.resourceContentUrl)&&u(e.viewerUrl),L=e=>s(e)&&(null==e.filenameExtension||u(e.filenameExtension))&&(null==e.editorialType||g(e.editorialType))&&(null==e.mimeType||u(e.mimeType))&&S(e.type)&&u(e.value),$=e=>"object"==typeof e&&null!=e,H=e=>"string"==typeof e,N=e=>$(e)&&(null==e.emailAddress||H(e.emailAddress))&&(null==e.displayName||H(e.displayName))&&Array.isArray(e.roles)&&H(e.userId);class B extends Error{status;statusText;body;constructor(e,t,r){super(`${e} - ${t}: ${r}`),this.status=e,this.statusText=t,this.body=r}}async function q(e){if(!e.ok)throw new B(e.status,e.statusText,await e.text());return e}function _(e){return"application/json"===e.headers.get("Content-Type")?e.json():e.text()}class K{tenantBaseUrl;ftCallingApp;authorization={};get defaultHeaders(){return{...this.authorization,"Ft-Calling-App":this.ftCallingApp}}constructor(e,t,r){this.tenantBaseUrl=e.trim().replace(/\/$/,""),r&&"undefined"!=typeof window&&window.location.href.startsWith(e)?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={}}login(e,t){let r={login:e,password:t,rememberMe:!0};return this.post("/api/authentication/login",r).then((r=>(this.setCredentials(e,t),r)))}logout(){return this.post("/api/authentication/logout").then((()=>this.clearAuthentication()))}getMap(e){return this.get(`/api/khub/maps/${e}`)}getTableOfContent(e){return this.get(`/api/khub/maps/${e}/toc`)}getTopic(e,t){return this.get(`/api/khub/maps/${e}/topics/${t}`)}getTopicHTMLContent(e,t,r){return this.get(`/api/khub/maps/${e}/topics/${t}/content${r?"?target="+r:""}`)}getMapAttachments(e){return this.get(`/api/khub/maps/${e}/attachments`)}getMapAttachmentContent(e,t){return this.fetchRawData(`/api/khub/maps/${e}/attachments/${t}/content`)}getMapResources(e){return this.get(`/api/khub/maps/${e}/resources`)}getMapResourceContent(e,t){return this.fetchRawData(`/api/khub/maps/${e}/resources/${t}/content`)}getUnstructuredDocument(e){return this.get(`/api/khub/documents/${e}`)}getUnstructuredDocumentContent(e){return this.fetchRawData(`/api/khub/documents/${e}/content`)}getUnstructuredDocumentTextContent(e){return this.get(`/api/khub/documents/${e}/content/text`)}getCollectionDocuments(e,t){return this.get(`/api/users/${e}/collections/${t}/documents`)}getSuggestions(e){return this.post("/api/khub/suggest",e)}search(e){return this.post("/api/khub/clustered-search",e)}getAvailableSearchLocales(){return this.get("/api/khub/locales")}get(e){return this.makeRequest("GET",e)}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)}async fetch(e,t){const r=t;return e.startsWith("/")||(e="/"+e),await fetch(this.tenantBaseUrl+e,{...r??{},headers:{...this.defaultHeaders,...r?.headers??{}}})}async upload(e,t,r,i=(()=>{})){return new Promise(((a,n)=>{let s=new XMLHttpRequest;s.onload=()=>{if(s.status>=200&&s.status<300){let e="application/json"===s.getResponseHeader("Content-Type")?JSON.parse(s.responseText):s.responseText;a(e)}else n(new B(s.status,s.statusText,s.responseText))},s.upload.onprogress=e=>i(e),s.open(e,this.tenantBaseUrl+t,!0),s.send(r)}))}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}).then(q).then(_)}fetchRawData(e){return fetch(this.tenantBaseUrl+e,{headers:this.defaultHeaders}).then(q).then((e=>e.arrayBuffer()))}}e.FluidTopicsApi=K,e.HttpError=B,e.default=K,e.isFtAuthenticatedSession=e=>$(e)&&N(e.profile),e.isFtAuthenticationIdentifier=e=>s(e)&&u(e.identifier)&&u(e.realm),e.isFtCollectionDocument=e=>s(e)&&l(e.deleted)&&(null==e.apiUrl||u(e.apiUrl))&&(null==e.portalUrl||u(e.portalUrl))&&u(e.id)&&u(e.title)&&R(e.type),e.isFtCollectionDocumentType=R,e.isFtCredentials=e=>s(e)&&u(e.password)&&(null==e.newPassword||u(e.newPassword))&&l(e.rememberMe)&&u(e.login),e.isFtEditorialType=g,e.isFtMap=e=>s(e)&&(null==e.prettyUrl||u(e.prettyUrl))&&Array.isArray(e.metadata)&&e.metadata.every((e=>h(e)))&&T(e.openMode)&&u(e.topicsApiEndpoint)&&(null==e.description||u(e.description))&&u(e.attachmentsApiEndpoint)&&g(e.editorialType)&&u(e.baseId)&&u(e.clusterId)&&u(e.title)&&u(e.lastPublication)&&u(e.lastEdition)&&u(e.originId)&&u(e.rightsApiEndpoint)&&(null==e.originUrl||u(e.originUrl))&&u(e.readerUrl)&&(null==e.khubVersion||u(e.khubVersion))&&u(e.id)&&(null==e.lang||u(e.lang)),e.isFtMapAttachment=e=>$(e)&&H(e.file)&&(null==e.size||(e=>"number"==typeof e)(e.size))&&(e=>"boolean"==typeof e)(e.externalLink)&&H(e.name)&&H(e.id)&&(null==e.mimeType||H(e.mimeType))&&(null==e.viewerUrl||H(e.viewerUrl)),e.isFtMapResource=e=>s(e)&&u(e.contentUrl)&&u(e.filename)&&u(e.id)&&u(e.mimeType),e.isFtMetadata=h,e.isFtOpenMode=T,e.isFtPageRequest=F,e.isFtSearchFacet=P,e.isFtSearchFacetConf=I,e.isFtSearchFacetEntry=w,e.isFtSearchFilter=y,e.isFtSearchLocale=d,e.isFtSearchLocales=e=>s(e)&&Array.isArray(e.contentLocales)&&e.contentLocales.every((e=>d(e))),e.isFtSearchPreset=e=>s(e)&&u(e.name)&&Array.isArray(e.filters)&&e.filters.every((e=>y(e)))&&(null==e.contentLocale||u(e.contentLocale)),e.isFtSearchRequest=e=>s(e)&&u(e.query)&&F(e.paging)&&Array.isArray(e.filters)&&e.filters.every((e=>y(e)))&&Array.isArray(e.sort)&&e.sort.every((e=>x(e)))&&(null==e.uiLocale||u(e.uiLocale))&&(null==e.contentLocale||u(e.contentLocale))&&Array.isArray(e.facets)&&e.facets.every((e=>I(e))),e.isFtSearchResultCluster=C,e.isFtSearchResultClusterEntry=E,e.isFtSearchResultMap=v,e.isFtSearchResultTopic=O,e.isFtSearchResultType=S,e.isFtSearchResultUnstructuredDocument=U,e.isFtSearchResults=e=>s(e)&&(null==e.spellcheck||M(e.spellcheck))&&f(e.paging)&&Array.isArray(e.results)&&e.results.every((e=>C(e)))&&Array.isArray(e.facets)&&e.facets.every((e=>P(e))),e.isFtSearchResultsPageInfo=f,e.isFtSearchSortCriterion=x,e.isFtSpellcheck=M,e.isFtSuggestRequest=e=>s(e)&&u(e.input)&&Array.isArray(e.filters)&&e.filters.every((e=>y(e)))&&Array.isArray(e.sort)&&e.sort.every((e=>x(e)))&&(null==e.maxCount||o(e.maxCount))&&(null==e.contentLocale||u(e.contentLocale)),e.isFtSuggestResult=L,e.isFtSuggestResults=e=>s(e)&&Array.isArray(e.suggestions)&&e.suggestions.every((e=>L(e))),e.isFtTocNode=c,e.isFtTopic=e=>s(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>h(e)))&&u(e.id)&&u(e.contentApiEndpoint)&&u(e.title),e.isFtTopicContentTarget=e=>["THIRD_PARTY","OFF_THE_GRID"].includes(e),e.isFtTopicResource=k,e.isFtUnstructuredDocument=e=>s(e)&&(null==e.prettyUrl||u(e.prettyUrl))&&Array.isArray(e.metadata)&&e.metadata.every((e=>h(e)))&&u(e.openMode)&&(null==e.description||u(e.description))&&u(e.mimeType)&&(null==e.baseId||u(e.baseId))&&(null==e.clusterId||u(e.clusterId))&&u(e.contentApiEndpoint)&&u(e.title)&&(null==e.lastPublication||u(e.lastPublication))&&u(e.viewerUrl)&&u(e.lastEdition)&&u(e.filename)&&(null==e.originId||u(e.originId))&&u(e.rightsApiEndpoint)&&(null==e.originUrl||u(e.originUrl))&&(null==e.khubVersion||u(e.khubVersion))&&u(e.id)&&(null==e.lang||u(e.lang)),e.isFtUserProfile=N}));
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:{},r={exports:{}},a={exports:{}};!function(e,t){var r=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==r)return r;throw new Error("unable to locate global object")}();e.exports=t=r.fetch,r.fetch&&(t.default=r.fetch.bind(r)),t.Headers=r.Headers,t.Request=r.Request,t.Response=r.Response}(a,a.exports),function(e,t){const r=a.exports,i=r.default||r,n=function(e,t){return/^\/\//.test(e)&&(e="https:"+e),i.call(this,e,t)};n.ponyfill=!0,e.exports=t=n,t.fetch=n,t.Headers=r.Headers,t.Request=r.Request,t.Response=r.Response,t.default=n}(r,r.exports);const i=r.exports,n=i.fetch.bind({});n.polyfill=!0,t.fetch||(t.fetch=n,t.Response=i.Response,t.Headers=i.Headers,t.Request=i.Request);const s=e=>"object"==typeof e&&null!=e,l=e=>"boolean"==typeof e,o=e=>"number"==typeof e,u=e=>"string"==typeof e,c=e=>s(e)&&u(e.tocId)&&Array.isArray(e.children)&&e.children.every((e=>c(e)))&&u(e.contentId)&&u(e.title);var p;e.FtTopicContentTarget=void 0,(p=e.FtTopicContentTarget||(e.FtTopicContentTarget={})).THIRD_PARTY="THIRD_PARTY",p.OFF_THE_GRID="OFF_THE_GRID";const d=e=>s(e)&&o(e.count)&&u(e.label)&&(null==e.lang||u(e.lang)),h=e=>s(e)&&Array.isArray(e.values)&&e.values.every((e=>u(e)))&&u(e.label)&&u(e.key),y=e=>s(e)&&Array.isArray(e.filter)&&e.filter.every((e=>u(e)))&&Array.isArray(e.prior)&&e.prior.every((e=>u(e))),f=e=>s(e)&&l(e.negative)&&Array.isArray(e.values)&&e.values.every((e=>u(e)))&&u(e.key),g=e=>s(e)&&o(e.totalResultsCount)&&l(e.lastPage)&&o(e.currentPage)&&o(e.totalClustersCount);var m;e.FtEditorialType=void 0,(m=e.FtEditorialType||(e.FtEditorialType={})).ARTICLE="ARTICLE",m.BOOK="BOOK";const A=e=>["ARTICLE","BOOK"].includes(e);var T;e.FtOpenMode=void 0,(T=e.FtOpenMode||(e.FtOpenMode={})).FLUIDTOPICS="FLUIDTOPICS",T.EXTERNAL="EXTERNAL";const F=e=>["FLUIDTOPICS","EXTERNAL"].includes(e),b=e=>s(e)&&(null==e.perPage||o(e.perPage))&&o(e.page);var v;e.FtCollectionDocumentType=void 0,(v=e.FtCollectionDocumentType||(e.FtCollectionDocumentType={})).MAP="MAP",v.DOCUMENT="DOCUMENT",v.TOPIC="TOPIC",v.PERSONAL_BOOK="PERSONAL_BOOK",v.SHARED_BOOK="SHARED_BOOK";const R=e=>["MAP","DOCUMENT","TOPIC","PERSONAL_BOOK","SHARED_BOOK"].includes(e),U=e=>s(e)&&o(e.weight)&&u(e.value)&&u(e.key),C=e=>s(e)&&Array.isArray(e.entries)&&e.entries.every((e=>S(e)))&&(null==e.metadataVariableAxis||u(e.metadataVariableAxis)),S=e=>s(e)&&(null==e.document||E(e.document))&&(null==e.topic||P(e.topic))&&w(e.type)&&(null==e.map||O(e.map)),E=e=>s(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>h(e)))&&F(e.openMode)&&u(e.documentUrl)&&u(e.mimeType)&&u(e.title)&&(null==e.lastPublicationDate||u(e.lastPublicationDate))&&u(e.viewerUrl)&&u(e.contentUrl)&&u(e.filename)&&u(e.htmlTitle)&&(null==e.originUrl||u(e.originUrl))&&u(e.documentId)&&u(e.lastEditionDate)&&u(e.htmlExcerpt),O=e=>s(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>h(e)))&&(null==e.openMode||F(e.openMode))&&A(e.editorialType)&&u(e.title)&&(null==e.lastPublicationDate||u(e.lastPublicationDate))&&u(e.htmlTitle)&&(null==e.originUrl||u(e.originUrl))&&u(e.mapUrl)&&u(e.readerUrl)&&u(e.mapId)&&(null==e.lastEditionDate||u(e.lastEditionDate))&&u(e.htmlExcerpt),P=e=>s(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>h(e)))&&F(e.openMode)&&u(e.contentId)&&Array.isArray(e.resources)&&e.resources.every((e=>L(e)))&&u(e.title)&&u(e.mapTitle)&&u(e.topicUrl)&&u(e.contentUrl)&&u(e.htmlTitle)&&Array.isArray(e.breadcrumb)&&e.breadcrumb.every((e=>u(e)))&&u(e.tocId)&&(null==e.originUrl||u(e.originUrl))&&u(e.readerUrl)&&u(e.mapId)&&(null==e.lastEditionDate||u(e.lastEditionDate))&&u(e.htmlExcerpt);var D;e.FtSearchResultType=void 0,(D=e.FtSearchResultType||(e.FtSearchResultType={})).MAP="MAP",D.DOCUMENT="DOCUMENT",D.TOPIC="TOPIC";const w=e=>["MAP","DOCUMENT","TOPIC"].includes(e),I=e=>s(e)&&l(e.hierarchical)&&u(e.label)&&l(e.multiSelectionable)&&u(e.key)&&Array.isArray(e.rootNodes)&&e.rootNodes.every((e=>k(e))),M=e=>s(e)&&(null==e.maxDepth||o(e.maxDepth))&&u(e.id),k=e=>s(e)&&o(e.totalResultsCount)&&l(e.descendantSelected)&&Array.isArray(e.childNodes)&&e.childNodes.every((e=>k(e)))&&u(e.label)&&u(e.value)&&l(e.selected),x=e=>s(e)&&u(e.key),_=e=>s(e)&&u(e.suggestedQuery)&&u(e.htmlSuggestedQuery),L=e=>s(e)&&u(e.filename)&&u(e.resourceUrl)&&u(e.id)&&u(e.mimeType)&&u(e.resourceContentUrl)&&u(e.viewerUrl),$=e=>s(e)&&(null==e.filenameExtension||u(e.filenameExtension))&&(null==e.editorialType||A(e.editorialType))&&(null==e.mimeType||u(e.mimeType))&&w(e.type)&&u(e.value),B=e=>"object"==typeof e&&null!=e,N=e=>"boolean"==typeof e,H=e=>"number"==typeof e,q=e=>"string"==typeof e,j=e=>B(e)&&(null==e.emailAddress||q(e.emailAddress))&&(null==e.displayName||q(e.displayName))&&Array.isArray(e.roles)&&q(e.userId),K="undefined"==typeof window?globalThis:window;class z extends Error{status;statusText;body;constructor(e,t,r){super(`${e} - ${t}: ${r}`),this.status=e,this.statusText=t,this.body=r}}async function V(e){if(!e.ok)throw new z(e.status,e.statusText,await e.text());return e}function G(e){return"application/json"===e.headers.get("Content-Type")?e.json():e.text()}class J{tenantBaseUrl;ftCallingApp;authorization={};get defaultHeaders(){return{...this.authorization,"Ft-Calling-App":this.ftCallingApp}}constructor(e,t,r){this.tenantBaseUrl=e.trim().replace(/\/$/,""),r&&void 0!==K.location&&K.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={}}login(e,t){let r={login:e,password:t,rememberMe:!0};return this.post("/api/authentication/login",r).then((r=>(this.setCredentials(e,t),r)))}logout(){return this.post("/api/authentication/logout").then((()=>this.clearAuthentication()))}getCurrentSession(){return this.get("/api/authentication/current-session")}getMap(e){return this.get(`/api/khub/maps/${e}`)}getTableOfContent(e){return this.get(`/api/khub/maps/${e}/toc`)}getTopic(e,t){return this.get(`/api/khub/maps/${e}/topics/${t}`)}getTopicHTMLContent(e,t,r){return this.get(`/api/khub/maps/${e}/topics/${t}/content${r?"?target="+r:""}`)}getMapAttachments(e){return this.get(`/api/khub/maps/${e}/attachments`)}getMapAttachmentContent(e,t){return this.fetchRawData(`/api/khub/maps/${e}/attachments/${t}/content`)}getMapResources(e){return this.get(`/api/khub/maps/${e}/resources`)}getMapResourceContent(e,t){return this.fetchRawData(`/api/khub/maps/${e}/resources/${t}/content`)}getUnstructuredDocument(e){return this.get(`/api/khub/documents/${e}`)}getUnstructuredDocumentContent(e){return this.fetchRawData(`/api/khub/documents/${e}/content`)}getUnstructuredDocumentTextContent(e){return this.get(`/api/khub/documents/${e}/content/text`)}getCollectionDocuments(e,t){return this.get(`/api/users/${e}/collections/${t}/documents`)}getSuggestions(e){return this.post("/api/khub/suggest",e)}search(e){return this.post("/api/khub/clustered-search",e)}getAvailableSearchLocales(){return this.get("/api/khub/locales")}get(e){return this.makeRequest("GET",e)}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)}async fetch(e,t){const r=t;return e.startsWith("/")||(e="/"+e),await fetch(this.tenantBaseUrl+e,{...r??{},headers:{...this.defaultHeaders,...r?.headers??{}}})}async upload(e,t,r,a=(()=>{})){return new Promise(((i,n)=>{let s=new XMLHttpRequest;s.onload=()=>{if(s.status>=200&&s.status<300){let e="application/json"===s.getResponseHeader("Content-Type")?JSON.parse(s.responseText):s.responseText;i(e)}else n(new z(s.status,s.statusText,s.responseText))},s.upload.onprogress=e=>a(e),s.open(e,this.tenantBaseUrl+t,!0),s.send(r)}))}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}).then(V).then(G)}fetchRawData(e){return fetch(this.tenantBaseUrl+e,{headers:this.defaultHeaders}).then(V).then((e=>e.arrayBuffer()))}}function X(e){let t={};for(let r in e){let a=e[r];("object"!=typeof a||Array.isArray(a))&&(a={prior:a});for(let e of["prior","filter"])a[e]=Array.isArray(a[e])?a[e]:[a[e]],a[e]=a[e].map((e=>null!=e?""+e:"")).filter((e=>""!==e));t[r]=a}return t}e.FluidTopicsApi=J,e.HttpError=z,e.default=J,e.getUnauthenticatedUserSearchPreferences=function(e){if(K.localStorage)return e=e??K.__gwt_ft_moduleBase??K.fluidtopicsclient?.__moduleBase??K.__gwt_activeModules?.fluidtopicsclient?.moduleBase,JSON.parse(K.localStorage.getItem(`${e}-FluidTopicsUnauthenticatedUserSearchPreferences`)??"{}");console.error("Cannot get unauthenticated preferences: local storage is unavailable.")},e.isFtAuthenticatedSession=e=>B(e)&&j(e.profile),e.isFtAuthenticationIdentifier=e=>s(e)&&u(e.identifier)&&u(e.realm),e.isFtCollectionDocument=e=>s(e)&&l(e.deleted)&&(null==e.apiUrl||u(e.apiUrl))&&(null==e.portalUrl||u(e.portalUrl))&&u(e.id)&&u(e.title)&&R(e.type),e.isFtCollectionDocumentType=R,e.isFtCredentials=e=>s(e)&&u(e.password)&&(null==e.newPassword||u(e.newPassword))&&l(e.rememberMe)&&u(e.login),e.isFtEditorialType=A,e.isFtMap=e=>s(e)&&(null==e.prettyUrl||u(e.prettyUrl))&&Array.isArray(e.metadata)&&e.metadata.every((e=>h(e)))&&F(e.openMode)&&u(e.topicsApiEndpoint)&&(null==e.description||u(e.description))&&u(e.attachmentsApiEndpoint)&&A(e.editorialType)&&u(e.baseId)&&u(e.clusterId)&&u(e.title)&&u(e.lastPublication)&&u(e.lastEdition)&&u(e.originId)&&u(e.rightsApiEndpoint)&&(null==e.originUrl||u(e.originUrl))&&u(e.readerUrl)&&(null==e.khubVersion||u(e.khubVersion))&&u(e.id)&&(null==e.lang||u(e.lang)),e.isFtMapAttachment=e=>B(e)&&q(e.file)&&(null==e.size||H(e.size))&&N(e.externalLink)&&q(e.name)&&q(e.id)&&(null==e.mimeType||q(e.mimeType))&&(null==e.viewerUrl||q(e.viewerUrl)),e.isFtMapResource=e=>s(e)&&u(e.contentUrl)&&u(e.filename)&&u(e.id)&&u(e.mimeType),e.isFtMetadata=h,e.isFtMetadataPreferenceConfiguration=y,e.isFtOpenMode=F,e.isFtPageRequest=b,e.isFtSearchFacet=I,e.isFtSearchFacetConf=M,e.isFtSearchFacetEntry=k,e.isFtSearchFilter=f,e.isFtSearchLocale=d,e.isFtSearchLocales=e=>s(e)&&Array.isArray(e.contentLocales)&&e.contentLocales.every((e=>d(e))),e.isFtSearchPreferencesConfiguration=e=>s(e)&&s(e.metadata)&&Object.keys(e.metadata).every((e=>u(e)))&&Object.values(e.metadata).every((e=>y(e))),e.isFtSearchPreset=e=>s(e)&&u(e.name)&&Array.isArray(e.filters)&&e.filters.every((e=>f(e)))&&(null==e.contentLocale||u(e.contentLocale)),e.isFtSearchPrior=U,e.isFtSearchRequest=e=>s(e)&&u(e.query)&&b(e.paging)&&Array.isArray(e.filters)&&e.filters.every((e=>f(e)))&&Array.isArray(e.sort)&&e.sort.every((e=>x(e)))&&(null==e.uiLocale||u(e.uiLocale))&&(null==e.contentLocale||u(e.contentLocale))&&(null==e.priors||Array.isArray(e.priors)&&e.priors.every((e=>U(e))))&&Array.isArray(e.facets)&&e.facets.every((e=>M(e))),e.isFtSearchResultCluster=C,e.isFtSearchResultClusterEntry=S,e.isFtSearchResultMap=O,e.isFtSearchResultTopic=P,e.isFtSearchResultType=w,e.isFtSearchResultUnstructuredDocument=E,e.isFtSearchResults=e=>s(e)&&(null==e.spellcheck||_(e.spellcheck))&&g(e.paging)&&Array.isArray(e.results)&&e.results.every((e=>C(e)))&&Array.isArray(e.facets)&&e.facets.every((e=>I(e))),e.isFtSearchResultsPageInfo=g,e.isFtSearchSortCriterion=x,e.isFtSession=e=>B(e)&&H(e.idleTimeoutInMillis)&&(null==e.profile||j(e.profile))&&N(e.sessionAuthenticated),e.isFtSpellcheck=_,e.isFtSuggestRequest=e=>s(e)&&u(e.input)&&Array.isArray(e.filters)&&e.filters.every((e=>f(e)))&&Array.isArray(e.sort)&&e.sort.every((e=>x(e)))&&(null==e.maxCount||o(e.maxCount))&&(null==e.contentLocale||u(e.contentLocale))&&(null==e.priors||Array.isArray(e.priors)&&e.priors.every((e=>U(e)))),e.isFtSuggestResult=$,e.isFtSuggestResults=e=>s(e)&&Array.isArray(e.suggestions)&&e.suggestions.every((e=>$(e))),e.isFtTocNode=c,e.isFtTopic=e=>s(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>h(e)))&&u(e.id)&&u(e.contentApiEndpoint)&&u(e.title),e.isFtTopicContentTarget=e=>["THIRD_PARTY","OFF_THE_GRID"].includes(e),e.isFtTopicResource=L,e.isFtUnstructuredDocument=e=>s(e)&&(null==e.prettyUrl||u(e.prettyUrl))&&Array.isArray(e.metadata)&&e.metadata.every((e=>h(e)))&&u(e.openMode)&&(null==e.description||u(e.description))&&u(e.mimeType)&&(null==e.baseId||u(e.baseId))&&(null==e.clusterId||u(e.clusterId))&&u(e.contentApiEndpoint)&&u(e.title)&&(null==e.lastPublication||u(e.lastPublication))&&u(e.viewerUrl)&&u(e.lastEdition)&&u(e.filename)&&(null==e.originId||u(e.originId))&&u(e.rightsApiEndpoint)&&(null==e.originUrl||u(e.originUrl))&&(null==e.khubVersion||u(e.khubVersion))&&u(e.id)&&(null==e.lang||u(e.lang)),e.isFtUserProfile=j,e.setUnauthenticatedUserSearchPreferences=function(e,t){if(K.localStorage){t=t??K.__gwt_ft_moduleBase??K.fluidtopicsclient?.__moduleBase??K.__gwt_activeModules?.fluidtopicsclient?.moduleBase;let r={...e,metadata:X(e.metadata??{})};const a=`${t}-FluidTopicsUnauthenticatedUserSearchPreferences`,i=JSON.stringify(r);return K.localStorage.setItem(a,i),K.dispatchEvent(new StorageEvent("storage",{key:a,newValue:i,storageArea:K.localStorage,url:K.location.href})),r}console.error("Cannot set unauthenticated preferences: local storage is unavailable.")}}));
@@ -1,6 +1,6 @@
1
1
  import "cross-fetch/polyfill";
2
- import { FtCollectionDocument, FtMap, FtMapResource, FtSearchLocales, FtSearchRequest, FtSearchResults, FtSuggestRequest, FtSuggestResults, FtTocNode, FtTopic, FtTopicContentTarget, FtUnstructuredDocument } from "./types/ft-common/public";
3
- import { FtAuthenticatedSession, FtMapAttachment } from "./types/ft-server/public";
2
+ import { FtCollectionDocument, FtMap, FtMapResource, FtMetadataPreferenceConfiguration, FtSearchLocales, FtSearchPreferencesConfiguration, FtSearchRequest, FtSearchResults, FtSuggestRequest, FtSuggestResults, FtTocNode, FtTopic, FtTopicContentTarget, FtUnstructuredDocument } from "./types/ft-common/public";
3
+ import { FtAuthenticatedSession, FtMapAttachment, FtSession } from "./types/ft-server/public";
4
4
  export * from "./types/ft-common/public";
5
5
  export * from "./types/ft-server/public";
6
6
  export declare class HttpError extends Error {
@@ -20,6 +20,7 @@ export declare class FluidTopicsApi {
20
20
  clearAuthentication(): void;
21
21
  login(login: string, password: string): Promise<FtAuthenticatedSession>;
22
22
  logout(): Promise<void>;
23
+ getCurrentSession(): Promise<FtSession>;
23
24
  getMap(mapId: string): Promise<FtMap>;
24
25
  getTableOfContent(mapId: string): Promise<Array<FtTocNode>>;
25
26
  getTopic(mapId: string, topicContentId: string): Promise<FtTopic>;
@@ -45,3 +46,7 @@ export declare class FluidTopicsApi {
45
46
  private fetchRawData;
46
47
  }
47
48
  export default FluidTopicsApi;
49
+ export declare function setUnauthenticatedUserSearchPreferences(input: FtSearchPreferencesConfiguration, tenantBaseUrl?: string): {
50
+ metadata: Record<string, FtMetadataPreferenceConfiguration>;
51
+ };
52
+ export declare function getUnauthenticatedUserSearchPreferences(tenantBaseUrl?: string): FtSearchPreferencesConfiguration;
package/dist/mjs/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import "cross-fetch/polyfill";
2
+ const wnd = (typeof window === "undefined" ? globalThis : window);
2
3
  export * from "./types/ft-common/public";
3
4
  export * from "./types/ft-server/public";
4
5
  function toBase64(s) {
@@ -36,7 +37,7 @@ export class FluidTopicsApi {
36
37
  }
37
38
  constructor(tenantBaseUrl, integrationIdentifier, overrideIdentifierIfOnTenant) {
38
39
  this.tenantBaseUrl = tenantBaseUrl.trim().replace(/\/$/, "");
39
- if (overrideIdentifierIfOnTenant && typeof window !== "undefined" && window.location.href.startsWith(tenantBaseUrl)) {
40
+ if (overrideIdentifierIfOnTenant && typeof wnd.location !== "undefined" && wnd.location.href.startsWith(this.tenantBaseUrl + "/")) {
40
41
  this.ftCallingApp = integrationIdentifier;
41
42
  }
42
43
  else {
@@ -68,6 +69,9 @@ export class FluidTopicsApi {
68
69
  return this.post(`/api/authentication/logout`)
69
70
  .then(() => this.clearAuthentication());
70
71
  }
72
+ getCurrentSession() {
73
+ return this.get(`/api/authentication/current-session`);
74
+ }
71
75
  getMap(mapId) {
72
76
  return this.get(`/api/khub/maps/${mapId}`);
73
77
  }
@@ -138,7 +142,7 @@ export class FluidTopicsApi {
138
142
  }
139
143
  });
140
144
  }
141
- async upload(method, endpoint, body, onProgress = () => { }) {
145
+ async upload(method, endpoint, body, onProgress = () => undefined) {
142
146
  return new Promise((resolve, reject) => {
143
147
  let xhr = new XMLHttpRequest();
144
148
  xhr.onload = () => {
@@ -173,3 +177,49 @@ export class FluidTopicsApi {
173
177
  }
174
178
  }
175
179
  export default FluidTopicsApi;
180
+ function normalizeMetadataPreferences(metadata) {
181
+ let normalized = {};
182
+ for (let key in metadata) {
183
+ let values = metadata[key];
184
+ if (typeof values !== "object" || Array.isArray(values)) {
185
+ values = { prior: values };
186
+ }
187
+ for (let property of ["prior", "filter"]) {
188
+ values[property] = Array.isArray(values[property]) ? values[property] : [values[property]];
189
+ values[property] = values[property]
190
+ .map(v => v != null ? "" + v : "")
191
+ .filter(v => v !== "");
192
+ }
193
+ normalized[key] = values;
194
+ }
195
+ return normalized;
196
+ }
197
+ export function setUnauthenticatedUserSearchPreferences(input, tenantBaseUrl) {
198
+ if (wnd.localStorage) {
199
+ //@ts-ignore
200
+ tenantBaseUrl = tenantBaseUrl ?? wnd.__gwt_ft_moduleBase ?? wnd.fluidtopicsclient?.__moduleBase ?? wnd.__gwt_activeModules?.fluidtopicsclient?.moduleBase;
201
+ let preferences = {
202
+ ...input,
203
+ metadata: normalizeMetadataPreferences(input.metadata ?? {})
204
+ };
205
+ const key = `${tenantBaseUrl}-FluidTopicsUnauthenticatedUserSearchPreferences`;
206
+ const newValue = JSON.stringify(preferences);
207
+ wnd.localStorage.setItem(key, newValue);
208
+ wnd.dispatchEvent(new StorageEvent("storage", {
209
+ key,
210
+ newValue,
211
+ storageArea: wnd.localStorage,
212
+ url: wnd.location.href
213
+ }));
214
+ return preferences;
215
+ }
216
+ console.error("Cannot set unauthenticated preferences: local storage is unavailable.");
217
+ }
218
+ export function getUnauthenticatedUserSearchPreferences(tenantBaseUrl) {
219
+ if (wnd.localStorage) {
220
+ //@ts-ignore
221
+ tenantBaseUrl = tenantBaseUrl ?? wnd.__gwt_ft_moduleBase ?? wnd.fluidtopicsclient?.__moduleBase ?? wnd.__gwt_activeModules?.fluidtopicsclient?.moduleBase;
222
+ return JSON.parse(wnd.localStorage.getItem(`${tenantBaseUrl}-FluidTopicsUnauthenticatedUserSearchPreferences`) ?? "{}");
223
+ }
224
+ console.error("Cannot get unauthenticated preferences: local storage is unavailable.");
225
+ }
@@ -100,6 +100,15 @@ export interface FtMapResource {
100
100
  mimeType: string;
101
101
  }
102
102
  export declare const isFtMapResource: (o: any) => o is FtMapResource;
103
+ export interface FtMetadataPreferenceConfiguration {
104
+ filter: Array<string>;
105
+ prior: Array<string>;
106
+ }
107
+ export declare const isFtMetadataPreferenceConfiguration: (o: any) => o is FtMetadataPreferenceConfiguration;
108
+ export interface FtSearchPreferencesConfiguration {
109
+ metadata: Record<string, FtMetadataPreferenceConfiguration>;
110
+ }
111
+ export declare const isFtSearchPreferencesConfiguration: (o: any) => o is FtSearchPreferencesConfiguration;
103
112
  export interface FtSearchFilter {
104
113
  negative: boolean;
105
114
  values: Array<string>;
@@ -149,6 +158,12 @@ export interface FtSearchResults {
149
158
  facets: Array<FtSearchFacet>;
150
159
  }
151
160
  export declare const isFtSearchResults: (o: any) => o is FtSearchResults;
161
+ export interface FtSearchPrior {
162
+ weight: number;
163
+ value: string;
164
+ key: string;
165
+ }
166
+ export declare const isFtSearchPrior: (o: any) => o is FtSearchPrior;
152
167
  export interface FtSearchRequest {
153
168
  query: string;
154
169
  paging: FtPageRequest;
@@ -156,6 +171,7 @@ export interface FtSearchRequest {
156
171
  sort: Array<FtSearchSortCriterion>;
157
172
  uiLocale?: string;
158
173
  contentLocale?: string;
174
+ priors?: Array<FtSearchPrior>;
159
175
  facets: Array<FtSearchFacetConf>;
160
176
  }
161
177
  export declare const isFtSearchRequest: (o: any) => o is FtSearchRequest;
@@ -191,7 +207,7 @@ export interface FtSearchResultUnstructuredDocument {
191
207
  export declare const isFtSearchResultUnstructuredDocument: (o: any) => o is FtSearchResultUnstructuredDocument;
192
208
  export interface FtSearchResultMap {
193
209
  metadata: Array<FtMetadata>;
194
- openMode: FtOpenMode;
210
+ openMode?: FtOpenMode;
195
211
  editorialType: FtEditorialType;
196
212
  source?: any;
197
213
  title: string;
@@ -279,6 +295,7 @@ export interface FtSuggestRequest {
279
295
  sort: Array<FtSearchSortCriterion>;
280
296
  maxCount?: number;
281
297
  contentLocale?: string;
298
+ priors?: Array<FtSearchPrior>;
282
299
  }
283
300
  export declare const isFtSuggestRequest: (o: any) => o is FtSuggestRequest;
284
301
  export interface FtSuggestResult {
@@ -114,6 +114,19 @@ export const isFtMapResource = (o) => {
114
114
  && (isString(o.id))
115
115
  && (isString(o.mimeType));
116
116
  };
117
+ export const isFtMetadataPreferenceConfiguration = (o) => {
118
+ return isObject(o)
119
+ && ((Array.isArray(o.filter)
120
+ && o.filter.every((v) => isString(v))))
121
+ && ((Array.isArray(o.prior)
122
+ && o.prior.every((v) => isString(v))));
123
+ };
124
+ export const isFtSearchPreferencesConfiguration = (o) => {
125
+ return isObject(o)
126
+ && ((isObject(o.metadata)
127
+ && Object.keys(o.metadata).every((k) => isString(k))
128
+ && Object.values(o.metadata).every((v) => isFtMetadataPreferenceConfiguration(v))));
129
+ };
117
130
  export const isFtSearchFilter = (o) => {
118
131
  return isObject(o)
119
132
  && (isBoolean(o.negative))
@@ -179,6 +192,12 @@ export const isFtSearchResults = (o) => {
179
192
  && ((Array.isArray(o.facets)
180
193
  && o.facets.every((v) => isFtSearchFacet(v))));
181
194
  };
195
+ export const isFtSearchPrior = (o) => {
196
+ return isObject(o)
197
+ && (isNumber(o.weight))
198
+ && (isString(o.value))
199
+ && (isString(o.key));
200
+ };
182
201
  export const isFtSearchRequest = (o) => {
183
202
  return isObject(o)
184
203
  && (isString(o.query))
@@ -189,6 +208,8 @@ export const isFtSearchRequest = (o) => {
189
208
  && o.sort.every((v) => isFtSearchSortCriterion(v))))
190
209
  && (o.uiLocale == null || isString(o.uiLocale))
191
210
  && (o.contentLocale == null || isString(o.contentLocale))
211
+ && (o.priors == null || (Array.isArray(o.priors)
212
+ && o.priors.every((v) => isFtSearchPrior(v))))
192
213
  && ((Array.isArray(o.facets)
193
214
  && o.facets.every((v) => isFtSearchFacetConf(v))));
194
215
  };
@@ -227,7 +248,7 @@ export const isFtSearchResultMap = (o) => {
227
248
  return isObject(o)
228
249
  && ((Array.isArray(o.metadata)
229
250
  && o.metadata.every((v) => isFtMetadata(v))))
230
- && (isFtOpenMode(o.openMode))
251
+ && (o.openMode == null || isFtOpenMode(o.openMode))
231
252
  && (isFtEditorialType(o.editorialType))
232
253
  && (isString(o.title))
233
254
  && (o.lastPublicationDate == null || isString(o.lastPublicationDate))
@@ -321,7 +342,9 @@ export const isFtSuggestRequest = (o) => {
321
342
  && ((Array.isArray(o.sort)
322
343
  && o.sort.every((v) => isFtSearchSortCriterion(v))))
323
344
  && (o.maxCount == null || isNumber(o.maxCount))
324
- && (o.contentLocale == null || isString(o.contentLocale));
345
+ && (o.contentLocale == null || isString(o.contentLocale))
346
+ && (o.priors == null || (Array.isArray(o.priors)
347
+ && o.priors.every((v) => isFtSearchPrior(v))));
325
348
  };
326
349
  export const isFtSuggestResult = (o) => {
327
350
  return isObject(o)
@@ -3,6 +3,13 @@ export interface FtAuthenticatedSession {
3
3
  profile: FtUserProfile;
4
4
  }
5
5
  export declare const isFtAuthenticatedSession: (o: any) => o is FtAuthenticatedSession;
6
+ export interface FtSession {
7
+ authenticationIdentifier?: any;
8
+ idleTimeoutInMillis: number;
9
+ profile?: FtUserProfile;
10
+ sessionAuthenticated: boolean;
11
+ }
12
+ export declare const isFtSession: (o: any) => o is FtSession;
6
13
  export interface FtUserProfile {
7
14
  emailAddress?: string;
8
15
  displayName?: string;
@@ -6,6 +6,12 @@ export const isFtAuthenticatedSession = (o) => {
6
6
  return isObject(o)
7
7
  && (isFtUserProfile(o.profile));
8
8
  };
9
+ export const isFtSession = (o) => {
10
+ return isObject(o)
11
+ && (isNumber(o.idleTimeoutInMillis))
12
+ && (o.profile == null || isFtUserProfile(o.profile))
13
+ && (isBoolean(o.sessionAuthenticated));
14
+ };
9
15
  export const isFtUserProfile = (o) => {
10
16
  return isObject(o)
11
17
  && (o.emailAddress == null || isString(o.emailAddress))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/public-api",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "Fluid Topics Public API",
5
5
  "author": "Fluid Topics dev team <opensource@antidot.net>",
6
6
  "license": "LGPLv3",