@fluid-topics/public-api 1.0.18 → 1.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/preferences/unauthenticated-preferences.js +2 -5
- package/dist/cjs/types/ft-common/public.js +1 -3
- package/dist/fluidtopics.min.js +1 -1
- package/dist/mjs/index.js +2 -0
- package/dist/mjs/preferences/unauthenticated-preferences.d.ts +3 -3
- package/dist/mjs/preferences/unauthenticated-preferences.js +2 -4
- package/dist/mjs/types/ft-common/public.d.ts +0 -1
- package/dist/mjs/types/ft-common/public.js +1 -3
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -50,7 +50,10 @@ function getBody(response) {
|
|
|
50
50
|
}
|
|
51
51
|
class FluidTopicsApi {
|
|
52
52
|
constructor(tenantBaseUrl, integrationIdentifier, overrideIdentifierIfOnTenant) {
|
|
53
|
+
var _a, _b, _c, _d, _e;
|
|
53
54
|
this.authorization = {};
|
|
55
|
+
//@ts-ignore
|
|
56
|
+
tenantBaseUrl = (_c = (_a = tenantBaseUrl !== null && tenantBaseUrl !== void 0 ? tenantBaseUrl : wnd.__gwt_ft_moduleBase) !== null && _a !== void 0 ? _a : (_b = wnd.fluidtopicsclient) === null || _b === void 0 ? void 0 : _b.__moduleBase) !== null && _c !== void 0 ? _c : (_e = (_d = wnd.__gwt_activeModules) === null || _d === void 0 ? void 0 : _d.fluidtopicsclient) === null || _e === void 0 ? void 0 : _e.moduleBase;
|
|
54
57
|
this.tenantBaseUrl = tenantBaseUrl.trim().replace(/\/$/, "");
|
|
55
58
|
if (overrideIdentifierIfOnTenant && typeof wnd.location !== "undefined" && wnd.location.href.startsWith(this.tenantBaseUrl + "/")) {
|
|
56
59
|
this.ftCallingApp = integrationIdentifier;
|
|
@@ -20,12 +20,9 @@ function normalizeMetadataPreferences(metadata) {
|
|
|
20
20
|
return normalized;
|
|
21
21
|
}
|
|
22
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
23
|
return `${tenantBaseUrl}-FluidTopicsUnauthenticatedUserSearchPreferences`;
|
|
27
24
|
}
|
|
28
|
-
function setUnauthenticatedUserSearchPreferences(
|
|
25
|
+
function setUnauthenticatedUserSearchPreferences(tenantBaseUrl, input) {
|
|
29
26
|
var _a;
|
|
30
27
|
if (wnd.localStorage) {
|
|
31
28
|
let preferences = Object.assign(Object.assign({}, input), { metadata: normalizeMetadataPreferences((_a = input.metadata) !== null && _a !== void 0 ? _a : {}) });
|
|
@@ -51,7 +48,7 @@ function getUnauthenticatedUserSearchPreferences(tenantBaseUrl) {
|
|
|
51
48
|
console.error("Cannot get unauthenticated preferences: local storage is unavailable.");
|
|
52
49
|
}
|
|
53
50
|
exports.getUnauthenticatedUserSearchPreferences = getUnauthenticatedUserSearchPreferences;
|
|
54
|
-
function addUnauthenticatedUserSearchPreferencesChangeHandler(
|
|
51
|
+
function addUnauthenticatedUserSearchPreferencesChangeHandler(tenantBaseUrl, handler) {
|
|
55
52
|
if (wnd.localStorage) {
|
|
56
53
|
const key = getStorageKey(tenantBaseUrl);
|
|
57
54
|
const eventListener = (event) => {
|
|
@@ -380,9 +380,7 @@ const isFtSuggestRequest = (o) => {
|
|
|
380
380
|
&& ((Array.isArray(o.sort)
|
|
381
381
|
&& o.sort.every((v) => (0, exports.isFtSearchSortCriterion)(v))))
|
|
382
382
|
&& (o.maxCount == null || isNumber(o.maxCount))
|
|
383
|
-
&& (o.contentLocale == null || isString(o.contentLocale))
|
|
384
|
-
&& (o.priors == null || (Array.isArray(o.priors)
|
|
385
|
-
&& o.priors.every((v) => (0, exports.isFtSearchPrior)(v))));
|
|
383
|
+
&& (o.contentLocale == null || isString(o.contentLocale));
|
|
386
384
|
};
|
|
387
385
|
exports.isFtSuggestRequest = isFtSuggestRequest;
|
|
388
386
|
const isFtSuggestResult = (o) => {
|
package/dist/fluidtopics.min.js
CHANGED
|
@@ -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:{}},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
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).fluidtopics={})}(this,(function(e){"use strict";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},r={exports:{}},a={exports:{}};!function(e,t){var r=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==r)return r;throw new Error("unable to locate global object")}();e.exports=t=r.fetch,r.fetch&&(t.default=r.fetch.bind(r)),t.Headers=r.Headers,t.Request=r.Request,t.Response=r.Response}(a,a.exports),function(e,t){const r=a.exports,n=r.default||r,i=function(e,t){return/^\/\//.test(e)&&(e="https:"+e),n.call(this,e,t)};i.ponyfill=!0,e.exports=t=i,t.fetch=i,t.Headers=r.Headers,t.Request=r.Request,t.Response=r.Response,t.default=i}(r,r.exports);const n=r.exports,i=n.fetch.bind({});i.polyfill=!0,t.fetch||(t.fetch=i,t.Response=n.Response,t.Headers=n.Headers,t.Request=n.Request);const s=e=>"object"==typeof e&&null!=e,o=e=>"boolean"==typeof e,l=e=>"number"==typeof e,u=e=>"string"==typeof e,c=e=>s(e)&&u(e.tocId)&&Array.isArray(e.children)&&e.children.every((e=>c(e)))&&u(e.contentId)&&u(e.title);var d;e.FtTopicContentTarget=void 0,(d=e.FtTopicContentTarget||(e.FtTopicContentTarget={})).THIRD_PARTY="THIRD_PARTY",d.OFF_THE_GRID="OFF_THE_GRID";const p=e=>s(e)&&l(e.count)&&u(e.label)&&(null==e.lang||u(e.lang)),h=e=>s(e)&&Array.isArray(e.values)&&e.values.every((e=>u(e)))&&u(e.label)&&u(e.key),y=e=>s(e)&&Array.isArray(e.filter)&&e.filter.every((e=>u(e)))&&Array.isArray(e.prior)&&e.prior.every((e=>u(e))),f=e=>s(e)&&o(e.negative)&&Array.isArray(e.values)&&e.values.every((e=>u(e)))&&u(e.key),g=e=>s(e)&&l(e.totalResultsCount)&&o(e.lastPage)&&l(e.currentPage)&&l(e.totalClustersCount);var m;e.FtEditorialType=void 0,(m=e.FtEditorialType||(e.FtEditorialType={})).ARTICLE="ARTICLE",m.BOOK="BOOK";const A=e=>["ARTICLE","BOOK"].includes(e);var T;e.FtOpenMode=void 0,(T=e.FtOpenMode||(e.FtOpenMode={})).FLUIDTOPICS="FLUIDTOPICS",T.EXTERNAL="EXTERNAL";const b=e=>["FLUIDTOPICS","EXTERNAL"].includes(e),F=e=>s(e)&&(null==e.perPage||l(e.perPage))&&l(e.page);var v;e.FtCollectionDocumentType=void 0,(v=e.FtCollectionDocumentType||(e.FtCollectionDocumentType={})).MAP="MAP",v.DOCUMENT="DOCUMENT",v.TOPIC="TOPIC",v.PERSONAL_BOOK="PERSONAL_BOOK",v.SHARED_BOOK="SHARED_BOOK";const R=e=>["MAP","DOCUMENT","TOPIC","PERSONAL_BOOK","SHARED_BOOK"].includes(e),U=e=>s(e)&&l(e.weight)&&u(e.value)&&u(e.key),C=e=>s(e)&&Array.isArray(e.entries)&&e.entries.every((e=>S(e)))&&(null==e.metadataVariableAxis||u(e.metadataVariableAxis)),S=e=>s(e)&&(null==e.document||E(e.document))&&(null==e.topic||P(e.topic))&&D(e.type)&&(null==e.map||O(e.map)),E=e=>s(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>h(e)))&&b(e.openMode)&&u(e.documentUrl)&&u(e.mimeType)&&u(e.title)&&(null==e.lastPublicationDate||u(e.lastPublicationDate))&&u(e.viewerUrl)&&u(e.contentUrl)&&u(e.filename)&&u(e.htmlTitle)&&(null==e.originUrl||u(e.originUrl))&&u(e.documentId)&&u(e.lastEditionDate)&&u(e.htmlExcerpt),O=e=>s(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>h(e)))&&(null==e.openMode||b(e.openMode))&&A(e.editorialType)&&u(e.title)&&(null==e.lastPublicationDate||u(e.lastPublicationDate))&&u(e.htmlTitle)&&(null==e.originUrl||u(e.originUrl))&&u(e.mapUrl)&&u(e.readerUrl)&&u(e.mapId)&&(null==e.lastEditionDate||u(e.lastEditionDate))&&u(e.htmlExcerpt),P=e=>s(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>h(e)))&&b(e.openMode)&&u(e.contentId)&&Array.isArray(e.resources)&&e.resources.every((e=>$(e)))&&u(e.title)&&u(e.mapTitle)&&u(e.topicUrl)&&u(e.contentUrl)&&u(e.htmlTitle)&&Array.isArray(e.breadcrumb)&&e.breadcrumb.every((e=>u(e)))&&u(e.tocId)&&(null==e.originUrl||u(e.originUrl))&&u(e.readerUrl)&&u(e.mapId)&&(null==e.lastEditionDate||u(e.lastEditionDate))&&u(e.htmlExcerpt);var w;e.FtSearchResultType=void 0,(w=e.FtSearchResultType||(e.FtSearchResultType={})).MAP="MAP",w.DOCUMENT="DOCUMENT",w.TOPIC="TOPIC";const D=e=>["MAP","DOCUMENT","TOPIC"].includes(e),I=e=>s(e)&&o(e.hierarchical)&&u(e.label)&&o(e.multiSelectionable)&&u(e.key)&&Array.isArray(e.rootNodes)&&e.rootNodes.every((e=>k(e))),M=e=>s(e)&&(null==e.maxDepth||l(e.maxDepth))&&u(e.id),k=e=>s(e)&&l(e.totalResultsCount)&&o(e.descendantSelected)&&Array.isArray(e.childNodes)&&e.childNodes.every((e=>k(e)))&&u(e.label)&&u(e.value)&&o(e.selected),x=e=>s(e)&&u(e.key),L=e=>s(e)&&u(e.suggestedQuery)&&u(e.htmlSuggestedQuery),$=e=>s(e)&&u(e.filename)&&u(e.resourceUrl)&&u(e.id)&&u(e.mimeType)&&u(e.resourceContentUrl)&&u(e.viewerUrl),H=e=>s(e)&&(null==e.filenameExtension||u(e.filenameExtension))&&(null==e.editorialType||A(e.editorialType))&&(null==e.mimeType||u(e.mimeType))&&D(e.type)&&u(e.value),N=e=>"object"==typeof e&&null!=e,_=e=>"boolean"==typeof e,B=e=>"number"==typeof e,q=e=>"string"==typeof e,j=e=>N(e)&&(null==e.emailAddress||q(e.emailAddress))&&(null==e.displayName||q(e.displayName))&&Array.isArray(e.roles)&&q(e.userId),K="undefined"==typeof window?globalThis:window;function z(e){let t={};for(let r in e){let a=e[r];("object"!=typeof a||Array.isArray(a))&&(a={prior:a});for(let e of["prior","filter"])a[e]=Array.isArray(a[e])?a[e]:[a[e]],a[e]=a[e].map((e=>null!=e?""+e:"")).filter((e=>""!==e));t[r]=a}return t}function V(e){return`${e}-FluidTopicsUnauthenticatedUserSearchPreferences`}const J="undefined"==typeof window?globalThis:window;class G extends Error{status;statusText;body;constructor(e,t,r){super(`${e} - ${t}: ${r}`),this.status=e,this.statusText=t,this.body=r}}async function X(e){if(!e.ok)throw new G(e.status,e.statusText,await e.text());return e}function Y(e){return"application/json"===e.headers.get("Content-Type")?e.json():e.text()}class Q{tenantBaseUrl;ftCallingApp;authorization={};get defaultHeaders(){return{...this.authorization,"Ft-Calling-App":this.ftCallingApp}}constructor(e,t,r){e=e??J.__gwt_ft_moduleBase??J.fluidtopicsclient?.__moduleBase??J.__gwt_activeModules?.fluidtopicsclient?.moduleBase,this.tenantBaseUrl=e.trim().replace(/\/$/,""),r&&void 0!==J.location&&J.location.href.startsWith(this.tenantBaseUrl+"/")?this.ftCallingApp=t:this.ftCallingApp=`ft-public-api/${t}`}setApiKey(e){this.authorization={Authorization:"Bearer "+e}}setCredentials(e,t){var r;this.authorization={Authorization:"Basic "+(r=`${e}:${t}`,"undefined"!=typeof Buffer?Buffer.from(r).toString("base64"):btoa(r))}}clearAuthentication(){this.authorization={}}login(e,t){let r={login:e,password:t,rememberMe:!0};return this.post("/api/authentication/login",r).then((r=>(this.setCredentials(e,t),r)))}logout(){return this.post("/api/authentication/logout").then((()=>this.clearAuthentication()))}getCurrentSession(){return this.get("/api/authentication/current-session")}getMap(e){return this.get(`/api/khub/maps/${e}`)}getTableOfContent(e){return this.get(`/api/khub/maps/${e}/toc`)}getTopic(e,t){return this.get(`/api/khub/maps/${e}/topics/${t}`)}getTopicHTMLContent(e,t,r){return this.get(`/api/khub/maps/${e}/topics/${t}/content${r?"?target="+r:""}`)}getMapAttachments(e){return this.get(`/api/khub/maps/${e}/attachments`)}getMapAttachmentContent(e,t){return this.fetchRawData(`/api/khub/maps/${e}/attachments/${t}/content`)}getMapResources(e){return this.get(`/api/khub/maps/${e}/resources`)}getMapResourceContent(e,t){return this.fetchRawData(`/api/khub/maps/${e}/resources/${t}/content`)}getUnstructuredDocument(e){return this.get(`/api/khub/documents/${e}`)}getUnstructuredDocumentContent(e){return this.fetchRawData(`/api/khub/documents/${e}/content`)}getUnstructuredDocumentTextContent(e){return this.get(`/api/khub/documents/${e}/content/text`)}getCollectionDocuments(e,t){return this.get(`/api/users/${e}/collections/${t}/documents`)}getSuggestions(e){return this.post("/api/khub/suggest",e)}search(e){return this.post("/api/khub/clustered-search",e)}getAvailableSearchLocales(){return this.get("/api/khub/locales")}get(e){return this.makeRequest("GET",e)}post(e,t){return this.makeRequest("POST",e,t)}put(e,t){return this.makeRequest("PUT",e,t)}delete(e){return this.makeRequest("DELETE",e)}async fetch(e,t){const r=t;return e.startsWith("/")||(e="/"+e),await fetch(this.tenantBaseUrl+e,{...r??{},headers:{...this.defaultHeaders,...r?.headers??{}}})}async upload(e,t,r,a=(()=>{})){return new Promise(((n,i)=>{let s=new XMLHttpRequest;s.onload=()=>{if(s.status>=200&&s.status<300){let e="application/json"===s.getResponseHeader("Content-Type")?JSON.parse(s.responseText):s.responseText;n(e)}else i(new G(s.status,s.statusText,s.responseText))},s.upload.onprogress=e=>a(e),s.open(e,this.tenantBaseUrl+t,!0),s.send(r)}))}makeRequest(e,t,r){return this.fetch(t,{method:e,headers:{...null!=r?{"Content-Type":"application/json"}:{}},body:null!=r?JSON.stringify(r):void 0}).then(X).then(Y)}fetchRawData(e){return fetch(this.tenantBaseUrl+e,{headers:this.defaultHeaders}).then(X).then((e=>e.arrayBuffer()))}}e.FluidTopicsApi=Q,e.HttpError=G,e.addUnauthenticatedUserSearchPreferencesChangeHandler=function(e,t){if(K.localStorage){const r=V(e),a=e=>{e.storageArea===K.localStorage&&e.key===r&&t(JSON.parse(e.newValue??"{}"))};return K.addEventListener("storage",a),{removeHandler:()=>K.removeEventListener("storage",a)}}console.error("Cannot handle unauthenticated preferences: local storage is unavailable.")},e.default=Q,e.getUnauthenticatedUserSearchPreferences=function(e){if(K.localStorage)return JSON.parse(K.localStorage.getItem(V(e))??"{}");console.error("Cannot get unauthenticated preferences: local storage is unavailable.")},e.isFtAuthenticatedSession=e=>N(e)&&j(e.profile),e.isFtAuthenticationIdentifier=e=>s(e)&&u(e.identifier)&&u(e.realm),e.isFtCollectionDocument=e=>s(e)&&o(e.deleted)&&(null==e.apiUrl||u(e.apiUrl))&&(null==e.portalUrl||u(e.portalUrl))&&u(e.id)&&u(e.title)&&R(e.type),e.isFtCollectionDocumentType=R,e.isFtCredentials=e=>s(e)&&u(e.password)&&(null==e.newPassword||u(e.newPassword))&&o(e.rememberMe)&&u(e.login),e.isFtEditorialType=A,e.isFtMap=e=>s(e)&&(null==e.prettyUrl||u(e.prettyUrl))&&Array.isArray(e.metadata)&&e.metadata.every((e=>h(e)))&&b(e.openMode)&&u(e.topicsApiEndpoint)&&(null==e.description||u(e.description))&&u(e.attachmentsApiEndpoint)&&A(e.editorialType)&&u(e.baseId)&&u(e.clusterId)&&u(e.title)&&u(e.lastPublication)&&u(e.lastEdition)&&u(e.originId)&&u(e.rightsApiEndpoint)&&(null==e.originUrl||u(e.originUrl))&&u(e.readerUrl)&&(null==e.khubVersion||u(e.khubVersion))&&u(e.id)&&(null==e.lang||u(e.lang)),e.isFtMapAttachment=e=>N(e)&&q(e.file)&&(null==e.size||B(e.size))&&_(e.externalLink)&&q(e.name)&&q(e.id)&&(null==e.mimeType||q(e.mimeType))&&(null==e.viewerUrl||q(e.viewerUrl)),e.isFtMapResource=e=>s(e)&&u(e.contentUrl)&&u(e.filename)&&u(e.id)&&u(e.mimeType),e.isFtMetadata=h,e.isFtMetadataPreferenceConfiguration=y,e.isFtOpenMode=b,e.isFtPageRequest=F,e.isFtSearchFacet=I,e.isFtSearchFacetConf=M,e.isFtSearchFacetEntry=k,e.isFtSearchFilter=f,e.isFtSearchLocale=p,e.isFtSearchLocales=e=>s(e)&&Array.isArray(e.contentLocales)&&e.contentLocales.every((e=>p(e))),e.isFtSearchPreferencesConfiguration=e=>s(e)&&s(e.metadata)&&Object.keys(e.metadata).every((e=>u(e)))&&Object.values(e.metadata).every((e=>y(e))),e.isFtSearchPreset=e=>s(e)&&u(e.name)&&Array.isArray(e.filters)&&e.filters.every((e=>f(e)))&&(null==e.contentLocale||u(e.contentLocale)),e.isFtSearchPrior=U,e.isFtSearchRequest=e=>s(e)&&u(e.query)&&F(e.paging)&&Array.isArray(e.filters)&&e.filters.every((e=>f(e)))&&Array.isArray(e.sort)&&e.sort.every((e=>x(e)))&&(null==e.uiLocale||u(e.uiLocale))&&(null==e.contentLocale||u(e.contentLocale))&&(null==e.priors||Array.isArray(e.priors)&&e.priors.every((e=>U(e))))&&Array.isArray(e.facets)&&e.facets.every((e=>M(e))),e.isFtSearchResultCluster=C,e.isFtSearchResultClusterEntry=S,e.isFtSearchResultMap=O,e.isFtSearchResultTopic=P,e.isFtSearchResultType=D,e.isFtSearchResultUnstructuredDocument=E,e.isFtSearchResults=e=>s(e)&&(null==e.spellcheck||L(e.spellcheck))&&g(e.paging)&&Array.isArray(e.results)&&e.results.every((e=>C(e)))&&Array.isArray(e.facets)&&e.facets.every((e=>I(e))),e.isFtSearchResultsPageInfo=g,e.isFtSearchSortCriterion=x,e.isFtSession=e=>N(e)&&B(e.idleTimeoutInMillis)&&(null==e.profile||j(e.profile))&&_(e.sessionAuthenticated),e.isFtSpellcheck=L,e.isFtSuggestRequest=e=>s(e)&&u(e.input)&&Array.isArray(e.filters)&&e.filters.every((e=>f(e)))&&Array.isArray(e.sort)&&e.sort.every((e=>x(e)))&&(null==e.maxCount||l(e.maxCount))&&(null==e.contentLocale||u(e.contentLocale)),e.isFtSuggestResult=H,e.isFtSuggestResults=e=>s(e)&&Array.isArray(e.suggestions)&&e.suggestions.every((e=>H(e))),e.isFtTocNode=c,e.isFtTopic=e=>s(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>h(e)))&&u(e.id)&&u(e.contentApiEndpoint)&&u(e.title),e.isFtTopicContentTarget=e=>["THIRD_PARTY","OFF_THE_GRID"].includes(e),e.isFtTopicResource=$,e.isFtUnstructuredDocument=e=>s(e)&&(null==e.prettyUrl||u(e.prettyUrl))&&Array.isArray(e.metadata)&&e.metadata.every((e=>h(e)))&&u(e.openMode)&&(null==e.description||u(e.description))&&u(e.mimeType)&&(null==e.baseId||u(e.baseId))&&(null==e.clusterId||u(e.clusterId))&&u(e.contentApiEndpoint)&&u(e.title)&&(null==e.lastPublication||u(e.lastPublication))&&u(e.viewerUrl)&&u(e.lastEdition)&&u(e.filename)&&(null==e.originId||u(e.originId))&&u(e.rightsApiEndpoint)&&(null==e.originUrl||u(e.originUrl))&&(null==e.khubVersion||u(e.khubVersion))&&u(e.id)&&(null==e.lang||u(e.lang)),e.isFtUserProfile=j,e.setUnauthenticatedUserSearchPreferences=function(e,t){if(K.localStorage){let r={...t,metadata:z(t.metadata??{})};const a=V(e),n=JSON.stringify(r);return K.localStorage.setItem(a,n),K.dispatchEvent(new StorageEvent("storage",{key:a,newValue:n,storageArea:K.localStorage,url:K.location.href})),r}console.error("Cannot set unauthenticated preferences: local storage is unavailable.")}}));
|
package/dist/mjs/index.js
CHANGED
|
@@ -37,6 +37,8 @@ export class FluidTopicsApi {
|
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
constructor(tenantBaseUrl, integrationIdentifier, overrideIdentifierIfOnTenant) {
|
|
40
|
+
//@ts-ignore
|
|
41
|
+
tenantBaseUrl = tenantBaseUrl ?? wnd.__gwt_ft_moduleBase ?? wnd.fluidtopicsclient?.__moduleBase ?? wnd.__gwt_activeModules?.fluidtopicsclient?.moduleBase;
|
|
40
42
|
this.tenantBaseUrl = tenantBaseUrl.trim().replace(/\/$/, "");
|
|
41
43
|
if (overrideIdentifierIfOnTenant && typeof wnd.location !== "undefined" && wnd.location.href.startsWith(this.tenantBaseUrl + "/")) {
|
|
42
44
|
this.ftCallingApp = integrationIdentifier;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { FtMetadataPreferenceConfiguration, FtSearchPreferencesConfiguration } from "../types/ft-common/public";
|
|
2
|
-
export declare function setUnauthenticatedUserSearchPreferences(
|
|
2
|
+
export declare function setUnauthenticatedUserSearchPreferences(tenantBaseUrl: string, input: FtSearchPreferencesConfiguration): {
|
|
3
3
|
metadata: Record<string, FtMetadataPreferenceConfiguration>;
|
|
4
4
|
};
|
|
5
|
-
export declare function getUnauthenticatedUserSearchPreferences(tenantBaseUrl
|
|
5
|
+
export declare function getUnauthenticatedUserSearchPreferences(tenantBaseUrl: string): FtSearchPreferencesConfiguration;
|
|
6
6
|
export declare type HandlerRegistration = {
|
|
7
7
|
removeHandler: () => void;
|
|
8
8
|
};
|
|
9
|
-
export declare function addUnauthenticatedUserSearchPreferencesChangeHandler(handler: (newValue: FtSearchPreferencesConfiguration) => void
|
|
9
|
+
export declare function addUnauthenticatedUserSearchPreferencesChangeHandler(tenantBaseUrl: string, handler: (newValue: FtSearchPreferencesConfiguration) => void): HandlerRegistration;
|
|
@@ -17,11 +17,9 @@ function normalizeMetadataPreferences(metadata) {
|
|
|
17
17
|
return normalized;
|
|
18
18
|
}
|
|
19
19
|
function getStorageKey(tenantBaseUrl) {
|
|
20
|
-
//@ts-ignore
|
|
21
|
-
tenantBaseUrl = tenantBaseUrl ?? wnd.__gwt_ft_moduleBase ?? wnd.fluidtopicsclient?.__moduleBase ?? wnd.__gwt_activeModules?.fluidtopicsclient?.moduleBase;
|
|
22
20
|
return `${tenantBaseUrl}-FluidTopicsUnauthenticatedUserSearchPreferences`;
|
|
23
21
|
}
|
|
24
|
-
export function setUnauthenticatedUserSearchPreferences(
|
|
22
|
+
export function setUnauthenticatedUserSearchPreferences(tenantBaseUrl, input) {
|
|
25
23
|
if (wnd.localStorage) {
|
|
26
24
|
let preferences = {
|
|
27
25
|
...input,
|
|
@@ -46,7 +44,7 @@ export function getUnauthenticatedUserSearchPreferences(tenantBaseUrl) {
|
|
|
46
44
|
}
|
|
47
45
|
console.error("Cannot get unauthenticated preferences: local storage is unavailable.");
|
|
48
46
|
}
|
|
49
|
-
export function addUnauthenticatedUserSearchPreferencesChangeHandler(
|
|
47
|
+
export function addUnauthenticatedUserSearchPreferencesChangeHandler(tenantBaseUrl, handler) {
|
|
50
48
|
if (wnd.localStorage) {
|
|
51
49
|
const key = getStorageKey(tenantBaseUrl);
|
|
52
50
|
const eventListener = (event) => {
|
|
@@ -295,7 +295,6 @@ export interface FtSuggestRequest {
|
|
|
295
295
|
sort: Array<FtSearchSortCriterion>;
|
|
296
296
|
maxCount?: number;
|
|
297
297
|
contentLocale?: string;
|
|
298
|
-
priors?: Array<FtSearchPrior>;
|
|
299
298
|
}
|
|
300
299
|
export declare const isFtSuggestRequest: (o: any) => o is FtSuggestRequest;
|
|
301
300
|
export interface FtSuggestResult {
|
|
@@ -342,9 +342,7 @@ export const isFtSuggestRequest = (o) => {
|
|
|
342
342
|
&& ((Array.isArray(o.sort)
|
|
343
343
|
&& o.sort.every((v) => isFtSearchSortCriterion(v))))
|
|
344
344
|
&& (o.maxCount == null || isNumber(o.maxCount))
|
|
345
|
-
&& (o.contentLocale == null || isString(o.contentLocale))
|
|
346
|
-
&& (o.priors == null || (Array.isArray(o.priors)
|
|
347
|
-
&& o.priors.every((v) => isFtSearchPrior(v))));
|
|
345
|
+
&& (o.contentLocale == null || isString(o.contentLocale));
|
|
348
346
|
};
|
|
349
347
|
export const isFtSuggestResult = (o) => {
|
|
350
348
|
return isObject(o)
|