@fluid-topics/public-api 1.0.10 → 1.0.14

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isFtAuthenticationIdentifier = exports.isFtSearchResultType = exports.FtSearchResultType = exports.isFtOpenMode = exports.FtOpenMode = exports.isFtEditorialType = exports.FtEditorialType = exports.isFtMapResource = exports.isFtMetadata = 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.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;
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";
@@ -20,7 +20,7 @@ const isFtCollectionDocument = (o) => {
20
20
  && (o.portalUrl == null || isString(o.portalUrl))
21
21
  && (isString(o.id))
22
22
  && (isString(o.title))
23
- && ((0, exports.isFtSearchResultType)(o.type));
23
+ && ((0, exports.isFtCollectionDocumentType)(o.type));
24
24
  };
25
25
  exports.isFtCollectionDocument = isFtCollectionDocument;
26
26
  const isFtMap = (o) => {
@@ -89,6 +89,29 @@ const isFtUnstructuredDocument = (o) => {
89
89
  && (o.lang == null || isString(o.lang));
90
90
  };
91
91
  exports.isFtUnstructuredDocument = isFtUnstructuredDocument;
92
+ // From: WsTopicContentTarget
93
+ var FtTopicContentTarget;
94
+ (function (FtTopicContentTarget) {
95
+ FtTopicContentTarget["THIRD_PARTY"] = "THIRD_PARTY";
96
+ FtTopicContentTarget["OFF_THE_GRID"] = "OFF_THE_GRID";
97
+ })(FtTopicContentTarget = exports.FtTopicContentTarget || (exports.FtTopicContentTarget = {}));
98
+ const isFtTopicContentTarget = (o) => {
99
+ return ["THIRD_PARTY", "OFF_THE_GRID"].includes(o);
100
+ };
101
+ exports.isFtTopicContentTarget = isFtTopicContentTarget;
102
+ const isFtSearchLocale = (o) => {
103
+ return isObject(o)
104
+ && (isNumber(o.count))
105
+ && (isString(o.label))
106
+ && (o.lang == null || isString(o.lang));
107
+ };
108
+ exports.isFtSearchLocale = isFtSearchLocale;
109
+ const isFtSearchLocales = (o) => {
110
+ return isObject(o)
111
+ && ((Array.isArray(o.contentLocales)
112
+ && o.contentLocales.every((v) => (0, exports.isFtSearchLocale)(v))));
113
+ };
114
+ exports.isFtSearchLocales = isFtSearchLocales;
92
115
  const isFtMetadata = (o) => {
93
116
  return isObject(o)
94
117
  && ((Array.isArray(o.values)
@@ -105,6 +128,22 @@ const isFtMapResource = (o) => {
105
128
  && (isString(o.mimeType));
106
129
  };
107
130
  exports.isFtMapResource = isFtMapResource;
131
+ const isFtSearchFilter = (o) => {
132
+ return isObject(o)
133
+ && (isBoolean(o.negative))
134
+ && ((Array.isArray(o.values)
135
+ && o.values.every((v) => isString(v))))
136
+ && (isString(o.key));
137
+ };
138
+ exports.isFtSearchFilter = isFtSearchFilter;
139
+ const isFtSearchResultsPageInfo = (o) => {
140
+ return isObject(o)
141
+ && (isNumber(o.totalResultsCount))
142
+ && (isBoolean(o.lastPage))
143
+ && (isNumber(o.currentPage))
144
+ && (isNumber(o.totalClustersCount));
145
+ };
146
+ exports.isFtSearchResultsPageInfo = isFtSearchResultsPageInfo;
108
147
  // From: WsEditorialType
109
148
  var FtEditorialType;
110
149
  (function (FtEditorialType) {
@@ -125,6 +164,123 @@ const isFtOpenMode = (o) => {
125
164
  return ["FLUIDTOPICS", "EXTERNAL"].includes(o);
126
165
  };
127
166
  exports.isFtOpenMode = isFtOpenMode;
167
+ const isFtPageRequest = (o) => {
168
+ return isObject(o)
169
+ && (o.perPage == null || isNumber(o.perPage))
170
+ && (isNumber(o.page));
171
+ };
172
+ exports.isFtPageRequest = isFtPageRequest;
173
+ // From: WsPublicCollectionDocumentType
174
+ var FtCollectionDocumentType;
175
+ (function (FtCollectionDocumentType) {
176
+ FtCollectionDocumentType["MAP"] = "MAP";
177
+ FtCollectionDocumentType["DOCUMENT"] = "DOCUMENT";
178
+ FtCollectionDocumentType["TOPIC"] = "TOPIC";
179
+ FtCollectionDocumentType["PERSONAL_BOOK"] = "PERSONAL_BOOK";
180
+ FtCollectionDocumentType["SHARED_BOOK"] = "SHARED_BOOK";
181
+ })(FtCollectionDocumentType = exports.FtCollectionDocumentType || (exports.FtCollectionDocumentType = {}));
182
+ const isFtCollectionDocumentType = (o) => {
183
+ return ["MAP", "DOCUMENT", "TOPIC", "PERSONAL_BOOK", "SHARED_BOOK"].includes(o);
184
+ };
185
+ exports.isFtCollectionDocumentType = isFtCollectionDocumentType;
186
+ const isFtSearchResults = (o) => {
187
+ return isObject(o)
188
+ && (o.spellcheck == null || (0, exports.isFtSpellcheck)(o.spellcheck))
189
+ && ((0, exports.isFtSearchResultsPageInfo)(o.paging))
190
+ && ((Array.isArray(o.results)
191
+ && o.results.every((v) => (0, exports.isFtSearchResultCluster)(v))))
192
+ && ((Array.isArray(o.facets)
193
+ && o.facets.every((v) => (0, exports.isFtSearchFacet)(v))));
194
+ };
195
+ exports.isFtSearchResults = isFtSearchResults;
196
+ const isFtSearchRequest = (o) => {
197
+ return isObject(o)
198
+ && (isString(o.query))
199
+ && ((0, exports.isFtPageRequest)(o.paging))
200
+ && ((Array.isArray(o.filters)
201
+ && o.filters.every((v) => (0, exports.isFtSearchFilter)(v))))
202
+ && ((Array.isArray(o.sort)
203
+ && o.sort.every((v) => (0, exports.isFtSearchSortCriterion)(v))))
204
+ && (o.uiLocale == null || isString(o.uiLocale))
205
+ && (o.contentLocale == null || isString(o.contentLocale))
206
+ && ((Array.isArray(o.facets)
207
+ && o.facets.every((v) => (0, exports.isFtSearchFacetConf)(v))));
208
+ };
209
+ exports.isFtSearchRequest = isFtSearchRequest;
210
+ const isFtSearchResultCluster = (o) => {
211
+ return isObject(o)
212
+ && ((Array.isArray(o.entries)
213
+ && o.entries.every((v) => (0, exports.isFtSearchResultClusterEntry)(v))))
214
+ && (o.metadataVariableAxis == null || isString(o.metadataVariableAxis));
215
+ };
216
+ exports.isFtSearchResultCluster = isFtSearchResultCluster;
217
+ const isFtSearchResultClusterEntry = (o) => {
218
+ return isObject(o)
219
+ && (o.document == null || (0, exports.isFtSearchResultUnstructuredDocument)(o.document))
220
+ && (o.topic == null || (0, exports.isFtSearchResultTopic)(o.topic))
221
+ && ((0, exports.isFtSearchResultType)(o.type))
222
+ && (o.map == null || (0, exports.isFtSearchResultMap)(o.map));
223
+ };
224
+ exports.isFtSearchResultClusterEntry = isFtSearchResultClusterEntry;
225
+ const isFtSearchResultUnstructuredDocument = (o) => {
226
+ return isObject(o)
227
+ && ((Array.isArray(o.metadata)
228
+ && o.metadata.every((v) => (0, exports.isFtMetadata)(v))))
229
+ && ((0, exports.isFtOpenMode)(o.openMode))
230
+ && (isString(o.documentUrl))
231
+ && (isString(o.mimeType))
232
+ && (isString(o.title))
233
+ && (o.lastPublicationDate == null || isString(o.lastPublicationDate))
234
+ && (isString(o.viewerUrl))
235
+ && (isString(o.contentUrl))
236
+ && (isString(o.filename))
237
+ && (isString(o.htmlTitle))
238
+ && (o.originUrl == null || isString(o.originUrl))
239
+ && (isString(o.documentId))
240
+ && (isString(o.lastEditionDate))
241
+ && (isString(o.htmlExcerpt));
242
+ };
243
+ exports.isFtSearchResultUnstructuredDocument = isFtSearchResultUnstructuredDocument;
244
+ const isFtSearchResultMap = (o) => {
245
+ return isObject(o)
246
+ && ((Array.isArray(o.metadata)
247
+ && o.metadata.every((v) => (0, exports.isFtMetadata)(v))))
248
+ && ((0, exports.isFtOpenMode)(o.openMode))
249
+ && ((0, exports.isFtEditorialType)(o.editorialType))
250
+ && (isString(o.title))
251
+ && (o.lastPublicationDate == null || isString(o.lastPublicationDate))
252
+ && (isString(o.htmlTitle))
253
+ && (o.originUrl == null || isString(o.originUrl))
254
+ && (isString(o.mapUrl))
255
+ && (isString(o.readerUrl))
256
+ && (isString(o.mapId))
257
+ && (o.lastEditionDate == null || isString(o.lastEditionDate))
258
+ && (isString(o.htmlExcerpt));
259
+ };
260
+ exports.isFtSearchResultMap = isFtSearchResultMap;
261
+ const isFtSearchResultTopic = (o) => {
262
+ return isObject(o)
263
+ && ((Array.isArray(o.metadata)
264
+ && o.metadata.every((v) => (0, exports.isFtMetadata)(v))))
265
+ && ((0, exports.isFtOpenMode)(o.openMode))
266
+ && (isString(o.contentId))
267
+ && ((Array.isArray(o.resources)
268
+ && o.resources.every((v) => (0, exports.isFtTopicResource)(v))))
269
+ && (isString(o.title))
270
+ && (isString(o.mapTitle))
271
+ && (isString(o.topicUrl))
272
+ && (isString(o.contentUrl))
273
+ && (isString(o.htmlTitle))
274
+ && ((Array.isArray(o.breadcrumb)
275
+ && o.breadcrumb.every((v) => isString(v))))
276
+ && (isString(o.tocId))
277
+ && (o.originUrl == null || isString(o.originUrl))
278
+ && (isString(o.readerUrl))
279
+ && (isString(o.mapId))
280
+ && (o.lastEditionDate == null || isString(o.lastEditionDate))
281
+ && (isString(o.htmlExcerpt));
282
+ };
283
+ exports.isFtSearchResultTopic = isFtSearchResultTopic;
128
284
  // From: WsPublicSearchResultType
129
285
  var FtSearchResultType;
130
286
  (function (FtSearchResultType) {
@@ -136,6 +292,80 @@ const isFtSearchResultType = (o) => {
136
292
  return ["MAP", "DOCUMENT", "TOPIC"].includes(o);
137
293
  };
138
294
  exports.isFtSearchResultType = isFtSearchResultType;
295
+ const isFtSearchFacet = (o) => {
296
+ return isObject(o)
297
+ && (isBoolean(o.hierarchical))
298
+ && (isString(o.label))
299
+ && (isBoolean(o.multiSelectionable))
300
+ && (isString(o.key))
301
+ && ((Array.isArray(o.rootNodes)
302
+ && o.rootNodes.every((v) => (0, exports.isFtSearchFacetEntry)(v))));
303
+ };
304
+ exports.isFtSearchFacet = isFtSearchFacet;
305
+ const isFtSearchFacetConf = (o) => {
306
+ return isObject(o)
307
+ && (o.maxDepth == null || isNumber(o.maxDepth))
308
+ && (isString(o.id));
309
+ };
310
+ exports.isFtSearchFacetConf = isFtSearchFacetConf;
311
+ const isFtSearchFacetEntry = (o) => {
312
+ return isObject(o)
313
+ && (isNumber(o.totalResultsCount))
314
+ && (isBoolean(o.descendantSelected))
315
+ && ((Array.isArray(o.childNodes)
316
+ && o.childNodes.every((v) => (0, exports.isFtSearchFacetEntry)(v))))
317
+ && (isString(o.label))
318
+ && (isString(o.value))
319
+ && (isBoolean(o.selected));
320
+ };
321
+ exports.isFtSearchFacetEntry = isFtSearchFacetEntry;
322
+ const isFtSearchSortCriterion = (o) => {
323
+ return isObject(o)
324
+ && (isString(o.key));
325
+ };
326
+ exports.isFtSearchSortCriterion = isFtSearchSortCriterion;
327
+ const isFtSpellcheck = (o) => {
328
+ return isObject(o)
329
+ && (isString(o.suggestedQuery))
330
+ && (isString(o.htmlSuggestedQuery));
331
+ };
332
+ exports.isFtSpellcheck = isFtSpellcheck;
333
+ const isFtTopicResource = (o) => {
334
+ return isObject(o)
335
+ && (isString(o.filename))
336
+ && (isString(o.resourceUrl))
337
+ && (isString(o.id))
338
+ && (isString(o.mimeType))
339
+ && (isString(o.resourceContentUrl))
340
+ && (isString(o.viewerUrl));
341
+ };
342
+ exports.isFtTopicResource = isFtTopicResource;
343
+ const isFtSuggestRequest = (o) => {
344
+ return isObject(o)
345
+ && (isString(o.input))
346
+ && ((Array.isArray(o.filters)
347
+ && o.filters.every((v) => (0, exports.isFtSearchFilter)(v))))
348
+ && ((Array.isArray(o.sort)
349
+ && o.sort.every((v) => (0, exports.isFtSearchSortCriterion)(v))))
350
+ && (o.maxCount == null || isNumber(o.maxCount))
351
+ && (o.contentLocale == null || isString(o.contentLocale));
352
+ };
353
+ exports.isFtSuggestRequest = isFtSuggestRequest;
354
+ const isFtSuggestResult = (o) => {
355
+ return isObject(o)
356
+ && (o.filenameExtension == null || isString(o.filenameExtension))
357
+ && (o.editorialType == null || (0, exports.isFtEditorialType)(o.editorialType))
358
+ && (o.mimeType == null || isString(o.mimeType))
359
+ && ((0, exports.isFtSearchResultType)(o.type))
360
+ && (isString(o.value));
361
+ };
362
+ exports.isFtSuggestResult = isFtSuggestResult;
363
+ const isFtSuggestResults = (o) => {
364
+ return isObject(o)
365
+ && ((Array.isArray(o.suggestions)
366
+ && o.suggestions.every((v) => (0, exports.isFtSuggestResult)(v))));
367
+ };
368
+ exports.isFtSuggestResults = isFtSuggestResults;
139
369
  const isFtAuthenticationIdentifier = (o) => {
140
370
  return isObject(o)
141
371
  && (isString(o.identifier))
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isFtMapAttachment = exports.isFtUserProfile = exports.isFtAuthenticatedSession = void 0;
4
+ const isObject = (o) => typeof o === "object" && o != null;
5
+ const isBoolean = (o) => typeof o === "boolean";
6
+ const isNumber = (o) => typeof o === "number";
7
+ const isString = (o) => typeof o === "string";
8
+ const isFtAuthenticatedSession = (o) => {
9
+ return isObject(o)
10
+ && ((0, exports.isFtUserProfile)(o.profile));
11
+ };
12
+ exports.isFtAuthenticatedSession = isFtAuthenticatedSession;
13
+ const isFtUserProfile = (o) => {
14
+ return isObject(o)
15
+ && (o.emailAddress == null || isString(o.emailAddress))
16
+ && (o.displayName == null || isString(o.displayName))
17
+ && ((Array.isArray(o.roles)))
18
+ && (isString(o.userId));
19
+ };
20
+ exports.isFtUserProfile = isFtUserProfile;
21
+ const isFtMapAttachment = (o) => {
22
+ return isObject(o)
23
+ && (isString(o.file))
24
+ && (o.size == null || isNumber(o.size))
25
+ && (isBoolean(o.externalLink))
26
+ && (isString(o.name))
27
+ && (isString(o.id))
28
+ && (o.mimeType == null || isString(o.mimeType))
29
+ && (o.viewerUrl == null || isString(o.viewerUrl));
30
+ };
31
+ exports.isFtMapAttachment = isFtMapAttachment;
@@ -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:{},n={exports:{}},i={exports:{}};!function(e,t){var n=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==n)return n;throw new Error("unable to locate global object")}();e.exports=t=n.fetch,n.fetch&&(t.default=n.fetch.bind(n)),t.Headers=n.Headers,t.Request=n.Request,t.Response=n.Response}(i,i.exports),function(e,t){const n=i.exports,r=n.default||n,s=function(e,t){return/^\/\//.test(e)&&(e="https:"+e),r.call(this,e,t)};s.ponyfill=!0,e.exports=t=s,t.fetch=s,t.Headers=n.Headers,t.Request=n.Request,t.Response=n.Response,t.default=s}(n,n.exports);const r=n.exports,s=r.fetch.bind({});s.polyfill=!0,t.fetch||(t.fetch=s,t.Response=r.Response,t.Headers=r.Headers,t.Request=r.Request);const a=e=>"object"==typeof e&&null!=e,o=e=>"boolean"==typeof e,l=e=>"string"==typeof e,u=e=>a(e)&&l(e.tocId)&&Array.isArray(e.children)&&e.children.every((e=>u(e)))&&l(e.contentId)&&l(e.title),p=e=>a(e)&&Array.isArray(e.values)&&e.values.every((e=>l(e)))&&l(e.label)&&l(e.key);var d;e.FtEditorialType=void 0,(d=e.FtEditorialType||(e.FtEditorialType={})).ARTICLE="ARTICLE",d.BOOK="BOOK";const c=e=>["ARTICLE","BOOK"].includes(e);var h;e.FtOpenMode=void 0,(h=e.FtOpenMode||(e.FtOpenMode={})).FLUIDTOPICS="FLUIDTOPICS",h.EXTERNAL="EXTERNAL";const f=e=>["FLUIDTOPICS","EXTERNAL"].includes(e);var y;e.FtSearchResultType=void 0,(y=e.FtSearchResultType||(e.FtSearchResultType={})).MAP="MAP",y.DOCUMENT="DOCUMENT",y.TOPIC="TOPIC";const m=e=>["MAP","DOCUMENT","TOPIC"].includes(e),g=e=>"object"==typeof e&&null!=e,T=e=>"string"==typeof e,b=e=>g(e)&&(null==e.emailAddress||T(e.emailAddress))&&(null==e.displayName||T(e.displayName))&&Array.isArray(e.roles)&&T(e.userId);async function A(e){if(!e.ok)throw new Error(`${e.status} - ${e.statusText}: ${await e.text()}`);return e}function R(e){return"application/json"===e.headers.get("Content-Type")?e.json():e.text()}class U{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 n;this.authorization={Authorization:"Basic "+(n=`${e}:${t}`,"undefined"!=typeof Buffer?Buffer.from(n).toString("base64"):btoa(n))}}clearAuthentication(){this.authorization={}}login(e,t){let n={login:e,password:t,rememberMe:!0};return this.post("/api/authentication/login",n).then((n=>(this.setCredentials(e,t),n)))}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){return this.get(`/api/khub/maps/${e}/topics/${t}/content`)}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`)}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 n=t;return e.startsWith("/")||(e="/"+e),await fetch(this.tenantBaseUrl+e,{...n??{},headers:{...this.defaultHeaders,...n?.headers??{}}})}makeRequest(e,t,n){return this.fetch(t,{method:e,headers:{...null!=n?{"Content-Type":"application/json"}:{}},body:null!=n?JSON.stringify(n):void 0}).then(A).then(R)}fetchRawData(e){return fetch(this.tenantBaseUrl+e,{headers:this.defaultHeaders}).then(A).then((e=>e.arrayBuffer()))}}e.FluidTopicsApi=U,e.default=U,e.isFtAuthenticatedSession=e=>g(e)&&b(e.profile),e.isFtAuthenticationIdentifier=e=>a(e)&&l(e.identifier)&&l(e.realm),e.isFtCollectionDocument=e=>a(e)&&o(e.deleted)&&(null==e.apiUrl||l(e.apiUrl))&&(null==e.portalUrl||l(e.portalUrl))&&l(e.id)&&l(e.title)&&m(e.type),e.isFtCredentials=e=>a(e)&&l(e.password)&&(null==e.newPassword||l(e.newPassword))&&o(e.rememberMe)&&l(e.login),e.isFtEditorialType=c,e.isFtMap=e=>a(e)&&(null==e.prettyUrl||l(e.prettyUrl))&&Array.isArray(e.metadata)&&e.metadata.every((e=>p(e)))&&f(e.openMode)&&l(e.topicsApiEndpoint)&&(null==e.description||l(e.description))&&l(e.attachmentsApiEndpoint)&&c(e.editorialType)&&l(e.baseId)&&l(e.clusterId)&&l(e.title)&&l(e.lastPublication)&&l(e.lastEdition)&&l(e.originId)&&l(e.rightsApiEndpoint)&&(null==e.originUrl||l(e.originUrl))&&l(e.readerUrl)&&(null==e.khubVersion||l(e.khubVersion))&&l(e.id)&&(null==e.lang||l(e.lang)),e.isFtMapAttachment=e=>g(e)&&T(e.file)&&(null==e.size||(e=>"number"==typeof e)(e.size))&&(e=>"boolean"==typeof e)(e.externalLink)&&T(e.name)&&T(e.id)&&(null==e.mimeType||T(e.mimeType))&&(null==e.viewerUrl||T(e.viewerUrl)),e.isFtMapResource=e=>a(e)&&l(e.contentUrl)&&l(e.filename)&&l(e.id)&&l(e.mimeType),e.isFtMetadata=p,e.isFtOpenMode=f,e.isFtSearchResultType=m,e.isFtTocNode=u,e.isFtTopic=e=>a(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>p(e)))&&l(e.id)&&l(e.contentApiEndpoint)&&l(e.title),e.isFtUnstructuredDocument=e=>a(e)&&(null==e.prettyUrl||l(e.prettyUrl))&&Array.isArray(e.metadata)&&e.metadata.every((e=>p(e)))&&l(e.openMode)&&(null==e.description||l(e.description))&&l(e.mimeType)&&(null==e.baseId||l(e.baseId))&&(null==e.clusterId||l(e.clusterId))&&l(e.contentApiEndpoint)&&l(e.title)&&(null==e.lastPublication||l(e.lastPublication))&&l(e.viewerUrl)&&l(e.lastEdition)&&l(e.filename)&&(null==e.originId||l(e.originId))&&l(e.rightsApiEndpoint)&&(null==e.originUrl||l(e.originUrl))&&(null==e.khubVersion||l(e.khubVersion))&&l(e.id)&&(null==e.lang||l(e.lang)),e.isFtUserProfile=b}));
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,8 +1,14 @@
1
1
  import "cross-fetch/polyfill";
2
- import { FtCollectionDocument, FtMap, FtMapResource, FtTocNode, FtTopic, FtUnstructuredDocument } from "./types/ft-common/public";
2
+ import { FtCollectionDocument, FtMap, FtMapResource, FtSearchLocales, FtSearchRequest, FtSearchResults, FtSuggestRequest, FtSuggestResults, FtTocNode, FtTopic, FtTopicContentTarget, FtUnstructuredDocument } from "./types/ft-common/public";
3
3
  import { FtAuthenticatedSession, FtMapAttachment } from "./types/ft-server/public";
4
4
  export * from "./types/ft-common/public";
5
5
  export * from "./types/ft-server/public";
6
+ export declare class HttpError extends Error {
7
+ readonly status: number;
8
+ readonly statusText: string;
9
+ readonly body: string;
10
+ constructor(status: number, statusText: string, body: string);
11
+ }
6
12
  export declare class FluidTopicsApi {
7
13
  private readonly tenantBaseUrl;
8
14
  private readonly ftCallingApp;
@@ -17,7 +23,7 @@ export declare class FluidTopicsApi {
17
23
  getMap(mapId: string): Promise<FtMap>;
18
24
  getTableOfContent(mapId: string): Promise<Array<FtTocNode>>;
19
25
  getTopic(mapId: string, topicContentId: string): Promise<FtTopic>;
20
- getTopicHTMLContent(mapId: string, topicContentId: string): Promise<string>;
26
+ getTopicHTMLContent(mapId: string, topicContentId: string, target?: FtTopicContentTarget): Promise<string>;
21
27
  getMapAttachments(mapId: string): Promise<Array<FtMapAttachment>>;
22
28
  getMapAttachmentContent(mapId: string, attachmentId: string): Promise<ArrayBuffer>;
23
29
  getMapResources(mapId: string): Promise<Array<FtMapResource>>;
@@ -26,6 +32,9 @@ export declare class FluidTopicsApi {
26
32
  getUnstructuredDocumentContent(documentId: string): Promise<ArrayBuffer>;
27
33
  getUnstructuredDocumentTextContent(documentId: string): Promise<string>;
28
34
  getCollectionDocuments(userId: string, collectionId: string): Promise<Array<FtCollectionDocument>>;
35
+ getSuggestions(request: FtSuggestRequest): Promise<FtSuggestResults>;
36
+ search(request: FtSearchRequest): Promise<FtSearchResults>;
37
+ getAvailableSearchLocales(): Promise<FtSearchLocales>;
29
38
  get<T>(endpoint: string): Promise<T>;
30
39
  post<T>(endpoint: string, data?: any): Promise<T>;
31
40
  put<T>(endpoint: string, data?: any): Promise<T>;
package/dist/mjs/index.js CHANGED
@@ -4,9 +4,20 @@ export * from "./types/ft-server/public";
4
4
  function toBase64(s) {
5
5
  return typeof Buffer !== "undefined" ? Buffer.from(s).toString("base64") : btoa(s);
6
6
  }
7
+ export class HttpError extends Error {
8
+ status;
9
+ statusText;
10
+ body;
11
+ constructor(status, statusText, body) {
12
+ super(`${status} - ${statusText}: ${body}`);
13
+ this.status = status;
14
+ this.statusText = statusText;
15
+ this.body = body;
16
+ }
17
+ }
7
18
  async function handleError(response) {
8
19
  if (!response.ok) {
9
- throw new Error(`${response.status} - ${response.statusText}: ${await response.text()}`);
20
+ throw new HttpError(response.status, response.statusText, await response.text());
10
21
  }
11
22
  return response;
12
23
  }
@@ -61,8 +72,8 @@ export class FluidTopicsApi {
61
72
  getTopic(mapId, topicContentId) {
62
73
  return this.get(`/api/khub/maps/${mapId}/topics/${topicContentId}`);
63
74
  }
64
- getTopicHTMLContent(mapId, topicContentId) {
65
- return this.get(`/api/khub/maps/${mapId}/topics/${topicContentId}/content`);
75
+ getTopicHTMLContent(mapId, topicContentId, target) {
76
+ return this.get(`/api/khub/maps/${mapId}/topics/${topicContentId}/content${target ? "?target=" + target : ""}`);
66
77
  }
67
78
  getMapAttachments(mapId) {
68
79
  return this.get(`/api/khub/maps/${mapId}/attachments`);
@@ -88,6 +99,15 @@ export class FluidTopicsApi {
88
99
  getCollectionDocuments(userId, collectionId) {
89
100
  return this.get(`/api/users/${userId}/collections/${collectionId}/documents`);
90
101
  }
102
+ getSuggestions(request) {
103
+ return this.post("/api/khub/suggest", request);
104
+ }
105
+ search(request) {
106
+ return this.post("/api/khub/clustered-search", request);
107
+ }
108
+ getAvailableSearchLocales() {
109
+ return this.get("/api/khub/locales");
110
+ }
91
111
  get(endpoint) {
92
112
  return this.makeRequest("GET", endpoint);
93
113
  }
@@ -0,0 +1,153 @@
1
+ import "cross-fetch/polyfill";
2
+ export * from "./types/ft-common/public";
3
+ export * from "./types/ft-server/public";
4
+ function toBase64(s) {
5
+ return typeof Buffer !== "undefined" ? Buffer.from(s).toString("base64") : btoa(s);
6
+ }
7
+ export class HttpError extends Error {
8
+ status;
9
+ statusText;
10
+ body;
11
+ constructor(status, statusText, body) {
12
+ super(`${status} - ${statusText}: ${body}`);
13
+ this.status = status;
14
+ this.statusText = statusText;
15
+ this.body = body;
16
+ }
17
+ }
18
+ async function handleError(response) {
19
+ if (!response.ok) {
20
+ throw new HttpError(response.status, response.statusText, await response.text());
21
+ }
22
+ return response;
23
+ }
24
+ function getBody(response) {
25
+ return response.headers.get("Content-Type") === "application/json" ? response.json() : response.text();
26
+ }
27
+ export class FluidTopicsApi {
28
+ tenantBaseUrl;
29
+ ftCallingApp;
30
+ authorization = {};
31
+ get defaultHeaders() {
32
+ return {
33
+ ...this.authorization,
34
+ "Ft-Calling-App": this.ftCallingApp
35
+ };
36
+ }
37
+ constructor(tenantBaseUrl, integrationIdentifier) {
38
+ this.tenantBaseUrl = tenantBaseUrl.trim().replace(/\/$/, "");
39
+ this.ftCallingApp = `ft-public-api/${integrationIdentifier}`;
40
+ }
41
+ setApiKey(apiKey) {
42
+ this.authorization = { "Authorization": "Bearer " + apiKey };
43
+ }
44
+ setCredentials(login, password) {
45
+ this.authorization = { "Authorization": "Basic " + toBase64(`${login}:${password}`) };
46
+ }
47
+ clearAuthentication() {
48
+ this.authorization = {};
49
+ }
50
+ login(login, password) {
51
+ let credentials = {
52
+ login: login,
53
+ password: password,
54
+ rememberMe: true
55
+ };
56
+ return this.post(`/api/authentication/login`, credentials)
57
+ .then(result => {
58
+ this.setCredentials(login, password);
59
+ return result;
60
+ });
61
+ }
62
+ logout() {
63
+ return this.post(`/api/authentication/logout`)
64
+ .then(() => this.clearAuthentication());
65
+ }
66
+ getMap(mapId) {
67
+ return this.get(`/api/khub/maps/${mapId}`);
68
+ }
69
+ getTableOfContent(mapId) {
70
+ return this.get(`/api/khub/maps/${mapId}/toc`);
71
+ }
72
+ getTopic(mapId, topicContentId) {
73
+ return this.get(`/api/khub/maps/${mapId}/topics/${topicContentId}`);
74
+ }
75
+ getTopicHTMLContent(mapId, topicContentId, target) {
76
+ return this.get(`/api/khub/maps/${mapId}/topics/${topicContentId}/content${target ? "?target=" + target : ""}`);
77
+ }
78
+ getMapAttachments(mapId) {
79
+ return this.get(`/api/khub/maps/${mapId}/attachments`);
80
+ }
81
+ getMapAttachmentContent(mapId, attachmentId) {
82
+ return this.fetchRawData(`/api/khub/maps/${mapId}/attachments/${attachmentId}/content`);
83
+ }
84
+ getMapResources(mapId) {
85
+ return this.get(`/api/khub/maps/${mapId}/resources`);
86
+ }
87
+ getMapResourceContent(mapId, resourceId) {
88
+ return this.fetchRawData(`/api/khub/maps/${mapId}/resources/${resourceId}/content`);
89
+ }
90
+ getUnstructuredDocument(documentId) {
91
+ return this.get(`/api/khub/documents/${documentId}`);
92
+ }
93
+ getUnstructuredDocumentContent(documentId) {
94
+ return this.fetchRawData(`/api/khub/documents/${documentId}/content`);
95
+ }
96
+ getUnstructuredDocumentTextContent(documentId) {
97
+ return this.get(`/api/khub/documents/${documentId}/content/text`);
98
+ }
99
+ getCollectionDocuments(userId, collectionId) {
100
+ return this.get(`/api/users/${userId}/collections/${collectionId}/documents`);
101
+ }
102
+ getSuggestions(request) {
103
+ return this.post("/api/khub/suggest", request);
104
+ }
105
+ search(request) {
106
+ return this.post("/api/khub/clustered-search", request);
107
+ }
108
+ getAvailableSearchLocales() {
109
+ return this.get("/api/khub/locales");
110
+ }
111
+ get(endpoint) {
112
+ return this.makeRequest("GET", endpoint);
113
+ }
114
+ post(endpoint, data) {
115
+ return this.makeRequest("POST", endpoint, data);
116
+ }
117
+ put(endpoint, data) {
118
+ return this.makeRequest("PUT", endpoint, data);
119
+ }
120
+ delete(endpoint) {
121
+ return this.makeRequest("DELETE", endpoint);
122
+ }
123
+ async fetch(endpoint, init) {
124
+ const requestInit = init;
125
+ if (!endpoint.startsWith("/")) {
126
+ endpoint = "/" + endpoint;
127
+ }
128
+ return await fetch(this.tenantBaseUrl + endpoint, {
129
+ ...(requestInit ?? {}),
130
+ headers: {
131
+ ...this.defaultHeaders,
132
+ ...(requestInit?.headers ?? {})
133
+ }
134
+ });
135
+ }
136
+ makeRequest(method, endpoint, data) {
137
+ return this.fetch(endpoint, {
138
+ method: method,
139
+ headers: {
140
+ ...(data != null ? { "Content-Type": "application/json" } : {})
141
+ },
142
+ body: data != null ? JSON.stringify(data) : undefined
143
+ })
144
+ .then(handleError)
145
+ .then(getBody);
146
+ }
147
+ fetchRawData(endpoint) {
148
+ return fetch(this.tenantBaseUrl + endpoint, { headers: this.defaultHeaders })
149
+ .then(handleError)
150
+ .then(response => response.arrayBuffer());
151
+ }
152
+ }
153
+ export default FluidTopicsApi;