@fluid-topics/public-api 1.0.14 → 1.0.17

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