@fluid-topics/public-api 1.0.16 → 1.0.19

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
@@ -21,8 +21,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
22
  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);
27
+ __exportStar(require("./preferences/unauthenticated-preferences"), exports);
26
28
  function toBase64(s) {
27
29
  return typeof Buffer !== "undefined" ? Buffer.from(s).toString("base64") : btoa(s);
28
30
  }
@@ -48,9 +50,12 @@ function getBody(response) {
48
50
  }
49
51
  class FluidTopicsApi {
50
52
  constructor(tenantBaseUrl, integrationIdentifier, overrideIdentifierIfOnTenant) {
53
+ var _a, _b, _c, _d, _e;
51
54
  this.authorization = {};
55
+ //@ts-ignore
56
+ 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;
52
57
  this.tenantBaseUrl = tenantBaseUrl.trim().replace(/\/$/, "");
53
- if (overrideIdentifierIfOnTenant && typeof window !== "undefined" && window.location.href.startsWith(tenantBaseUrl)) {
58
+ if (overrideIdentifierIfOnTenant && typeof wnd.location !== "undefined" && wnd.location.href.startsWith(this.tenantBaseUrl + "/")) {
54
59
  this.ftCallingApp = integrationIdentifier;
55
60
  }
56
61
  else {
@@ -85,6 +90,9 @@ class FluidTopicsApi {
85
90
  return this.post(`/api/authentication/logout`)
86
91
  .then(() => this.clearAuthentication());
87
92
  }
93
+ getCurrentSession() {
94
+ return this.get(`/api/authentication/current-session`);
95
+ }
88
96
  getMap(mapId) {
89
97
  return this.get(`/api/khub/maps/${mapId}`);
90
98
  }
@@ -152,7 +160,7 @@ class FluidTopicsApi {
152
160
  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
161
  });
154
162
  }
155
- upload(method, endpoint, body, onProgress = () => { }) {
163
+ upload(method, endpoint, body, onProgress = () => undefined) {
156
164
  return __awaiter(this, void 0, void 0, function* () {
157
165
  return new Promise((resolve, reject) => {
158
166
  let xhr = new XMLHttpRequest();
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addUnauthenticatedUserSearchPreferencesChangeHandler = exports.getUnauthenticatedUserSearchPreferences = exports.setUnauthenticatedUserSearchPreferences = void 0;
4
+ const wnd = (typeof window === "undefined" ? globalThis : window);
5
+ function normalizeMetadataPreferences(metadata) {
6
+ let normalized = {};
7
+ for (let key in metadata) {
8
+ let values = metadata[key];
9
+ if (typeof values !== "object" || Array.isArray(values)) {
10
+ values = { prior: values };
11
+ }
12
+ for (let property of ["prior", "filter"]) {
13
+ values[property] = Array.isArray(values[property]) ? values[property] : [values[property]];
14
+ values[property] = values[property]
15
+ .map(v => v != null ? "" + v : "")
16
+ .filter(v => v !== "");
17
+ }
18
+ normalized[key] = values;
19
+ }
20
+ return normalized;
21
+ }
22
+ function getStorageKey(tenantBaseUrl) {
23
+ return `${tenantBaseUrl}-FluidTopicsUnauthenticatedUserSearchPreferences`;
24
+ }
25
+ function setUnauthenticatedUserSearchPreferences(tenantBaseUrl, input) {
26
+ var _a;
27
+ if (wnd.localStorage) {
28
+ let preferences = Object.assign(Object.assign({}, input), { metadata: normalizeMetadataPreferences((_a = input.metadata) !== null && _a !== void 0 ? _a : {}) });
29
+ const key = getStorageKey(tenantBaseUrl);
30
+ const newValue = JSON.stringify(preferences);
31
+ wnd.localStorage.setItem(key, newValue);
32
+ wnd.dispatchEvent(new StorageEvent("storage", {
33
+ key,
34
+ newValue,
35
+ storageArea: wnd.localStorage,
36
+ url: wnd.location.href
37
+ }));
38
+ return preferences;
39
+ }
40
+ console.error("Cannot set unauthenticated preferences: local storage is unavailable.");
41
+ }
42
+ exports.setUnauthenticatedUserSearchPreferences = setUnauthenticatedUserSearchPreferences;
43
+ function getUnauthenticatedUserSearchPreferences(tenantBaseUrl) {
44
+ var _a;
45
+ if (wnd.localStorage) {
46
+ return JSON.parse((_a = wnd.localStorage.getItem(getStorageKey(tenantBaseUrl))) !== null && _a !== void 0 ? _a : "{}");
47
+ }
48
+ console.error("Cannot get unauthenticated preferences: local storage is unavailable.");
49
+ }
50
+ exports.getUnauthenticatedUserSearchPreferences = getUnauthenticatedUserSearchPreferences;
51
+ function addUnauthenticatedUserSearchPreferencesChangeHandler(tenantBaseUrl, handler) {
52
+ if (wnd.localStorage) {
53
+ const key = getStorageKey(tenantBaseUrl);
54
+ const eventListener = (event) => {
55
+ var _a;
56
+ if (event.storageArea === wnd.localStorage && event.key === key) {
57
+ handler(JSON.parse((_a = event.newValue) !== null && _a !== void 0 ? _a : "{}"));
58
+ }
59
+ };
60
+ wnd.addEventListener("storage", eventListener);
61
+ return {
62
+ removeHandler: () => wnd.removeEventListener("storage", eventListener)
63
+ };
64
+ }
65
+ console.error("Cannot handle unauthenticated preferences: local storage is unavailable.");
66
+ }
67
+ exports.addUnauthenticatedUserSearchPreferencesChangeHandler = addUnauthenticatedUserSearchPreferencesChangeHandler;
@@ -1,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))
@@ -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,n=r.default||r,i=function(e,t){return/^\/\//.test(e)&&(e="https:"+e),n.call(this,e,t)};i.ponyfill=!0,e.exports=t=i,t.fetch=i,t.Headers=r.Headers,t.Request=r.Request,t.Response=r.Response,t.default=i}(r,r.exports);const n=r.exports,i=n.fetch.bind({});i.polyfill=!0,t.fetch||(t.fetch=i,t.Response=n.Response,t.Headers=n.Headers,t.Request=n.Request);const s=e=>"object"==typeof e&&null!=e,o=e=>"boolean"==typeof e,l=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 d;e.FtTopicContentTarget=void 0,(d=e.FtTopicContentTarget||(e.FtTopicContentTarget={})).THIRD_PARTY="THIRD_PARTY",d.OFF_THE_GRID="OFF_THE_GRID";const p=e=>s(e)&&l(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)&&o(e.negative)&&Array.isArray(e.values)&&e.values.every((e=>u(e)))&&u(e.key),g=e=>s(e)&&l(e.totalResultsCount)&&o(e.lastPage)&&l(e.currentPage)&&l(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 b=e=>["FLUIDTOPICS","EXTERNAL"].includes(e),F=e=>s(e)&&(null==e.perPage||l(e.perPage))&&l(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)&&l(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))&&D(e.type)&&(null==e.map||O(e.map)),E=e=>s(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>h(e)))&&b(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||b(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)))&&b(e.openMode)&&u(e.contentId)&&Array.isArray(e.resources)&&e.resources.every((e=>$(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 w;e.FtSearchResultType=void 0,(w=e.FtSearchResultType||(e.FtSearchResultType={})).MAP="MAP",w.DOCUMENT="DOCUMENT",w.TOPIC="TOPIC";const D=e=>["MAP","DOCUMENT","TOPIC"].includes(e),I=e=>s(e)&&o(e.hierarchical)&&u(e.label)&&o(e.multiSelectionable)&&u(e.key)&&Array.isArray(e.rootNodes)&&e.rootNodes.every((e=>k(e))),M=e=>s(e)&&(null==e.maxDepth||l(e.maxDepth))&&u(e.id),k=e=>s(e)&&l(e.totalResultsCount)&&o(e.descendantSelected)&&Array.isArray(e.childNodes)&&e.childNodes.every((e=>k(e)))&&u(e.label)&&u(e.value)&&o(e.selected),x=e=>s(e)&&u(e.key),L=e=>s(e)&&u(e.suggestedQuery)&&u(e.htmlSuggestedQuery),$=e=>s(e)&&u(e.filename)&&u(e.resourceUrl)&&u(e.id)&&u(e.mimeType)&&u(e.resourceContentUrl)&&u(e.viewerUrl),H=e=>s(e)&&(null==e.filenameExtension||u(e.filenameExtension))&&(null==e.editorialType||A(e.editorialType))&&(null==e.mimeType||u(e.mimeType))&&D(e.type)&&u(e.value),N=e=>"object"==typeof e&&null!=e,_=e=>"boolean"==typeof e,B=e=>"number"==typeof e,q=e=>"string"==typeof e,j=e=>N(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;function z(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}function V(e){return`${e}-FluidTopicsUnauthenticatedUserSearchPreferences`}const J="undefined"==typeof window?globalThis:window;class G extends Error{status;statusText;body;constructor(e,t,r){super(`${e} - ${t}: ${r}`),this.status=e,this.statusText=t,this.body=r}}async function X(e){if(!e.ok)throw new G(e.status,e.statusText,await e.text());return e}function Y(e){return"application/json"===e.headers.get("Content-Type")?e.json():e.text()}class Q{tenantBaseUrl;ftCallingApp;authorization={};get defaultHeaders(){return{...this.authorization,"Ft-Calling-App":this.ftCallingApp}}constructor(e,t,r){e=e??J.__gwt_ft_moduleBase??J.fluidtopicsclient?.__moduleBase??J.__gwt_activeModules?.fluidtopicsclient?.moduleBase,this.tenantBaseUrl=e.trim().replace(/\/$/,""),r&&void 0!==J.location&&J.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(((n,i)=>{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;n(e)}else i(new G(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(X).then(Y)}fetchRawData(e){return fetch(this.tenantBaseUrl+e,{headers:this.defaultHeaders}).then(X).then((e=>e.arrayBuffer()))}}e.FluidTopicsApi=Q,e.HttpError=G,e.addUnauthenticatedUserSearchPreferencesChangeHandler=function(e,t){if(K.localStorage){const r=V(e),a=e=>{e.storageArea===K.localStorage&&e.key===r&&t(JSON.parse(e.newValue??"{}"))};return K.addEventListener("storage",a),{removeHandler:()=>K.removeEventListener("storage",a)}}console.error("Cannot handle unauthenticated preferences: local storage is unavailable.")},e.default=Q,e.getUnauthenticatedUserSearchPreferences=function(e){if(K.localStorage)return JSON.parse(K.localStorage.getItem(V(e))??"{}");console.error("Cannot get unauthenticated preferences: local storage is unavailable.")},e.isFtAuthenticatedSession=e=>N(e)&&j(e.profile),e.isFtAuthenticationIdentifier=e=>s(e)&&u(e.identifier)&&u(e.realm),e.isFtCollectionDocument=e=>s(e)&&o(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))&&o(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)))&&b(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=>N(e)&&q(e.file)&&(null==e.size||B(e.size))&&_(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=b,e.isFtPageRequest=F,e.isFtSearchFacet=I,e.isFtSearchFacetConf=M,e.isFtSearchFacetEntry=k,e.isFtSearchFilter=f,e.isFtSearchLocale=p,e.isFtSearchLocales=e=>s(e)&&Array.isArray(e.contentLocales)&&e.contentLocales.every((e=>p(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)&&F(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=D,e.isFtSearchResultUnstructuredDocument=E,e.isFtSearchResults=e=>s(e)&&(null==e.spellcheck||L(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=>N(e)&&B(e.idleTimeoutInMillis)&&(null==e.profile||j(e.profile))&&_(e.sessionAuthenticated),e.isFtSpellcheck=L,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||l(e.maxCount))&&(null==e.contentLocale||u(e.contentLocale)),e.isFtSuggestResult=H,e.isFtSuggestResults=e=>s(e)&&Array.isArray(e.suggestions)&&e.suggestions.every((e=>H(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=$,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){let r={...t,metadata:z(t.metadata??{})};const a=V(e),n=JSON.stringify(r);return K.localStorage.setItem(a,n),K.dispatchEvent(new StorageEvent("storage",{key:a,newValue:n,storageArea:K.localStorage,url:K.location.href})),r}console.error("Cannot set unauthenticated preferences: local storage is unavailable.")}}));
@@ -1,8 +1,9 @@
1
1
  import "cross-fetch/polyfill";
2
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";
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
+ export * from "./preferences/unauthenticated-preferences";
6
7
  export declare class HttpError extends Error {
7
8
  readonly status: number;
8
9
  readonly statusText: string;
@@ -20,6 +21,7 @@ export declare class FluidTopicsApi {
20
21
  clearAuthentication(): void;
21
22
  login(login: string, password: string): Promise<FtAuthenticatedSession>;
22
23
  logout(): Promise<void>;
24
+ getCurrentSession(): Promise<FtSession>;
23
25
  getMap(mapId: string): Promise<FtMap>;
24
26
  getTableOfContent(mapId: string): Promise<Array<FtTocNode>>;
25
27
  getTopic(mapId: string, topicContentId: string): Promise<FtTopic>;
package/dist/mjs/index.js CHANGED
@@ -1,6 +1,8 @@
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";
5
+ export * from "./preferences/unauthenticated-preferences";
4
6
  function toBase64(s) {
5
7
  return typeof Buffer !== "undefined" ? Buffer.from(s).toString("base64") : btoa(s);
6
8
  }
@@ -35,8 +37,10 @@ export class FluidTopicsApi {
35
37
  };
36
38
  }
37
39
  constructor(tenantBaseUrl, integrationIdentifier, overrideIdentifierIfOnTenant) {
40
+ //@ts-ignore
41
+ tenantBaseUrl = tenantBaseUrl ?? wnd.__gwt_ft_moduleBase ?? wnd.fluidtopicsclient?.__moduleBase ?? wnd.__gwt_activeModules?.fluidtopicsclient?.moduleBase;
38
42
  this.tenantBaseUrl = tenantBaseUrl.trim().replace(/\/$/, "");
39
- if (overrideIdentifierIfOnTenant && typeof window !== "undefined" && window.location.href.startsWith(tenantBaseUrl)) {
43
+ if (overrideIdentifierIfOnTenant && typeof wnd.location !== "undefined" && wnd.location.href.startsWith(this.tenantBaseUrl + "/")) {
40
44
  this.ftCallingApp = integrationIdentifier;
41
45
  }
42
46
  else {
@@ -68,6 +72,9 @@ export class FluidTopicsApi {
68
72
  return this.post(`/api/authentication/logout`)
69
73
  .then(() => this.clearAuthentication());
70
74
  }
75
+ getCurrentSession() {
76
+ return this.get(`/api/authentication/current-session`);
77
+ }
71
78
  getMap(mapId) {
72
79
  return this.get(`/api/khub/maps/${mapId}`);
73
80
  }
@@ -138,7 +145,7 @@ export class FluidTopicsApi {
138
145
  }
139
146
  });
140
147
  }
141
- async upload(method, endpoint, body, onProgress = () => { }) {
148
+ async upload(method, endpoint, body, onProgress = () => undefined) {
142
149
  return new Promise((resolve, reject) => {
143
150
  let xhr = new XMLHttpRequest();
144
151
  xhr.onload = () => {
@@ -0,0 +1,9 @@
1
+ import { FtMetadataPreferenceConfiguration, FtSearchPreferencesConfiguration } from "../types/ft-common/public";
2
+ export declare function setUnauthenticatedUserSearchPreferences(tenantBaseUrl: string, input: FtSearchPreferencesConfiguration): {
3
+ metadata: Record<string, FtMetadataPreferenceConfiguration>;
4
+ };
5
+ export declare function getUnauthenticatedUserSearchPreferences(tenantBaseUrl: string): FtSearchPreferencesConfiguration;
6
+ export declare type HandlerRegistration = {
7
+ removeHandler: () => void;
8
+ };
9
+ export declare function addUnauthenticatedUserSearchPreferencesChangeHandler(tenantBaseUrl: string, handler: (newValue: FtSearchPreferencesConfiguration) => void): HandlerRegistration;
@@ -0,0 +1,61 @@
1
+ const wnd = (typeof window === "undefined" ? globalThis : window);
2
+ function normalizeMetadataPreferences(metadata) {
3
+ let normalized = {};
4
+ for (let key in metadata) {
5
+ let values = metadata[key];
6
+ if (typeof values !== "object" || Array.isArray(values)) {
7
+ values = { prior: values };
8
+ }
9
+ for (let property of ["prior", "filter"]) {
10
+ values[property] = Array.isArray(values[property]) ? values[property] : [values[property]];
11
+ values[property] = values[property]
12
+ .map(v => v != null ? "" + v : "")
13
+ .filter(v => v !== "");
14
+ }
15
+ normalized[key] = values;
16
+ }
17
+ return normalized;
18
+ }
19
+ function getStorageKey(tenantBaseUrl) {
20
+ return `${tenantBaseUrl}-FluidTopicsUnauthenticatedUserSearchPreferences`;
21
+ }
22
+ export function setUnauthenticatedUserSearchPreferences(tenantBaseUrl, input) {
23
+ if (wnd.localStorage) {
24
+ let preferences = {
25
+ ...input,
26
+ metadata: normalizeMetadataPreferences(input.metadata ?? {})
27
+ };
28
+ const key = getStorageKey(tenantBaseUrl);
29
+ const newValue = JSON.stringify(preferences);
30
+ wnd.localStorage.setItem(key, newValue);
31
+ wnd.dispatchEvent(new StorageEvent("storage", {
32
+ key,
33
+ newValue,
34
+ storageArea: wnd.localStorage,
35
+ url: wnd.location.href
36
+ }));
37
+ return preferences;
38
+ }
39
+ console.error("Cannot set unauthenticated preferences: local storage is unavailable.");
40
+ }
41
+ export function getUnauthenticatedUserSearchPreferences(tenantBaseUrl) {
42
+ if (wnd.localStorage) {
43
+ return JSON.parse(wnd.localStorage.getItem(getStorageKey(tenantBaseUrl)) ?? "{}");
44
+ }
45
+ console.error("Cannot get unauthenticated preferences: local storage is unavailable.");
46
+ }
47
+ export function addUnauthenticatedUserSearchPreferencesChangeHandler(tenantBaseUrl, handler) {
48
+ if (wnd.localStorage) {
49
+ const key = getStorageKey(tenantBaseUrl);
50
+ const eventListener = (event) => {
51
+ if (event.storageArea === wnd.localStorage && event.key === key) {
52
+ handler(JSON.parse(event.newValue ?? "{}"));
53
+ }
54
+ };
55
+ wnd.addEventListener("storage", eventListener);
56
+ return {
57
+ removeHandler: () => wnd.removeEventListener("storage", eventListener)
58
+ };
59
+ }
60
+ console.error("Cannot handle unauthenticated preferences: local storage is unavailable.");
61
+ }
@@ -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;
@@ -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))
@@ -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.19",
4
4
  "description": "Fluid Topics Public API",
5
5
  "author": "Fluid Topics dev team <opensource@antidot.net>",
6
6
  "license": "LGPLv3",