@fluid-topics/public-api 1.0.15 → 1.0.18

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
  }
@@ -50,7 +52,7 @@ class FluidTopicsApi {
50
52
  constructor(tenantBaseUrl, integrationIdentifier, overrideIdentifierIfOnTenant) {
51
53
  this.authorization = {};
52
54
  this.tenantBaseUrl = tenantBaseUrl.trim().replace(/\/$/, "");
53
- if (overrideIdentifierIfOnTenant && typeof window !== "undefined" && window.location.href.startsWith(tenantBaseUrl)) {
55
+ if (overrideIdentifierIfOnTenant && typeof wnd.location !== "undefined" && wnd.location.href.startsWith(this.tenantBaseUrl + "/")) {
54
56
  this.ftCallingApp = integrationIdentifier;
55
57
  }
56
58
  else {
@@ -85,6 +87,9 @@ class FluidTopicsApi {
85
87
  return this.post(`/api/authentication/logout`)
86
88
  .then(() => this.clearAuthentication());
87
89
  }
90
+ getCurrentSession() {
91
+ return this.get(`/api/authentication/current-session`);
92
+ }
88
93
  getMap(mapId) {
89
94
  return this.get(`/api/khub/maps/${mapId}`);
90
95
  }
@@ -152,6 +157,25 @@ class FluidTopicsApi {
152
157
  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
158
  });
154
159
  }
160
+ upload(method, endpoint, body, onProgress = () => undefined) {
161
+ return __awaiter(this, void 0, void 0, function* () {
162
+ return new Promise((resolve, reject) => {
163
+ let xhr = new XMLHttpRequest();
164
+ xhr.onload = () => {
165
+ if (xhr.status >= 200 && xhr.status < 300) {
166
+ let data = xhr.getResponseHeader("Content-Type") === "application/json" ? JSON.parse(xhr.responseText) : xhr.responseText;
167
+ resolve(data);
168
+ }
169
+ else {
170
+ reject(new HttpError(xhr.status, xhr.statusText, xhr.responseText));
171
+ }
172
+ };
173
+ xhr.upload.onprogress = (e) => onProgress(e);
174
+ xhr.open(method, this.tenantBaseUrl + endpoint, true);
175
+ xhr.send(body);
176
+ });
177
+ });
178
+ }
155
179
  makeRequest(method, endpoint, data) {
156
180
  return this.fetch(endpoint, {
157
181
  method: method,
@@ -0,0 +1,70 @@
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
+ var _a, _b, _c, _d, _e;
24
+ //@ts-ignore
25
+ 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;
26
+ return `${tenantBaseUrl}-FluidTopicsUnauthenticatedUserSearchPreferences`;
27
+ }
28
+ function setUnauthenticatedUserSearchPreferences(input, tenantBaseUrl) {
29
+ var _a;
30
+ if (wnd.localStorage) {
31
+ let preferences = Object.assign(Object.assign({}, input), { metadata: normalizeMetadataPreferences((_a = input.metadata) !== null && _a !== void 0 ? _a : {}) });
32
+ const key = getStorageKey(tenantBaseUrl);
33
+ const newValue = JSON.stringify(preferences);
34
+ wnd.localStorage.setItem(key, newValue);
35
+ wnd.dispatchEvent(new StorageEvent("storage", {
36
+ key,
37
+ newValue,
38
+ storageArea: wnd.localStorage,
39
+ url: wnd.location.href
40
+ }));
41
+ return preferences;
42
+ }
43
+ console.error("Cannot set unauthenticated preferences: local storage is unavailable.");
44
+ }
45
+ exports.setUnauthenticatedUserSearchPreferences = setUnauthenticatedUserSearchPreferences;
46
+ function getUnauthenticatedUserSearchPreferences(tenantBaseUrl) {
47
+ var _a;
48
+ if (wnd.localStorage) {
49
+ return JSON.parse((_a = wnd.localStorage.getItem(getStorageKey(tenantBaseUrl))) !== null && _a !== void 0 ? _a : "{}");
50
+ }
51
+ console.error("Cannot get unauthenticated preferences: local storage is unavailable.");
52
+ }
53
+ exports.getUnauthenticatedUserSearchPreferences = getUnauthenticatedUserSearchPreferences;
54
+ function addUnauthenticatedUserSearchPreferencesChangeHandler(handler, tenantBaseUrl) {
55
+ if (wnd.localStorage) {
56
+ const key = getStorageKey(tenantBaseUrl);
57
+ const eventListener = (event) => {
58
+ var _a;
59
+ if (event.storageArea === wnd.localStorage && event.key === key) {
60
+ handler(JSON.parse((_a = event.newValue) !== null && _a !== void 0 ? _a : "{}"));
61
+ }
62
+ };
63
+ wnd.addEventListener("storage", eventListener);
64
+ return {
65
+ removeHandler: () => wnd.removeEventListener("storage", eventListener)
66
+ };
67
+ }
68
+ console.error("Cannot handle unauthenticated preferences: local storage is unavailable.");
69
+ }
70
+ 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))
@@ -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=>x(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),I=e=>s(e)&&l(e.hierarchical)&&u(e.label)&&l(e.multiSelectionable)&&u(e.key)&&Array.isArray(e.rootNodes)&&e.rootNodes.every((e=>M(e))),P=e=>s(e)&&(null==e.maxDepth||o(e.maxDepth))&&u(e.id),M=e=>s(e)&&o(e.totalResultsCount)&&l(e.descendantSelected)&&Array.isArray(e.childNodes)&&e.childNodes.every((e=>M(e)))&&u(e.label)&&u(e.value)&&l(e.selected),w=e=>s(e)&&u(e.key),k=e=>s(e)&&u(e.suggestedQuery)&&u(e.htmlSuggestedQuery),x=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??{}}})}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=I,e.isFtSearchFacetConf=P,e.isFtSearchFacetEntry=M,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=>w(e)))&&(null==e.uiLocale||u(e.uiLocale))&&(null==e.contentLocale||u(e.contentLocale))&&Array.isArray(e.facets)&&e.facets.every((e=>P(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||k(e.spellcheck))&&f(e.paging)&&Array.isArray(e.results)&&e.results.every((e=>C(e)))&&Array.isArray(e.facets)&&e.facets.every((e=>I(e))),e.isFtSearchResultsPageInfo=f,e.isFtSearchSortCriterion=w,e.isFtSpellcheck=k,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=>w(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=x,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 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)&&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=e??K.__gwt_ft_moduleBase??K.fluidtopicsclient?.__moduleBase??K.__gwt_activeModules?.fluidtopicsclient?.moduleBase}-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){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(t),a=t=>{t.storageArea===K.localStorage&&t.key===r&&e(JSON.parse(t.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=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)&&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))&&(null==e.priors||Array.isArray(e.priors)&&e.priors.every((e=>U(e)))),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={...e,metadata:z(e.metadata??{})};const a=V(t),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>;
@@ -40,6 +42,7 @@ export declare class FluidTopicsApi {
40
42
  put<T>(endpoint: string, data?: any): Promise<T>;
41
43
  delete<T>(endpoint: string): Promise<T>;
42
44
  fetch<FetchRequestInit, FetchResponse>(endpoint: string, init?: FetchRequestInit): Promise<FetchResponse>;
45
+ upload<T>(method: string, endpoint: string, body: Document | XMLHttpRequestBodyInit, onProgress?: (e: ProgressEvent) => void): Promise<T>;
43
46
  private makeRequest;
44
47
  private fetchRawData;
45
48
  }
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
  }
@@ -36,7 +38,7 @@ export class FluidTopicsApi {
36
38
  }
37
39
  constructor(tenantBaseUrl, integrationIdentifier, overrideIdentifierIfOnTenant) {
38
40
  this.tenantBaseUrl = tenantBaseUrl.trim().replace(/\/$/, "");
39
- if (overrideIdentifierIfOnTenant && typeof window !== "undefined" && window.location.href.startsWith(tenantBaseUrl)) {
41
+ if (overrideIdentifierIfOnTenant && typeof wnd.location !== "undefined" && wnd.location.href.startsWith(this.tenantBaseUrl + "/")) {
40
42
  this.ftCallingApp = integrationIdentifier;
41
43
  }
42
44
  else {
@@ -68,6 +70,9 @@ export class FluidTopicsApi {
68
70
  return this.post(`/api/authentication/logout`)
69
71
  .then(() => this.clearAuthentication());
70
72
  }
73
+ getCurrentSession() {
74
+ return this.get(`/api/authentication/current-session`);
75
+ }
71
76
  getMap(mapId) {
72
77
  return this.get(`/api/khub/maps/${mapId}`);
73
78
  }
@@ -138,6 +143,23 @@ export class FluidTopicsApi {
138
143
  }
139
144
  });
140
145
  }
146
+ async upload(method, endpoint, body, onProgress = () => undefined) {
147
+ return new Promise((resolve, reject) => {
148
+ let xhr = new XMLHttpRequest();
149
+ xhr.onload = () => {
150
+ if (xhr.status >= 200 && xhr.status < 300) {
151
+ let data = xhr.getResponseHeader("Content-Type") === "application/json" ? JSON.parse(xhr.responseText) : xhr.responseText;
152
+ resolve(data);
153
+ }
154
+ else {
155
+ reject(new HttpError(xhr.status, xhr.statusText, xhr.responseText));
156
+ }
157
+ };
158
+ xhr.upload.onprogress = (e) => onProgress(e);
159
+ xhr.open(method, this.tenantBaseUrl + endpoint, true);
160
+ xhr.send(body);
161
+ });
162
+ }
141
163
  makeRequest(method, endpoint, data) {
142
164
  return this.fetch(endpoint, {
143
165
  method: method,
@@ -0,0 +1,9 @@
1
+ import { FtMetadataPreferenceConfiguration, FtSearchPreferencesConfiguration } from "../types/ft-common/public";
2
+ export declare function setUnauthenticatedUserSearchPreferences(input: FtSearchPreferencesConfiguration, tenantBaseUrl?: string): {
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(handler: (newValue: FtSearchPreferencesConfiguration) => void, tenantBaseUrl?: string): HandlerRegistration;
@@ -0,0 +1,63 @@
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
+ //@ts-ignore
21
+ tenantBaseUrl = tenantBaseUrl ?? wnd.__gwt_ft_moduleBase ?? wnd.fluidtopicsclient?.__moduleBase ?? wnd.__gwt_activeModules?.fluidtopicsclient?.moduleBase;
22
+ return `${tenantBaseUrl}-FluidTopicsUnauthenticatedUserSearchPreferences`;
23
+ }
24
+ export function setUnauthenticatedUserSearchPreferences(input, tenantBaseUrl) {
25
+ if (wnd.localStorage) {
26
+ let preferences = {
27
+ ...input,
28
+ metadata: normalizeMetadataPreferences(input.metadata ?? {})
29
+ };
30
+ const key = getStorageKey(tenantBaseUrl);
31
+ const newValue = JSON.stringify(preferences);
32
+ wnd.localStorage.setItem(key, newValue);
33
+ wnd.dispatchEvent(new StorageEvent("storage", {
34
+ key,
35
+ newValue,
36
+ storageArea: wnd.localStorage,
37
+ url: wnd.location.href
38
+ }));
39
+ return preferences;
40
+ }
41
+ console.error("Cannot set unauthenticated preferences: local storage is unavailable.");
42
+ }
43
+ export function getUnauthenticatedUserSearchPreferences(tenantBaseUrl) {
44
+ if (wnd.localStorage) {
45
+ return JSON.parse(wnd.localStorage.getItem(getStorageKey(tenantBaseUrl)) ?? "{}");
46
+ }
47
+ console.error("Cannot get unauthenticated preferences: local storage is unavailable.");
48
+ }
49
+ export function addUnauthenticatedUserSearchPreferencesChangeHandler(handler, tenantBaseUrl) {
50
+ if (wnd.localStorage) {
51
+ const key = getStorageKey(tenantBaseUrl);
52
+ const eventListener = (event) => {
53
+ if (event.storageArea === wnd.localStorage && event.key === key) {
54
+ handler(JSON.parse(event.newValue ?? "{}"));
55
+ }
56
+ };
57
+ wnd.addEventListener("storage", eventListener);
58
+ return {
59
+ removeHandler: () => wnd.removeEventListener("storage", eventListener)
60
+ };
61
+ }
62
+ console.error("Cannot handle unauthenticated preferences: local storage is unavailable.");
63
+ }
@@ -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.15",
3
+ "version": "1.0.18",
4
4
  "description": "Fluid Topics Public API",
5
5
  "author": "Fluid Topics dev team <opensource@antidot.net>",
6
6
  "license": "LGPLv3",