@fluid-topics/public-api 1.0.22 → 1.0.23

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
@@ -67,7 +67,7 @@ class FluidTopicsApi {
67
67
  }
68
68
  }
69
69
  get defaultHeaders() {
70
- return Object.assign(Object.assign({}, this.authorization), { "Ft-Calling-App": this.ftCallingApp });
70
+ return Object.assign(Object.assign(Object.assign({}, this.authorization), this.searchLabel), { "Ft-Calling-App": this.ftCallingApp });
71
71
  }
72
72
  setApiKey(apiKey) {
73
73
  this.authorization = { "Authorization": "Bearer " + apiKey };
@@ -76,7 +76,13 @@ class FluidTopicsApi {
76
76
  this.authorization = { "Authorization": "Basic " + toBase64(`${login}:${password}`) };
77
77
  }
78
78
  clearAuthentication() {
79
- this.authorization = {};
79
+ this.authorization = undefined;
80
+ }
81
+ setSearchLabel(searchLabel) {
82
+ this.searchLabel = { "FT-search-label": searchLabel };
83
+ }
84
+ clearSearchLabel() {
85
+ this.searchLabel = undefined;
80
86
  }
81
87
  login(login, password) {
82
88
  let credentials = {
@@ -170,6 +170,7 @@ const isFtSearchPreset = (o) => {
170
170
  && (isString(o.name))
171
171
  && ((Array.isArray(o.filters)
172
172
  && o.filters.every((v) => (0, exports.isFtSearchFilter)(v))))
173
+ && (isNumber(o.priority))
173
174
  && (o.contentLocale == null || isString(o.contentLocale));
174
175
  };
175
176
  exports.isFtSearchPreset = isFtSearchPreset;
@@ -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,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)&&(null==e.prettyUrl||u(e.prettyUrl))&&u(e.tocId)&&Array.isArray(e.children)&&e.children.every((e=>c(e)))&&u(e.contentId)&&(null==e.page||p(e.page))&&u(e.title),p=e=>s(e)&&l(e.visible)&&l(e.onItsOwn)&&(null==e.parentsVisibility||Array.isArray(e.parentsVisibility)&&e.parentsVisibility.every((e=>l(e))));var d;e.FtTopicContentTarget=void 0,(d=e.FtTopicContentTarget||(e.FtTopicContentTarget={})).THIRD_PARTY="THIRD_PARTY",d.OFF_THE_GRID="OFF_THE_GRID",d.CONTENT_PACKAGER="CONTENT_PACKAGER",d.PAGES="PAGES",d.DESIGNED_READER="DESIGNED_READER";const h=e=>s(e)&&o(e.count)&&u(e.label)&&(null==e.lang||u(e.lang)),y=e=>s(e)&&Array.isArray(e.values)&&e.values.every((e=>u(e)))&&u(e.label)&&u(e.key),f=e=>s(e)&&Array.isArray(e.filter)&&e.filter.every((e=>u(e)))&&Array.isArray(e.prior)&&e.prior.every((e=>u(e))),g=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 A;e.FtEditorialType=void 0,(A=e.FtEditorialType||(e.FtEditorialType={})).ARTICLE="ARTICLE",A.BOOK="BOOK";const T=e=>["ARTICLE","BOOK"].includes(e);var E;e.FtOpenMode=void 0,(E=e.FtOpenMode||(e.FtOpenMode={})).FLUIDTOPICS="FLUIDTOPICS",E.EXTERNAL="EXTERNAL";const b=e=>["FLUIDTOPICS","EXTERNAL"].includes(e),F=e=>s(e)&&(null==e.perPage||o(e.perPage))&&o(e.page);var R;e.FtCollectionDocumentType=void 0,(R=e.FtCollectionDocumentType||(e.FtCollectionDocumentType={})).MAP="MAP",R.DOCUMENT="DOCUMENT",R.TOPIC="TOPIC",R.PERSONAL_BOOK="PERSONAL_BOOK",R.SHARED_BOOK="SHARED_BOOK";const v=e=>["MAP","DOCUMENT","TOPIC","PERSONAL_BOOK","SHARED_BOOK"].includes(e),C=e=>s(e)&&o(e.weight)&&u(e.value)&&u(e.key),S=e=>s(e)&&Array.isArray(e.entries)&&e.entries.every((e=>U(e)))&&(null==e.metadataVariableAxis||u(e.metadataVariableAxis)),U=e=>s(e)&&(null==e.document||P(e.document))&&(null==e.topic||D(e.topic))&&I(e.type)&&(null==e.map||O(e.map)),P=e=>s(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>y(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=>y(e)))&&(null==e.openMode||b(e.openMode))&&T(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),D=e=>s(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>y(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 I=e=>["MAP","DOCUMENT","TOPIC"].includes(e),M=e=>s(e)&&l(e.hierarchical)&&u(e.label)&&l(e.multiSelectionable)&&u(e.key)&&Array.isArray(e.rootNodes)&&e.rootNodes.every((e=>x(e))),k=e=>s(e)&&(null==e.maxDepth||o(e.maxDepth))&&u(e.id),x=e=>s(e)&&o(e.totalResultsCount)&&l(e.descendantSelected)&&Array.isArray(e.childNodes)&&e.childNodes.every((e=>x(e)))&&u(e.label)&&u(e.value)&&l(e.selected),N=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),$=e=>s(e)&&(null==e.filenameExtension||u(e.filenameExtension))&&(null==e.editorialType||T(e.editorialType))&&(null==e.mimeType||u(e.mimeType))&&I(e.type)&&u(e.value),H=e=>"object"==typeof e&&null!=e,B=e=>"boolean"==typeof e,q=e=>"number"==typeof e,G=e=>"string"==typeof e,K=e=>H(e)&&(null==e.emailAddress||G(e.emailAddress))&&(null==e.displayName||G(e.displayName))&&Array.isArray(e.roles)&&G(e.userId),j="undefined"==typeof window?globalThis:window;function V(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 z(e){return`${e}-FluidTopicsUnauthenticatedUserSearchPreferences`}const J="undefined"==typeof window?globalThis:window;class X extends Error{status;statusText;body;constructor(e,t,r){super(`${e} - ${t}: ${r}`),this.status=e,this.statusText=t,this.body=r}}async function Y(e){if(!e.ok)throw new X(e.status,e.statusText,await e.text());return e}function Q(e){return"application/json"===e.headers.get("Content-Type")?e.json():e.text()}class W{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(((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 X(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(Y).then(Q)}fetchRawData(e){return fetch(this.tenantBaseUrl+e,{headers:this.defaultHeaders}).then(Y).then((e=>e.arrayBuffer()))}}e.FluidTopicsApi=W,e.HttpError=X,e.addUnauthenticatedUserSearchPreferencesChangeHandler=function(e,t){if(j.localStorage){const r=z(e),a=e=>{e.storageArea===j.localStorage&&e.key===r&&t(JSON.parse(e.newValue??"{}"))};return j.addEventListener("storage",a),{removeHandler:()=>j.removeEventListener("storage",a)}}console.error("Cannot handle unauthenticated preferences: local storage is unavailable.")},e.default=W,e.getUnauthenticatedUserSearchPreferences=function(e){if(j.localStorage)return JSON.parse(j.localStorage.getItem(z(e))??"{}");console.error("Cannot get unauthenticated preferences: local storage is unavailable.")},e.isFtAuthenticatedSession=e=>H(e)&&K(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)&&v(e.type),e.isFtCollectionDocumentType=v,e.isFtCredentials=e=>s(e)&&u(e.password)&&(null==e.newPassword||u(e.newPassword))&&l(e.rememberMe)&&u(e.login),e.isFtEditorialType=T,e.isFtMap=e=>s(e)&&(null==e.prettyUrl||u(e.prettyUrl))&&Array.isArray(e.metadata)&&e.metadata.every((e=>y(e)))&&b(e.openMode)&&u(e.topicsApiEndpoint)&&(null==e.description||u(e.description))&&u(e.attachmentsApiEndpoint)&&T(e.editorialType)&&u(e.baseId)&&u(e.clusterId)&&(null==e.shouldSplitCurrentPageToc||l(e.shouldSplitCurrentPageToc))&&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=>H(e)&&G(e.file)&&(null==e.size||q(e.size))&&B(e.externalLink)&&G(e.name)&&G(e.id)&&(null==e.mimeType||G(e.mimeType))&&(null==e.viewerUrl||G(e.viewerUrl)),e.isFtMapResource=e=>s(e)&&u(e.contentUrl)&&u(e.filename)&&u(e.id)&&u(e.mimeType),e.isFtMetadata=y,e.isFtMetadataPreferenceConfiguration=f,e.isFtOpenMode=b,e.isFtPageRequest=F,e.isFtSearchFacet=M,e.isFtSearchFacetConf=k,e.isFtSearchFacetEntry=x,e.isFtSearchFilter=g,e.isFtSearchLocale=h,e.isFtSearchLocales=e=>s(e)&&Array.isArray(e.contentLocales)&&e.contentLocales.every((e=>h(e))),e.isFtSearchPreferencesConfiguration=e=>s(e)&&s(e.metadata)&&Object.keys(e.metadata).every((e=>u(e)))&&Object.values(e.metadata).every((e=>f(e))),e.isFtSearchPreset=e=>s(e)&&u(e.name)&&Array.isArray(e.filters)&&e.filters.every((e=>g(e)))&&(null==e.contentLocale||u(e.contentLocale)),e.isFtSearchPrior=C,e.isFtSearchRequest=e=>s(e)&&u(e.query)&&F(e.paging)&&Array.isArray(e.filters)&&e.filters.every((e=>g(e)))&&Array.isArray(e.sort)&&e.sort.every((e=>N(e)))&&(null==e.uiLocale||u(e.uiLocale))&&(null==e.contentLocale||u(e.contentLocale))&&(null==e.priors||Array.isArray(e.priors)&&e.priors.every((e=>C(e))))&&Array.isArray(e.facets)&&e.facets.every((e=>k(e))),e.isFtSearchResultCluster=S,e.isFtSearchResultClusterEntry=U,e.isFtSearchResultMap=O,e.isFtSearchResultTopic=D,e.isFtSearchResultType=I,e.isFtSearchResultUnstructuredDocument=P,e.isFtSearchResults=e=>s(e)&&(null==e.spellcheck||L(e.spellcheck))&&m(e.paging)&&Array.isArray(e.results)&&e.results.every((e=>S(e)))&&Array.isArray(e.facets)&&e.facets.every((e=>M(e))),e.isFtSearchResultsPageInfo=m,e.isFtSearchSortCriterion=N,e.isFtSession=e=>H(e)&&q(e.idleTimeoutInMillis)&&(null==e.profile||K(e.profile))&&B(e.sessionAuthenticated),e.isFtSpellcheck=L,e.isFtSuggestRequest=e=>s(e)&&u(e.input)&&Array.isArray(e.filters)&&e.filters.every((e=>g(e)))&&Array.isArray(e.sort)&&e.sort.every((e=>N(e)))&&(null==e.maxCount||o(e.maxCount))&&(null==e.contentLocale||u(e.contentLocale)),e.isFtSuggestResult=$,e.isFtSuggestResults=e=>s(e)&&Array.isArray(e.suggestions)&&e.suggestions.every((e=>$(e))),e.isFtTocNode=c,e.isFtTocPage=p,e.isFtTopic=e=>s(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>y(e)))&&u(e.id)&&u(e.contentApiEndpoint)&&u(e.title),e.isFtTopicContentTarget=e=>["THIRD_PARTY","OFF_THE_GRID","CONTENT_PACKAGER","PAGES","DESIGNED_READER"].includes(e),e.isFtTopicResource=_,e.isFtUnstructuredDocument=e=>s(e)&&(null==e.prettyUrl||u(e.prettyUrl))&&Array.isArray(e.metadata)&&e.metadata.every((e=>y(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=K,e.setUnauthenticatedUserSearchPreferences=function(e,t){if(j.localStorage){let r={...t,metadata:V(t.metadata??{})};const a=z(e),i=JSON.stringify(r);return j.localStorage.setItem(a,i),j.dispatchEvent(new StorageEvent("storage",{key:a,newValue:i,storageArea:j.localStorage,url:j.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,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)&&(null==e.prettyUrl||u(e.prettyUrl))&&u(e.tocId)&&Array.isArray(e.children)&&e.children.every((e=>c(e)))&&u(e.contentId)&&(null==e.page||p(e.page))&&u(e.title),p=e=>s(e)&&l(e.visible)&&l(e.onItsOwn)&&(null==e.parentsVisibility||Array.isArray(e.parentsVisibility)&&e.parentsVisibility.every((e=>l(e))));var d;e.FtTopicContentTarget=void 0,(d=e.FtTopicContentTarget||(e.FtTopicContentTarget={})).THIRD_PARTY="THIRD_PARTY",d.OFF_THE_GRID="OFF_THE_GRID",d.CONTENT_PACKAGER="CONTENT_PACKAGER",d.PAGES="PAGES",d.DESIGNED_READER="DESIGNED_READER";const h=e=>s(e)&&o(e.count)&&u(e.label)&&(null==e.lang||u(e.lang)),y=e=>s(e)&&Array.isArray(e.values)&&e.values.every((e=>u(e)))&&u(e.label)&&u(e.key),f=e=>s(e)&&Array.isArray(e.filter)&&e.filter.every((e=>u(e)))&&Array.isArray(e.prior)&&e.prior.every((e=>u(e))),g=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 A;e.FtEditorialType=void 0,(A=e.FtEditorialType||(e.FtEditorialType={})).ARTICLE="ARTICLE",A.BOOK="BOOK";const T=e=>["ARTICLE","BOOK"].includes(e);var b;e.FtOpenMode=void 0,(b=e.FtOpenMode||(e.FtOpenMode={})).FLUIDTOPICS="FLUIDTOPICS",b.EXTERNAL="EXTERNAL";const E=e=>["FLUIDTOPICS","EXTERNAL"].includes(e),F=e=>s(e)&&(null==e.perPage||o(e.perPage))&&o(e.page);var R;e.FtCollectionDocumentType=void 0,(R=e.FtCollectionDocumentType||(e.FtCollectionDocumentType={})).MAP="MAP",R.DOCUMENT="DOCUMENT",R.TOPIC="TOPIC",R.PERSONAL_BOOK="PERSONAL_BOOK",R.SHARED_BOOK="SHARED_BOOK";const v=e=>["MAP","DOCUMENT","TOPIC","PERSONAL_BOOK","SHARED_BOOK"].includes(e),S=e=>s(e)&&o(e.weight)&&u(e.value)&&u(e.key),C=e=>s(e)&&Array.isArray(e.entries)&&e.entries.every((e=>U(e)))&&(null==e.metadataVariableAxis||u(e.metadataVariableAxis)),U=e=>s(e)&&(null==e.document||P(e.document))&&(null==e.topic||D(e.topic))&&I(e.type)&&(null==e.map||O(e.map)),P=e=>s(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>y(e)))&&E(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=>y(e)))&&(null==e.openMode||E(e.openMode))&&T(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),D=e=>s(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>y(e)))&&E(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 I=e=>["MAP","DOCUMENT","TOPIC"].includes(e),M=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))),L=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),N=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),$=e=>s(e)&&(null==e.filenameExtension||u(e.filenameExtension))&&(null==e.editorialType||T(e.editorialType))&&(null==e.mimeType||u(e.mimeType))&&I(e.type)&&u(e.value),H=e=>"object"==typeof e&&null!=e,B=e=>"boolean"==typeof e,q=e=>"number"==typeof e,G=e=>"string"==typeof e,K=e=>H(e)&&(null==e.emailAddress||G(e.emailAddress))&&(null==e.displayName||G(e.displayName))&&Array.isArray(e.roles)&&G(e.userId),j="undefined"==typeof window?globalThis:window;function V(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 z(e){return`${e}-FluidTopicsUnauthenticatedUserSearchPreferences`}const J="undefined"==typeof window?globalThis:window;class X extends Error{status;statusText;body;constructor(e,t,r){super(`${e} - ${t}: ${r}`),this.status=e,this.statusText=t,this.body=r}}async function Y(e){if(!e.ok)throw new X(e.status,e.statusText,await e.text());return e}function Q(e){return"application/json"===e.headers.get("Content-Type")?e.json():e.text()}class W{tenantBaseUrl;ftCallingApp;authorization={};searchLabel;get defaultHeaders(){return{...this.authorization,...this.searchLabel,"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=void 0}setSearchLabel(e){this.searchLabel={"FT-search-label":e}}clearSearchLabel(){this.searchLabel=void 0}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 X(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(Y).then(Q)}fetchRawData(e){return fetch(this.tenantBaseUrl+e,{headers:this.defaultHeaders}).then(Y).then((e=>e.arrayBuffer()))}}e.FluidTopicsApi=W,e.HttpError=X,e.addUnauthenticatedUserSearchPreferencesChangeHandler=function(e,t){if(j.localStorage){const r=z(e),a=e=>{e.storageArea===j.localStorage&&e.key===r&&t(JSON.parse(e.newValue??"{}"))};return j.addEventListener("storage",a),{removeHandler:()=>j.removeEventListener("storage",a)}}console.error("Cannot handle unauthenticated preferences: local storage is unavailable.")},e.default=W,e.getUnauthenticatedUserSearchPreferences=function(e){if(j.localStorage)return JSON.parse(j.localStorage.getItem(z(e))??"{}");console.error("Cannot get unauthenticated preferences: local storage is unavailable.")},e.isFtAuthenticatedSession=e=>H(e)&&K(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)&&v(e.type),e.isFtCollectionDocumentType=v,e.isFtCredentials=e=>s(e)&&u(e.password)&&(null==e.newPassword||u(e.newPassword))&&l(e.rememberMe)&&u(e.login),e.isFtEditorialType=T,e.isFtMap=e=>s(e)&&(null==e.prettyUrl||u(e.prettyUrl))&&Array.isArray(e.metadata)&&e.metadata.every((e=>y(e)))&&E(e.openMode)&&u(e.topicsApiEndpoint)&&(null==e.description||u(e.description))&&u(e.attachmentsApiEndpoint)&&T(e.editorialType)&&u(e.baseId)&&u(e.clusterId)&&(null==e.shouldSplitCurrentPageToc||l(e.shouldSplitCurrentPageToc))&&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=>H(e)&&G(e.file)&&(null==e.size||q(e.size))&&B(e.externalLink)&&G(e.name)&&G(e.id)&&(null==e.mimeType||G(e.mimeType))&&(null==e.viewerUrl||G(e.viewerUrl)),e.isFtMapResource=e=>s(e)&&u(e.contentUrl)&&u(e.filename)&&u(e.id)&&u(e.mimeType),e.isFtMetadata=y,e.isFtMetadataPreferenceConfiguration=f,e.isFtOpenMode=E,e.isFtPageRequest=F,e.isFtSearchFacet=M,e.isFtSearchFacetConf=L,e.isFtSearchFacetEntry=k,e.isFtSearchFilter=g,e.isFtSearchLocale=h,e.isFtSearchLocales=e=>s(e)&&Array.isArray(e.contentLocales)&&e.contentLocales.every((e=>h(e))),e.isFtSearchPreferencesConfiguration=e=>s(e)&&s(e.metadata)&&Object.keys(e.metadata).every((e=>u(e)))&&Object.values(e.metadata).every((e=>f(e))),e.isFtSearchPreset=e=>s(e)&&u(e.name)&&Array.isArray(e.filters)&&e.filters.every((e=>g(e)))&&o(e.priority)&&(null==e.contentLocale||u(e.contentLocale)),e.isFtSearchPrior=S,e.isFtSearchRequest=e=>s(e)&&u(e.query)&&F(e.paging)&&Array.isArray(e.filters)&&e.filters.every((e=>g(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=>S(e))))&&Array.isArray(e.facets)&&e.facets.every((e=>L(e))),e.isFtSearchResultCluster=C,e.isFtSearchResultClusterEntry=U,e.isFtSearchResultMap=O,e.isFtSearchResultTopic=D,e.isFtSearchResultType=I,e.isFtSearchResultUnstructuredDocument=P,e.isFtSearchResults=e=>s(e)&&(null==e.spellcheck||N(e.spellcheck))&&m(e.paging)&&Array.isArray(e.results)&&e.results.every((e=>C(e)))&&Array.isArray(e.facets)&&e.facets.every((e=>M(e))),e.isFtSearchResultsPageInfo=m,e.isFtSearchSortCriterion=x,e.isFtSession=e=>H(e)&&q(e.idleTimeoutInMillis)&&(null==e.profile||K(e.profile))&&B(e.sessionAuthenticated),e.isFtSpellcheck=N,e.isFtSuggestRequest=e=>s(e)&&u(e.input)&&Array.isArray(e.filters)&&e.filters.every((e=>g(e)))&&Array.isArray(e.sort)&&e.sort.every((e=>x(e)))&&(null==e.maxCount||o(e.maxCount))&&(null==e.contentLocale||u(e.contentLocale)),e.isFtSuggestResult=$,e.isFtSuggestResults=e=>s(e)&&Array.isArray(e.suggestions)&&e.suggestions.every((e=>$(e))),e.isFtTocNode=c,e.isFtTocPage=p,e.isFtTopic=e=>s(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>y(e)))&&u(e.id)&&u(e.contentApiEndpoint)&&u(e.title),e.isFtTopicContentTarget=e=>["THIRD_PARTY","OFF_THE_GRID","CONTENT_PACKAGER","PAGES","DESIGNED_READER"].includes(e),e.isFtTopicResource=_,e.isFtUnstructuredDocument=e=>s(e)&&(null==e.prettyUrl||u(e.prettyUrl))&&Array.isArray(e.metadata)&&e.metadata.every((e=>y(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=K,e.setUnauthenticatedUserSearchPreferences=function(e,t){if(j.localStorage){let r={...t,metadata:V(t.metadata??{})};const a=z(e),i=JSON.stringify(r);return j.localStorage.setItem(a,i),j.dispatchEvent(new StorageEvent("storage",{key:a,newValue:i,storageArea:j.localStorage,url:j.location.href})),r}console.error("Cannot set unauthenticated preferences: local storage is unavailable.")}}));
@@ -14,11 +14,14 @@ export declare class FluidTopicsApi {
14
14
  private readonly tenantBaseUrl;
15
15
  private readonly ftCallingApp;
16
16
  private authorization;
17
+ private searchLabel;
17
18
  private get defaultHeaders();
18
19
  constructor(tenantBaseUrl: string, integrationIdentifier: string, overrideIdentifierIfOnTenant?: boolean);
19
20
  setApiKey(apiKey: string): void;
20
21
  setCredentials(login: string, password: string): void;
21
22
  clearAuthentication(): void;
23
+ setSearchLabel(searchLabel: string): void;
24
+ clearSearchLabel(): void;
22
25
  login(login: string, password: string): Promise<FtAuthenticatedSession>;
23
26
  logout(): Promise<void>;
24
27
  getCurrentSession(): Promise<FtSession>;
package/dist/mjs/index.js CHANGED
@@ -30,9 +30,11 @@ export class FluidTopicsApi {
30
30
  tenantBaseUrl;
31
31
  ftCallingApp;
32
32
  authorization = {};
33
+ searchLabel;
33
34
  get defaultHeaders() {
34
35
  return {
35
36
  ...this.authorization,
37
+ ...this.searchLabel,
36
38
  "Ft-Calling-App": this.ftCallingApp
37
39
  };
38
40
  }
@@ -54,7 +56,13 @@ export class FluidTopicsApi {
54
56
  this.authorization = { "Authorization": "Basic " + toBase64(`${login}:${password}`) };
55
57
  }
56
58
  clearAuthentication() {
57
- this.authorization = {};
59
+ this.authorization = undefined;
60
+ }
61
+ setSearchLabel(searchLabel) {
62
+ this.searchLabel = { "FT-search-label": searchLabel };
63
+ }
64
+ clearSearchLabel() {
65
+ this.searchLabel = undefined;
58
66
  }
59
67
  login(login, password) {
60
68
  let credentials = {
@@ -131,6 +131,7 @@ export declare const isFtSearchFilter: (o: any) => o is FtSearchFilter;
131
131
  export interface FtSearchPreset {
132
132
  name: string;
133
133
  filters: Array<FtSearchFilter>;
134
+ priority: number;
134
135
  contentLocale?: string;
135
136
  }
136
137
  export declare const isFtSearchPreset: (o: any) => o is FtSearchPreset;
@@ -152,6 +152,7 @@ export const isFtSearchPreset = (o) => {
152
152
  && (isString(o.name))
153
153
  && ((Array.isArray(o.filters)
154
154
  && o.filters.every((v) => isFtSearchFilter(v))))
155
+ && (isNumber(o.priority))
155
156
  && (o.contentLocale == null || isString(o.contentLocale));
156
157
  };
157
158
  export const isFtSearchResultsPageInfo = (o) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/public-api",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
4
4
  "description": "Fluid Topics Public API",
5
5
  "author": "Fluid Topics dev team <opensource@antidot.net>",
6
6
  "license": "LGPL-3.0-only",
@@ -30,6 +30,7 @@
30
30
  "@types/node": "^16.9.1",
31
31
  "chai": "^4.3.4",
32
32
  "mocha": "^9.1.1",
33
+ "nock": "^13.2.9",
33
34
  "rollup": "^2.56.3",
34
35
  "rollup-plugin-node-resolve": "^5.2.0",
35
36
  "rollup-plugin-terser": "^7.0.2",