@fluid-topics/public-api 1.0.26 → 1.0.28

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/.yarnrc ADDED
@@ -0,0 +1 @@
1
+ --frozen-lockfile true
package/dist/cjs/index.js CHANGED
@@ -54,12 +54,81 @@ function getBody(response) {
54
54
  }
55
55
  class FluidTopicsApi {
56
56
  constructor(tenantBaseUrl, integrationIdentifier, overrideIdentifierIfOnTenant) {
57
- var _a, _b, _c, _d, _e;
57
+ var _a, _b, _c, _d, _e, _f;
58
58
  this.authorization = {};
59
+ this.endpoints = {
60
+ authentication: {
61
+ login: `api/authentication/login`,
62
+ logout: `api/authentication/logout`,
63
+ currentSession: `api/authentication/current-session`,
64
+ },
65
+ khub: {
66
+ maps: {
67
+ mapId: (mapId) => ({
68
+ info: `api/khub/maps/${mapId}`,
69
+ toc: `api/khub/maps/${mapId}/toc`,
70
+ pages: `api/khub/maps/${mapId}/pages`,
71
+ feedback: `api/khub/maps/${mapId}/feedback`,
72
+ rating: `api/khub/maps/${mapId}/rating`,
73
+ attachments: {
74
+ list: `api/khub/maps/${mapId}/attachments`,
75
+ attachmentId: (attachmentId) => ({
76
+ content: `api/khub/maps/${mapId}/attachments/${attachmentId}/content`,
77
+ })
78
+ },
79
+ resources: {
80
+ list: `api/khub/maps/${mapId}/resources`,
81
+ resourceId: (resourceId) => ({
82
+ content: `api/khub/maps/${mapId}/resources/${resourceId}/content`,
83
+ })
84
+ },
85
+ topics: {
86
+ contentId: (contentId) => ({
87
+ info: `api/khub/maps/${mapId}/topics/${contentId}`,
88
+ content: `api/khub/maps/${mapId}/topics/${contentId}/content`,
89
+ }),
90
+ tocId: (tocId) => ({
91
+ feedback: `api/khub/maps/${mapId}/topics/${tocId}/feedback`,
92
+ rating: `api/khub/maps/${mapId}/topics/${tocId}/rating`,
93
+ })
94
+ },
95
+ })
96
+ },
97
+ documents: {
98
+ documentId: (documentId) => ({
99
+ info: `api/khub/documents/${documentId}`,
100
+ content: `api/khub/documents/${documentId}/content`,
101
+ text: `api/khub/documents/${documentId}/content/text`,
102
+ feedback: `api/khub/documents/${documentId}/feedback`,
103
+ rating: `api/khub/documents/${documentId}/rating`,
104
+ })
105
+ },
106
+ suggest: `api/khub/suggest`,
107
+ clusteredSearch: `api/khub/clustered-search`,
108
+ locales: `api/khub/locales`,
109
+ },
110
+ users: {
111
+ userId: (userId) => ({
112
+ collections: {
113
+ collectionId: (collectionId) => ({
114
+ documents: `api/users/${userId}/collections/${collectionId}/documents`,
115
+ })
116
+ }
117
+ })
118
+ },
119
+ stylesheets: {
120
+ fonts: `api/stylesheets/fonts.css`,
121
+ theme: `api/stylesheets/theme.css`,
122
+ content: {
123
+ title: `api/stylesheets/content/title.css`,
124
+ topic: `api/stylesheets/content/topic.css`,
125
+ },
126
+ },
127
+ };
59
128
  //@ts-ignore
60
- 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;
61
- this.tenantBaseUrl = tenantBaseUrl.trim().replace(/\/$/, "");
62
- if (overrideIdentifierIfOnTenant && typeof wnd.location !== "undefined" && wnd.location.href.startsWith(this.tenantBaseUrl + "/")) {
129
+ tenantBaseUrl = ((_f = (_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) !== null && _f !== void 0 ? _f : "").trim();
130
+ this.tenantBaseUrl = tenantBaseUrl.endsWith("/") ? tenantBaseUrl : tenantBaseUrl + "/";
131
+ if (overrideIdentifierIfOnTenant && typeof wnd.location !== "undefined" && wnd.location.href.startsWith(this.tenantBaseUrl)) {
63
132
  this.ftCallingApp = integrationIdentifier;
64
133
  }
65
134
  else {
@@ -90,96 +159,101 @@ class FluidTopicsApi {
90
159
  password: password,
91
160
  rememberMe: true
92
161
  };
93
- return this.post(`/api/authentication/login`, credentials)
162
+ return this.post(this.endpoints.authentication.login, credentials)
94
163
  .then(result => {
95
164
  this.setCredentials(login, password);
96
165
  return result;
97
166
  });
98
167
  }
99
168
  logout() {
100
- return this.post(`/api/authentication/logout`)
169
+ return this.post(this.endpoints.authentication.logout)
101
170
  .then(() => this.clearAuthentication());
102
171
  }
103
172
  getCurrentSession() {
104
- return this.get(`/api/authentication/current-session`);
173
+ return this.get(this.endpoints.authentication.currentSession);
105
174
  }
106
175
  getMap(mapId) {
107
- return this.get(`/api/khub/maps/${mapId}`);
176
+ return this.get(this.endpoints.khub.maps.mapId(mapId).info);
108
177
  }
109
178
  getTableOfContent(mapId) {
110
- return this.get(`/api/khub/maps/${mapId}/toc`);
179
+ return this.get(this.endpoints.khub.maps.mapId(mapId).toc);
180
+ }
181
+ getPages(mapId) {
182
+ return this.get(this.endpoints.khub.maps.mapId(mapId).pages);
111
183
  }
112
184
  getTopic(mapId, topicContentId) {
113
- return this.get(`/api/khub/maps/${mapId}/topics/${topicContentId}`);
185
+ return this.get(this.endpoints.khub.maps.mapId(mapId).topics.contentId(topicContentId).info);
114
186
  }
115
187
  getTopicHTMLContent(mapId, topicContentId, target) {
116
- return this.get(`/api/khub/maps/${mapId}/topics/${topicContentId}/content${target ? "?target=" + target : ""}`);
188
+ return this.get(this.endpoints.khub.maps.mapId(mapId).topics.contentId(topicContentId).content + (target ? "?target=" + target : ""));
117
189
  }
118
190
  getMapAttachments(mapId) {
119
- return this.get(`/api/khub/maps/${mapId}/attachments`);
191
+ return this.get(this.endpoints.khub.maps.mapId(mapId).attachments.list);
120
192
  }
121
193
  getMapAttachmentContent(mapId, attachmentId) {
122
- return this.fetchRawData(`/api/khub/maps/${mapId}/attachments/${attachmentId}/content`);
194
+ return this.fetchRawData(this.endpoints.khub.maps.mapId(mapId).attachments.attachmentId(attachmentId).content);
123
195
  }
124
196
  getMapResources(mapId) {
125
- return this.get(`/api/khub/maps/${mapId}/resources`);
197
+ return this.get(this.endpoints.khub.maps.mapId(mapId).resources.list);
126
198
  }
127
199
  getMapResourceContent(mapId, resourceId) {
128
- return this.fetchRawData(`/api/khub/maps/${mapId}/resources/${resourceId}/content`);
200
+ return this.fetchRawData(this.endpoints.khub.maps.mapId(mapId).resources.resourceId(resourceId).content);
129
201
  }
130
202
  getUnstructuredDocument(documentId) {
131
- return this.get(`/api/khub/documents/${documentId}`);
203
+ return this.get(this.endpoints.khub.documents.documentId(documentId).info);
132
204
  }
133
205
  getUnstructuredDocumentContent(documentId) {
134
- return this.fetchRawData(`/api/khub/documents/${documentId}/content`);
206
+ return this.fetchRawData(this.endpoints.khub.documents.documentId(documentId).content);
135
207
  }
136
208
  getUnstructuredDocumentTextContent(documentId) {
137
- return this.get(`/api/khub/documents/${documentId}/content/text`);
209
+ return this.get(this.endpoints.khub.documents.documentId(documentId).text);
138
210
  }
139
211
  getCollectionDocuments(userId, collectionId) {
140
- return this.get(`/api/users/${userId}/collections/${collectionId}/documents`);
212
+ return this.get(this.endpoints.users.userId(userId).collections.collectionId(collectionId).documents);
141
213
  }
142
214
  getSuggestions(request) {
143
- return this.post("/api/khub/suggest", request);
215
+ return this.post(this.endpoints.khub.suggest, request);
144
216
  }
145
217
  search(request) {
146
- return this.post("/api/khub/clustered-search", request);
218
+ return this.post(this.endpoints.khub.clusteredSearch, request);
147
219
  }
148
220
  getAvailableSearchLocales() {
149
- return this.get("/api/khub/locales");
221
+ return this.get(this.endpoints.khub.locales);
150
222
  }
151
223
  getMapRating(mapId) {
152
- return this.get(`/api/khub/maps/${mapId}/rating`);
153
- }
154
- getDocumentRating(docId) {
155
- return this.get(`/api/khub/documents/${docId}/rating`);
224
+ return this.get(this.endpoints.khub.maps.mapId(mapId).rating);
156
225
  }
157
226
  rateMap(mapId, type, value) {
158
- return this.post(`/api/khub/maps/${mapId}/rating`, { type, value });
227
+ return this.post(this.endpoints.khub.maps.mapId(mapId).rating, { type, value });
159
228
  }
160
229
  unrateMap(mapId) {
161
- return this.delete(`/api/khub/maps/${mapId}/rating`);
230
+ return this.delete(this.endpoints.khub.maps.mapId(mapId).rating);
162
231
  }
163
232
  sendMapFeedback(mapId, message) {
164
- return this.post(`/api/khub/maps/${mapId}/feedback`, { message });
233
+ return this.post(this.endpoints.khub.maps.mapId(mapId).feedback, { message });
165
234
  }
166
235
  rateTopic(mapId, tocId, type, value) {
167
- return this.post(`/api/khub/maps/${mapId}/topics/${tocId}/rating`, { type, value });
236
+ return this.post(this.endpoints.khub.maps.mapId(mapId).topics.tocId(tocId).rating, {
237
+ type, value
238
+ });
168
239
  }
169
240
  unrateTopic(mapId, tocId) {
170
- return this.delete(`/api/khub/maps/${mapId}/topics/${tocId}/rating`);
241
+ return this.delete(this.endpoints.khub.maps.mapId(mapId).topics.tocId(tocId).rating);
171
242
  }
172
243
  sendTopicFeedback(mapId, tocId, message) {
173
- return this.post(`/api/khub/maps/${mapId}/topics/${tocId}/feedback`, { message });
244
+ return this.post(this.endpoints.khub.maps.mapId(mapId).topics.tocId(tocId).feedback, { message });
245
+ }
246
+ getDocumentRating(docId) {
247
+ return this.get(this.endpoints.khub.documents.documentId(docId).rating);
174
248
  }
175
249
  rateDocument(docId, type, value) {
176
- return this.post(`/api/khub/documents/${docId}/rating`, { type, value });
250
+ return this.post(this.endpoints.khub.documents.documentId(docId).rating, { type, value });
177
251
  }
178
252
  unrateDocument(docId) {
179
- return this.delete(`/api/khub/documents/${docId}/rating`);
253
+ return this.delete(this.endpoints.khub.documents.documentId(docId).rating);
180
254
  }
181
255
  sendDocumentFeedback(docId, message) {
182
- return this.post(`/api/khub/documents/${docId}/feedback`, { message });
256
+ return this.post(this.endpoints.khub.documents.documentId(docId).feedback, { message });
183
257
  }
184
258
  get(endpoint) {
185
259
  return this.makeRequest("GET", endpoint);
@@ -193,18 +267,18 @@ class FluidTopicsApi {
193
267
  delete(endpoint) {
194
268
  return this.makeRequest("DELETE", endpoint);
195
269
  }
270
+ makeAbsolute(endpoint) {
271
+ return this.tenantBaseUrl + endpoint.replace(/^\//, "");
272
+ }
196
273
  fetch(endpoint, init) {
197
274
  var _a;
198
275
  return __awaiter(this, void 0, void 0, function* () {
199
276
  const requestInit = init;
200
- if (!endpoint.startsWith("/")) {
201
- endpoint = "/" + endpoint;
202
- }
203
- return yield fetch(this.tenantBaseUrl + endpoint, Object.assign(Object.assign({}, (requestInit !== null && requestInit !== void 0 ? requestInit : {})), { headers: Object.assign(Object.assign({}, this.defaultHeaders), ((_a = requestInit === null || requestInit === void 0 ? void 0 : requestInit.headers) !== null && _a !== void 0 ? _a : {})) }));
277
+ return yield fetch(this.makeAbsolute(endpoint), Object.assign(Object.assign({}, (requestInit !== null && requestInit !== void 0 ? requestInit : {})), { headers: Object.assign(Object.assign({}, this.defaultHeaders), ((_a = requestInit === null || requestInit === void 0 ? void 0 : requestInit.headers) !== null && _a !== void 0 ? _a : {})) }));
204
278
  });
205
279
  }
206
280
  upload(method, endpoint, body, onProgress = () => undefined) {
207
- return __awaiter(this, void 0, void 0, function* () {
281
+ if (typeof XMLHttpRequest !== "undefined") {
208
282
  return new Promise((resolve, reject) => {
209
283
  let xhr = new XMLHttpRequest();
210
284
  xhr.onload = () => {
@@ -217,10 +291,13 @@ class FluidTopicsApi {
217
291
  }
218
292
  };
219
293
  xhr.upload.onprogress = (e) => onProgress(e);
220
- xhr.open(method, this.tenantBaseUrl + endpoint, true);
294
+ xhr.open(method, this.makeAbsolute(endpoint), true);
221
295
  xhr.send(body);
222
296
  });
223
- });
297
+ }
298
+ else {
299
+ return this.fetch(endpoint, { method, body }).then(handleError).then(getBody);
300
+ }
224
301
  }
225
302
  makeRequest(method, endpoint, data) {
226
303
  return this.fetch(endpoint, {
@@ -232,7 +309,7 @@ class FluidTopicsApi {
232
309
  .then(getBody);
233
310
  }
234
311
  fetchRawData(endpoint) {
235
- return fetch(this.tenantBaseUrl + endpoint, { headers: this.defaultHeaders })
312
+ return fetch(this.makeAbsolute(endpoint), { headers: this.defaultHeaders })
236
313
  .then(handleError)
237
314
  .then(response => response.arrayBuffer());
238
315
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isFtSpellcheck = exports.isFtSearchSortCriterion = exports.isFtSearchFacetEntry = exports.isFtSearchFacetConf = exports.isFtSearchFacet = exports.isFtSearchResultType = exports.FtSearchResultType = exports.isFtSearchResultTopic = exports.isFtSearchResultMap = exports.isFtSearchResultUnstructuredDocument = exports.isFtSearchResultClusterEntry = exports.isFtSearchResultCluster = exports.isFtSearchRequest = exports.isFtSearchPrior = exports.isFtSearchResults = exports.isFtCollectionDocumentType = exports.FtCollectionDocumentType = exports.isFtPageRequest = exports.isFtOpenMode = exports.FtOpenMode = exports.isFtEditorialType = exports.FtEditorialType = exports.isFtSearchResultsPageInfo = exports.isFtSearchPreset = exports.isFtSearchFilter = exports.isFtSearchPreferencesConfiguration = exports.isFtMetadataPreferenceConfiguration = exports.isFtMapResource = exports.isFtTopicsRatingSummary = exports.isFtTopicRating = exports.isFtRatingSummary = exports.isFtRatingCreation = exports.isFtPublicationRatingSummary = exports.isFtPublicationRating = exports.isFtRatingType = exports.FtRatingType = exports.isFtMetadata = exports.isFtSearchLocales = exports.isFtSearchLocale = exports.isFtFeedbackCreation = exports.isFtTopicContentTarget = exports.FtTopicContentTarget = exports.isFtUnstructuredDocument = exports.isFtTopic = exports.isFtTocPage = exports.isFtTocNode = exports.isFtMapStyles = exports.isFtMap = exports.isFtCollectionDocument = exports.isFtCredentials = void 0;
4
- exports.isFtAuthenticationIdentifier = exports.isFtSuggestResults = exports.isFtSuggestResult = exports.isFtSuggestRequest = exports.isFtTopicResource = void 0;
3
+ exports.isFtTopicResource = exports.isFtSpellcheck = exports.isFtSearchSortCriterion = exports.isFtSearchFacetEntry = exports.isFtSearchFacetConf = exports.isFtSearchFacet = exports.isFtSearchResultType = exports.FtSearchResultType = exports.isFtSearchResultTopic = exports.isFtSearchResultMap = exports.isFtSearchResultUnstructuredDocument = exports.isFtSearchResultClusterEntry = exports.isFtSearchResultCluster = exports.isFtSearchRequest = exports.isFtSearchPrior = exports.isFtSearchResults = exports.isFtCollectionDocumentType = exports.FtCollectionDocumentType = exports.isFtPageRequest = exports.isFtOpenMode = exports.FtOpenMode = exports.isFtEditorialType = exports.FtEditorialType = exports.isFtSearchResultsPageInfo = exports.isFtSearchPreset = exports.isFtSearchFilter = exports.isFtSearchPreferencesConfiguration = exports.isFtMetadataPreferenceConfiguration = exports.isFtMapResource = exports.isFtTopicsRatingSummary = exports.isFtTopicRating = exports.isFtRatingSummary = exports.isFtRatingCreation = exports.isFtPublicationRatingSummary = exports.isFtPublicationRating = exports.isFtRatingType = exports.FtRatingType = exports.isFtMetadata = exports.isFtSearchLocales = exports.isFtSearchLocale = exports.isFtFeedbackCreation = exports.isFtTopicContentTarget = exports.FtTopicContentTarget = exports.isFtUnstructuredDocument = exports.isFtTopic = exports.isFtTocNode = exports.isFtMapStyles = exports.isFtMap = exports.isFtCollectionDocument = exports.isFtCredentials = void 0;
4
+ exports.isFtAuthenticationIdentifier = exports.isFtSuggestResults = exports.isFtSuggestResult = exports.isFtSuggestRequest = void 0;
5
5
  const isObject = (o) => typeof o === "object" && o != null;
6
6
  const isBoolean = (o) => typeof o === "boolean";
7
7
  const isNumber = (o) => typeof o === "number";
@@ -65,18 +65,9 @@ const isFtTocNode = (o) => {
65
65
  && ((Array.isArray(o.children)
66
66
  && o.children.every((v) => (0, exports.isFtTocNode)(v))))
67
67
  && (isString(o.contentId))
68
- && (o.page == null || (0, exports.isFtTocPage)(o.page))
69
68
  && (isString(o.title));
70
69
  };
71
70
  exports.isFtTocNode = isFtTocNode;
72
- const isFtTocPage = (o) => {
73
- return isObject(o)
74
- && (isBoolean(o.visible))
75
- && (isBoolean(o.onItsOwn))
76
- && (o.parentsVisibility == null || (Array.isArray(o.parentsVisibility)
77
- && o.parentsVisibility.every((v) => isBoolean(v))));
78
- };
79
- exports.isFtTocPage = isFtTocPage;
80
71
  const isFtTopic = (o) => {
81
72
  return isObject(o)
82
73
  && ((Array.isArray(o.metadata)
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isFtMapAttachment = exports.isFtUserProfile = exports.isFtSession = exports.isFtAuthenticatedSession = void 0;
3
+ exports.isFtPaginationConfiguration = exports.isFtPaginatedTocNode = exports.isFtPaginatedToc = exports.isFtPageConfiguration = exports.isFtMapAttachment = exports.isFtUserProfile = exports.isFtSession = exports.isFtAuthenticatedSession = void 0;
4
4
  const isObject = (o) => typeof o === "object" && o != null;
5
5
  const isBoolean = (o) => typeof o === "boolean";
6
6
  const isNumber = (o) => typeof o === "number";
@@ -36,3 +36,34 @@ const isFtMapAttachment = (o) => {
36
36
  && (o.viewerUrl == null || isString(o.viewerUrl));
37
37
  };
38
38
  exports.isFtMapAttachment = isFtMapAttachment;
39
+ const isFtPageConfiguration = (o) => {
40
+ return isObject(o)
41
+ && (o.parentsVisibility == null || (Array.isArray(o.parentsVisibility)
42
+ && o.parentsVisibility.every((v) => isBoolean(v))))
43
+ && (isBoolean(o.isVisible));
44
+ };
45
+ exports.isFtPageConfiguration = isFtPageConfiguration;
46
+ const isFtPaginatedToc = (o) => {
47
+ return isObject(o)
48
+ && ((0, exports.isFtPaginationConfiguration)(o.configuration))
49
+ && ((Array.isArray(o.paginatedToc)
50
+ && o.paginatedToc.every((v) => (0, exports.isFtPaginatedTocNode)(v))));
51
+ };
52
+ exports.isFtPaginatedToc = isFtPaginatedToc;
53
+ const isFtPaginatedTocNode = (o) => {
54
+ return isObject(o)
55
+ && (o.prettyUrl == null || isString(o.prettyUrl))
56
+ && (o.pageToc == null || (Array.isArray(o.pageToc)))
57
+ && (o.tocId == null || isString(o.tocId))
58
+ && ((Array.isArray(o.children)
59
+ && o.children.every((v) => (0, exports.isFtPaginatedTocNode)(v))))
60
+ && (o.pageConfiguration == null || (0, exports.isFtPageConfiguration)(o.pageConfiguration))
61
+ && (o.contentId == null || isString(o.contentId))
62
+ && (o.title == null || isString(o.title));
63
+ };
64
+ exports.isFtPaginatedTocNode = isFtPaginatedTocNode;
65
+ const isFtPaginationConfiguration = (o) => {
66
+ return isObject(o)
67
+ && (isBoolean(o.splitCurrentPageToc));
68
+ };
69
+ exports.isFtPaginationConfiguration = isFtPaginationConfiguration;
@@ -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,s=function(e,t){return/^\/\//.test(e)&&(e="https:"+e),i.call(this,e,t)};s.ponyfill=!0,e.exports=t=s,t.fetch=s,t.Headers=r.Headers,t.Request=r.Request,t.Response=r.Response,t.default=s}(r,r.exports);const i=r.exports,s=i.fetch.bind({});s.polyfill=!0,t.fetch||(t.fetch=s,t.Response=i.Response,t.Headers=i.Headers,t.Request=i.Request);const n=e=>"object"==typeof e&&null!=e,l=e=>"boolean"==typeof e,o=e=>"number"==typeof e,u=e=>"string"==typeof e,c=e=>n(e)&&u(e.topicStylesheetUrl)&&u(e.titleStylesheetUrl)&&Array.isArray(e.customCssClasses)&&e.customCssClasses.every((e=>u(e))),p=e=>n(e)&&(null==e.prettyUrl||u(e.prettyUrl))&&u(e.tocId)&&Array.isArray(e.children)&&e.children.every((e=>p(e)))&&u(e.contentId)&&(null==e.page||d(e.page))&&u(e.title),d=e=>n(e)&&l(e.visible)&&l(e.onItsOwn)&&(null==e.parentsVisibility||Array.isArray(e.parentsVisibility)&&e.parentsVisibility.every((e=>l(e))));var h;e.FtTopicContentTarget=void 0,(h=e.FtTopicContentTarget||(e.FtTopicContentTarget={})).THIRD_PARTY="THIRD_PARTY",h.OFF_THE_GRID="OFF_THE_GRID",h.CONTENT_PACKAGER="CONTENT_PACKAGER",h.PAGES="PAGES",h.DESIGNED_READER="DESIGNED_READER";const y=e=>n(e)&&o(e.count)&&u(e.label)&&(null==e.lang||u(e.lang)),g=e=>n(e)&&Array.isArray(e.values)&&e.values.every((e=>u(e)))&&(null==e.hierarchicalValues||Array.isArray(e.hierarchicalValues)&&e.hierarchicalValues.every((e=>Array.isArray(e)&&e.every((e=>u(e))))))&&u(e.label)&&u(e.key);var f;e.FtRatingType=void 0,(f=e.FtRatingType||(e.FtRatingType={})).STARS="STARS",f.LIKE="LIKE",f.DICHOTOMOUS="DICHOTOMOUS",f.NO_RATING="NO_RATING";const m=e=>["STARS","LIKE","DICHOTOMOUS","NO_RATING"].includes(e),A=e=>n(e)&&u(e.date)&&m(e.type)&&o(e.value),T=e=>n(e)&&(null==e.rating||A(e.rating))&&m(e.type),b=e=>n(e)&&u(e.date)&&u(e.tocId)&&m(e.type)&&o(e.value),R=e=>n(e)&&Array.isArray(e.ratings)&&e.ratings.every((e=>b(e)))&&m(e.type),F=e=>n(e)&&Array.isArray(e.filter)&&e.filter.every((e=>u(e)))&&Array.isArray(e.prior)&&e.prior.every((e=>u(e))),S=e=>n(e)&&l(e.negative)&&Array.isArray(e.values)&&e.values.every((e=>u(e)))&&u(e.key),v=e=>n(e)&&o(e.totalResultsCount)&&l(e.lastPage)&&o(e.currentPage)&&o(e.totalClustersCount);var E;e.FtEditorialType=void 0,(E=e.FtEditorialType||(e.FtEditorialType={})).ARTICLE="ARTICLE",E.BOOK="BOOK";const C=e=>["ARTICLE","BOOK"].includes(e);var U;e.FtOpenMode=void 0,(U=e.FtOpenMode||(e.FtOpenMode={})).FLUIDTOPICS="FLUIDTOPICS",U.EXTERNAL="EXTERNAL";const O=e=>["FLUIDTOPICS","EXTERNAL"].includes(e),D=e=>n(e)&&(null==e.perPage||o(e.perPage))&&o(e.page);var P;e.FtCollectionDocumentType=void 0,(P=e.FtCollectionDocumentType||(e.FtCollectionDocumentType={})).MAP="MAP",P.DOCUMENT="DOCUMENT",P.TOPIC="TOPIC",P.PERSONAL_BOOK="PERSONAL_BOOK",P.SHARED_BOOK="SHARED_BOOK";const I=e=>["MAP","DOCUMENT","TOPIC","PERSONAL_BOOK","SHARED_BOOK"].includes(e),k=e=>n(e)&&o(e.weight)&&u(e.value)&&u(e.key),w=e=>n(e)&&Array.isArray(e.entries)&&e.entries.every((e=>M(e)))&&(null==e.metadataVariableAxis||u(e.metadataVariableAxis)),M=e=>n(e)&&(null==e.document||L(e.document))&&(null==e.topic||N(e.topic))&&_(e.type)&&(null==e.map||$(e.map)),L=e=>n(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>g(e)))&&O(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),$=e=>n(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>g(e)))&&(null==e.openMode||O(e.openMode))&&C(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),N=e=>n(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>g(e)))&&O(e.openMode)&&u(e.contentId)&&Array.isArray(e.resources)&&e.resources.every((e=>V(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 x;e.FtSearchResultType=void 0,(x=e.FtSearchResultType||(e.FtSearchResultType={})).MAP="MAP",x.DOCUMENT="DOCUMENT",x.TOPIC="TOPIC";const _=e=>["MAP","DOCUMENT","TOPIC"].includes(e),H=e=>n(e)&&l(e.hierarchical)&&u(e.label)&&l(e.multiSelectionable)&&u(e.key)&&Array.isArray(e.rootNodes)&&e.rootNodes.every((e=>q(e))),B=e=>n(e)&&(null==e.maxDepth||o(e.maxDepth))&&u(e.id),q=e=>n(e)&&o(e.totalResultsCount)&&l(e.descendantSelected)&&Array.isArray(e.childNodes)&&e.childNodes.every((e=>q(e)))&&u(e.label)&&u(e.value)&&l(e.selected),G=e=>n(e)&&u(e.key),K=e=>n(e)&&u(e.suggestedQuery)&&u(e.htmlSuggestedQuery),V=e=>n(e)&&u(e.filename)&&u(e.resourceUrl)&&u(e.id)&&u(e.mimeType)&&u(e.resourceContentUrl)&&u(e.viewerUrl),j=e=>n(e)&&(null==e.filenameExtension||u(e.filenameExtension))&&(null==e.editorialType||C(e.editorialType))&&(null==e.mimeType||u(e.mimeType))&&_(e.type)&&u(e.value),z=e=>"object"==typeof e&&null!=e,J=e=>"boolean"==typeof e,X=e=>"number"==typeof e,Y=e=>"string"==typeof e,Q=e=>z(e)&&(null==e.emailAddress||Y(e.emailAddress))&&(null==e.displayName||Y(e.displayName))&&Array.isArray(e.roles)&&Y(e.userId),W="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 ee(e){return`${e}-FluidTopicsUnauthenticatedUserSearchPreferences`}const te="undefined"==typeof window?globalThis:window;class re extends Error{status;statusText;body;constructor(e,t,r){super(`${e} - ${t}: ${r}`),this.status=e,this.statusText=t,this.body=r}}async function ae(e){if(!e.ok)throw new re(e.status,e.statusText,await e.text());return e}function ie(e){return"application/json"===e.headers.get("Content-Type")?e.json():e.text()}class se{tenantBaseUrl;ftCallingApp;authorization={};searchLabel;get defaultHeaders(){return{...this.authorization,...this.searchLabel,"Ft-Calling-App":this.ftCallingApp}}constructor(e,t,r){e=e??te.__gwt_ft_moduleBase??te.fluidtopicsclient?.__moduleBase??te.__gwt_activeModules?.fluidtopicsclient?.moduleBase,this.tenantBaseUrl=e.trim().replace(/\/$/,""),r&&void 0!==te.location&&te.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")}getMapRating(e){return this.get(`/api/khub/maps/${e}/rating`)}getDocumentRating(e){return this.get(`/api/khub/documents/${e}/rating`)}rateMap(e,t,r){return this.post(`/api/khub/maps/${e}/rating`,{type:t,value:r})}unrateMap(e){return this.delete(`/api/khub/maps/${e}/rating`)}sendMapFeedback(e,t){return this.post(`/api/khub/maps/${e}/feedback`,{message:t})}rateTopic(e,t,r,a){return this.post(`/api/khub/maps/${e}/topics/${t}/rating`,{type:r,value:a})}unrateTopic(e,t){return this.delete(`/api/khub/maps/${e}/topics/${t}/rating`)}sendTopicFeedback(e,t,r){return this.post(`/api/khub/maps/${e}/topics/${t}/feedback`,{message:r})}rateDocument(e,t,r){return this.post(`/api/khub/documents/${e}/rating`,{type:t,value:r})}unrateDocument(e){return this.delete(`/api/khub/documents/${e}/rating`)}sendDocumentFeedback(e,t){return this.post(`/api/khub/documents/${e}/feedback`,{message:t})}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,s)=>{let n=new XMLHttpRequest;n.onload=()=>{if(n.status>=200&&n.status<300){let e="application/json"===n.getResponseHeader("Content-Type")?JSON.parse(n.responseText):n.responseText;i(e)}else s(new re(n.status,n.statusText,n.responseText))},n.upload.onprogress=e=>a(e),n.open(e,this.tenantBaseUrl+t,!0),n.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(ae).then(ie)}fetchRawData(e){return fetch(this.tenantBaseUrl+e,{headers:this.defaultHeaders}).then(ae).then((e=>e.arrayBuffer()))}}e.FluidTopicsApi=se,e.HttpError=re,e.addUnauthenticatedUserSearchPreferencesChangeHandler=function(e,t){if(W.localStorage){const r=ee(e),a=e=>{e.storageArea===W.localStorage&&e.key===r&&t(JSON.parse(e.newValue??"{}"))};return W.addEventListener("storage",a),{removeHandler:()=>W.removeEventListener("storage",a)}}console.error("Cannot handle unauthenticated preferences: local storage is unavailable.")},e.default=se,e.getUnauthenticatedUserSearchPreferences=function(e){if(W.localStorage)return JSON.parse(W.localStorage.getItem(ee(e))??"{}");console.error("Cannot get unauthenticated preferences: local storage is unavailable.")},e.isFtAuthenticatedSession=e=>z(e)&&Q(e.profile),e.isFtAuthenticationIdentifier=e=>n(e)&&u(e.identifier)&&u(e.realm),e.isFtCollectionDocument=e=>n(e)&&l(e.deleted)&&(null==e.apiUrl||u(e.apiUrl))&&(null==e.portalUrl||u(e.portalUrl))&&u(e.id)&&u(e.title)&&I(e.type),e.isFtCollectionDocumentType=I,e.isFtCredentials=e=>n(e)&&u(e.password)&&(null==e.newPassword||u(e.newPassword))&&l(e.rememberMe)&&u(e.login),e.isFtEditorialType=C,e.isFtFeedbackCreation=e=>n(e)&&u(e.message),e.isFtMap=e=>n(e)&&(null==e.prettyUrl||u(e.prettyUrl))&&Array.isArray(e.metadata)&&e.metadata.every((e=>g(e)))&&O(e.openMode)&&u(e.topicsApiEndpoint)&&(null==e.description||u(e.description))&&u(e.attachmentsApiEndpoint)&&C(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)&&c(e.contentStyles)&&(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=>z(e)&&Y(e.file)&&(null==e.size||X(e.size))&&J(e.externalLink)&&Y(e.name)&&Y(e.id)&&(null==e.mimeType||Y(e.mimeType))&&(null==e.viewerUrl||Y(e.viewerUrl)),e.isFtMapResource=e=>n(e)&&u(e.contentUrl)&&u(e.filename)&&u(e.id)&&u(e.mimeType),e.isFtMapStyles=c,e.isFtMetadata=g,e.isFtMetadataPreferenceConfiguration=F,e.isFtOpenMode=O,e.isFtPageRequest=D,e.isFtPublicationRating=A,e.isFtPublicationRatingSummary=T,e.isFtRatingCreation=e=>n(e)&&m(e.type)&&o(e.value),e.isFtRatingSummary=e=>n(e)&&(null==e.topics||R(e.topics))&&T(e.publication),e.isFtRatingType=m,e.isFtSearchFacet=H,e.isFtSearchFacetConf=B,e.isFtSearchFacetEntry=q,e.isFtSearchFilter=S,e.isFtSearchLocale=y,e.isFtSearchLocales=e=>n(e)&&Array.isArray(e.contentLocales)&&e.contentLocales.every((e=>y(e))),e.isFtSearchPreferencesConfiguration=e=>n(e)&&n(e.metadata)&&Object.keys(e.metadata).every((e=>u(e)))&&Object.values(e.metadata).every((e=>F(e))),e.isFtSearchPreset=e=>n(e)&&u(e.name)&&Array.isArray(e.filters)&&e.filters.every((e=>S(e)))&&o(e.priority)&&(null==e.contentLocale||u(e.contentLocale)),e.isFtSearchPrior=k,e.isFtSearchRequest=e=>n(e)&&u(e.query)&&D(e.paging)&&Array.isArray(e.filters)&&e.filters.every((e=>S(e)))&&Array.isArray(e.sort)&&e.sort.every((e=>G(e)))&&(null==e.uiLocale||u(e.uiLocale))&&(null==e.contentLocale||u(e.contentLocale))&&(null==e.priors||Array.isArray(e.priors)&&e.priors.every((e=>k(e))))&&Array.isArray(e.facets)&&e.facets.every((e=>B(e))),e.isFtSearchResultCluster=w,e.isFtSearchResultClusterEntry=M,e.isFtSearchResultMap=$,e.isFtSearchResultTopic=N,e.isFtSearchResultType=_,e.isFtSearchResultUnstructuredDocument=L,e.isFtSearchResults=e=>n(e)&&(null==e.spellcheck||K(e.spellcheck))&&v(e.paging)&&Array.isArray(e.results)&&e.results.every((e=>w(e)))&&Array.isArray(e.facets)&&e.facets.every((e=>H(e))),e.isFtSearchResultsPageInfo=v,e.isFtSearchSortCriterion=G,e.isFtSession=e=>z(e)&&X(e.idleTimeoutInMillis)&&(null==e.profile||Q(e.profile))&&J(e.sessionAuthenticated),e.isFtSpellcheck=K,e.isFtSuggestRequest=e=>n(e)&&u(e.input)&&Array.isArray(e.filters)&&e.filters.every((e=>S(e)))&&Array.isArray(e.sort)&&e.sort.every((e=>G(e)))&&(null==e.maxCount||o(e.maxCount))&&(null==e.contentLocale||u(e.contentLocale)),e.isFtSuggestResult=j,e.isFtSuggestResults=e=>n(e)&&Array.isArray(e.suggestions)&&e.suggestions.every((e=>j(e))),e.isFtTocNode=p,e.isFtTocPage=d,e.isFtTopic=e=>n(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>g(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.isFtTopicRating=b,e.isFtTopicResource=V,e.isFtTopicsRatingSummary=R,e.isFtUnstructuredDocument=e=>n(e)&&(null==e.prettyUrl||u(e.prettyUrl))&&Array.isArray(e.metadata)&&e.metadata.every((e=>g(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=Q,e.setUnauthenticatedUserSearchPreferences=function(e,t){if(W.localStorage){let r={...t,metadata:Z(t.metadata??{})};const a=ee(e),i=JSON.stringify(r);return W.localStorage.setItem(a,i),W.dispatchEvent(new StorageEvent("storage",{key:a,newValue:i,storageArea:W.localStorage,url:W.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:{},n={exports:{}},a={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}(a,a.exports),function(e,t){const n=a.exports,i=n.default||n,s=function(e,t){return/^\/\//.test(e)&&(e="https:"+e),i.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 i=n.exports,s=i.fetch.bind({});s.polyfill=!0,t.fetch||(t.fetch=s,t.Response=i.Response,t.Headers=i.Headers,t.Request=i.Request);const r=e=>"object"==typeof e&&null!=e,o=e=>"boolean"==typeof e,l=e=>"number"==typeof e,u=e=>"string"==typeof e,c=e=>r(e)&&u(e.topicStylesheetUrl)&&u(e.titleStylesheetUrl)&&Array.isArray(e.customCssClasses)&&e.customCssClasses.every((e=>u(e))),p=e=>r(e)&&(null==e.prettyUrl||u(e.prettyUrl))&&u(e.tocId)&&Array.isArray(e.children)&&e.children.every((e=>p(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",d.CONTENT_PACKAGER="CONTENT_PACKAGER",d.PAGES="PAGES",d.DESIGNED_READER="DESIGNED_READER";const h=e=>r(e)&&l(e.count)&&u(e.label)&&(null==e.lang||u(e.lang)),y=e=>r(e)&&Array.isArray(e.values)&&e.values.every((e=>u(e)))&&(null==e.hierarchicalValues||Array.isArray(e.hierarchicalValues)&&e.hierarchicalValues.every((e=>Array.isArray(e)&&e.every((e=>u(e))))))&&u(e.label)&&u(e.key);var m;e.FtRatingType=void 0,(m=e.FtRatingType||(e.FtRatingType={})).STARS="STARS",m.LIKE="LIKE",m.DICHOTOMOUS="DICHOTOMOUS",m.NO_RATING="NO_RATING";const g=e=>["STARS","LIKE","DICHOTOMOUS","NO_RATING"].includes(e),f=e=>r(e)&&u(e.date)&&g(e.type)&&l(e.value),A=e=>r(e)&&(null==e.rating||f(e.rating))&&g(e.type),b=e=>r(e)&&u(e.date)&&u(e.tocId)&&g(e.type)&&l(e.value),T=e=>r(e)&&Array.isArray(e.ratings)&&e.ratings.every((e=>b(e)))&&g(e.type),I=e=>r(e)&&Array.isArray(e.filter)&&e.filter.every((e=>u(e)))&&Array.isArray(e.prior)&&e.prior.every((e=>u(e))),F=e=>r(e)&&o(e.negative)&&Array.isArray(e.values)&&e.values.every((e=>u(e)))&&u(e.key),R=e=>r(e)&&l(e.totalResultsCount)&&o(e.lastPage)&&l(e.currentPage)&&l(e.totalClustersCount);var S;e.FtEditorialType=void 0,(S=e.FtEditorialType||(e.FtEditorialType={})).ARTICLE="ARTICLE",S.BOOK="BOOK";const k=e=>["ARTICLE","BOOK"].includes(e);var v;e.FtOpenMode=void 0,(v=e.FtOpenMode||(e.FtOpenMode={})).FLUIDTOPICS="FLUIDTOPICS",v.EXTERNAL="EXTERNAL";const C=e=>["FLUIDTOPICS","EXTERNAL"].includes(e),E=e=>r(e)&&(null==e.perPage||l(e.perPage))&&l(e.page);var U;e.FtCollectionDocumentType=void 0,(U=e.FtCollectionDocumentType||(e.FtCollectionDocumentType={})).MAP="MAP",U.DOCUMENT="DOCUMENT",U.TOPIC="TOPIC",U.PERSONAL_BOOK="PERSONAL_BOOK",U.SHARED_BOOK="SHARED_BOOK";const O=e=>["MAP","DOCUMENT","TOPIC","PERSONAL_BOOK","SHARED_BOOK"].includes(e),P=e=>r(e)&&l(e.weight)&&u(e.value)&&u(e.key),D=e=>r(e)&&Array.isArray(e.entries)&&e.entries.every((e=>M(e)))&&(null==e.metadataVariableAxis||u(e.metadataVariableAxis)),M=e=>r(e)&&(null==e.document||w(e.document))&&(null==e.topic||N(e.topic))&&$(e.type)&&(null==e.map||L(e.map)),w=e=>r(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>y(e)))&&C(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),L=e=>r(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>y(e)))&&(null==e.openMode||C(e.openMode))&&k(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),N=e=>r(e)&&Array.isArray(e.metadata)&&e.metadata.every((e=>y(e)))&&C(e.openMode)&&u(e.contentId)&&Array.isArray(e.resources)&&e.resources.every((e=>K(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 x;e.FtSearchResultType=void 0,(x=e.FtSearchResultType||(e.FtSearchResultType={})).MAP="MAP",x.DOCUMENT="DOCUMENT",x.TOPIC="TOPIC";const $=e=>["MAP","DOCUMENT","TOPIC"].includes(e),_=e=>r(e)&&o(e.hierarchical)&&u(e.label)&&o(e.multiSelectionable)&&u(e.key)&&Array.isArray(e.rootNodes)&&e.rootNodes.every((e=>B(e))),H=e=>r(e)&&(null==e.maxDepth||l(e.maxDepth))&&u(e.id),B=e=>r(e)&&l(e.totalResultsCount)&&o(e.descendantSelected)&&Array.isArray(e.childNodes)&&e.childNodes.every((e=>B(e)))&&u(e.label)&&u(e.value)&&o(e.selected),q=e=>r(e)&&u(e.key),G=e=>r(e)&&u(e.suggestedQuery)&&u(e.htmlSuggestedQuery),K=e=>r(e)&&u(e.filename)&&u(e.resourceUrl)&&u(e.id)&&u(e.mimeType)&&u(e.resourceContentUrl)&&u(e.viewerUrl),V=e=>r(e)&&(null==e.filenameExtension||u(e.filenameExtension))&&(null==e.editorialType||k(e.editorialType))&&(null==e.mimeType||u(e.mimeType))&&$(e.type)&&u(e.value),j=e=>"object"==typeof e&&null!=e,z=e=>"boolean"==typeof e,J=e=>"number"==typeof e,X=e=>"string"==typeof e,Y=e=>j(e)&&(null==e.emailAddress||X(e.emailAddress))&&(null==e.displayName||X(e.displayName))&&Array.isArray(e.roles)&&X(e.userId),Q=e=>j(e)&&(null==e.parentsVisibility||Array.isArray(e.parentsVisibility)&&e.parentsVisibility.every((e=>z(e))))&&z(e.isVisible),W=e=>j(e)&&(null==e.prettyUrl||X(e.prettyUrl))&&(null==e.pageToc||Array.isArray(e.pageToc))&&(null==e.tocId||X(e.tocId))&&Array.isArray(e.children)&&e.children.every((e=>W(e)))&&(null==e.pageConfiguration||Q(e.pageConfiguration))&&(null==e.contentId||X(e.contentId))&&(null==e.title||X(e.title)),Z=e=>j(e)&&z(e.splitCurrentPageToc),ee="undefined"==typeof window?globalThis:window;function te(e){let t={};for(let n in e){let a=e[n];("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[n]=a}return t}function ne(e){return`${e}-FluidTopicsUnauthenticatedUserSearchPreferences`}const ae="undefined"==typeof window?globalThis:window;class ie extends Error{status;statusText;body;constructor(e,t,n){super(`${e} - ${t}: ${n}`),this.status=e,this.statusText=t,this.body=n}}async function se(e){if(!e.ok)throw new ie(e.status,e.statusText,await e.text());return e}function re(e){return"application/json"===e.headers.get("Content-Type")?e.json():e.text()}class oe{tenantBaseUrl;ftCallingApp;authorization={};searchLabel;endpoints={authentication:{login:"api/authentication/login",logout:"api/authentication/logout",currentSession:"api/authentication/current-session"},khub:{maps:{mapId:e=>({info:`api/khub/maps/${e}`,toc:`api/khub/maps/${e}/toc`,pages:`api/khub/maps/${e}/pages`,feedback:`api/khub/maps/${e}/feedback`,rating:`api/khub/maps/${e}/rating`,attachments:{list:`api/khub/maps/${e}/attachments`,attachmentId:t=>({content:`api/khub/maps/${e}/attachments/${t}/content`})},resources:{list:`api/khub/maps/${e}/resources`,resourceId:t=>({content:`api/khub/maps/${e}/resources/${t}/content`})},topics:{contentId:t=>({info:`api/khub/maps/${e}/topics/${t}`,content:`api/khub/maps/${e}/topics/${t}/content`}),tocId:t=>({feedback:`api/khub/maps/${e}/topics/${t}/feedback`,rating:`api/khub/maps/${e}/topics/${t}/rating`})}})},documents:{documentId:e=>({info:`api/khub/documents/${e}`,content:`api/khub/documents/${e}/content`,text:`api/khub/documents/${e}/content/text`,feedback:`api/khub/documents/${e}/feedback`,rating:`api/khub/documents/${e}/rating`})},suggest:"api/khub/suggest",clusteredSearch:"api/khub/clustered-search",locales:"api/khub/locales"},users:{userId:e=>({collections:{collectionId:t=>({documents:`api/users/${e}/collections/${t}/documents`})}})},stylesheets:{fonts:"api/stylesheets/fonts.css",theme:"api/stylesheets/theme.css",content:{title:"api/stylesheets/content/title.css",topic:"api/stylesheets/content/topic.css"}}};get defaultHeaders(){return{...this.authorization,...this.searchLabel,"Ft-Calling-App":this.ftCallingApp}}constructor(e,t,n){e=(e??ae.__gwt_ft_moduleBase??ae.fluidtopicsclient?.__moduleBase??ae.__gwt_activeModules?.fluidtopicsclient?.moduleBase??"").trim(),this.tenantBaseUrl=e.endsWith("/")?e:e+"/",n&&void 0!==ae.location&&ae.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 n;this.authorization={Authorization:"Basic "+(n=`${e}:${t}`,"undefined"!=typeof Buffer?Buffer.from(n).toString("base64"):btoa(n))}}clearAuthentication(){this.authorization=void 0}setSearchLabel(e){this.searchLabel={"FT-search-label":e}}clearSearchLabel(){this.searchLabel=void 0}login(e,t){let n={login:e,password:t,rememberMe:!0};return this.post(this.endpoints.authentication.login,n).then((n=>(this.setCredentials(e,t),n)))}logout(){return this.post(this.endpoints.authentication.logout).then((()=>this.clearAuthentication()))}getCurrentSession(){return this.get(this.endpoints.authentication.currentSession)}getMap(e){return this.get(this.endpoints.khub.maps.mapId(e).info)}getTableOfContent(e){return this.get(this.endpoints.khub.maps.mapId(e).toc)}getPages(e){return this.get(this.endpoints.khub.maps.mapId(e).pages)}getTopic(e,t){return this.get(this.endpoints.khub.maps.mapId(e).topics.contentId(t).info)}getTopicHTMLContent(e,t,n){return this.get(this.endpoints.khub.maps.mapId(e).topics.contentId(t).content+(n?"?target="+n:""))}getMapAttachments(e){return this.get(this.endpoints.khub.maps.mapId(e).attachments.list)}getMapAttachmentContent(e,t){return this.fetchRawData(this.endpoints.khub.maps.mapId(e).attachments.attachmentId(t).content)}getMapResources(e){return this.get(this.endpoints.khub.maps.mapId(e).resources.list)}getMapResourceContent(e,t){return this.fetchRawData(this.endpoints.khub.maps.mapId(e).resources.resourceId(t).content)}getUnstructuredDocument(e){return this.get(this.endpoints.khub.documents.documentId(e).info)}getUnstructuredDocumentContent(e){return this.fetchRawData(this.endpoints.khub.documents.documentId(e).content)}getUnstructuredDocumentTextContent(e){return this.get(this.endpoints.khub.documents.documentId(e).text)}getCollectionDocuments(e,t){return this.get(this.endpoints.users.userId(e).collections.collectionId(t).documents)}getSuggestions(e){return this.post(this.endpoints.khub.suggest,e)}search(e){return this.post(this.endpoints.khub.clusteredSearch,e)}getAvailableSearchLocales(){return this.get(this.endpoints.khub.locales)}getMapRating(e){return this.get(this.endpoints.khub.maps.mapId(e).rating)}rateMap(e,t,n){return this.post(this.endpoints.khub.maps.mapId(e).rating,{type:t,value:n})}unrateMap(e){return this.delete(this.endpoints.khub.maps.mapId(e).rating)}sendMapFeedback(e,t){return this.post(this.endpoints.khub.maps.mapId(e).feedback,{message:t})}rateTopic(e,t,n,a){return this.post(this.endpoints.khub.maps.mapId(e).topics.tocId(t).rating,{type:n,value:a})}unrateTopic(e,t){return this.delete(this.endpoints.khub.maps.mapId(e).topics.tocId(t).rating)}sendTopicFeedback(e,t,n){return this.post(this.endpoints.khub.maps.mapId(e).topics.tocId(t).feedback,{message:n})}getDocumentRating(e){return this.get(this.endpoints.khub.documents.documentId(e).rating)}rateDocument(e,t,n){return this.post(this.endpoints.khub.documents.documentId(e).rating,{type:t,value:n})}unrateDocument(e){return this.delete(this.endpoints.khub.documents.documentId(e).rating)}sendDocumentFeedback(e,t){return this.post(this.endpoints.khub.documents.documentId(e).feedback,{message:t})}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)}makeAbsolute(e){return this.tenantBaseUrl+e.replace(/^\//,"")}async fetch(e,t){const n=t;return await fetch(this.makeAbsolute(e),{...n??{},headers:{...this.defaultHeaders,...n?.headers??{}}})}upload(e,t,n,a=(()=>{})){return"undefined"!=typeof XMLHttpRequest?new Promise(((i,s)=>{let r=new XMLHttpRequest;r.onload=()=>{if(r.status>=200&&r.status<300){let e="application/json"===r.getResponseHeader("Content-Type")?JSON.parse(r.responseText):r.responseText;i(e)}else s(new ie(r.status,r.statusText,r.responseText))},r.upload.onprogress=e=>a(e),r.open(e,this.makeAbsolute(t),!0),r.send(n)})):this.fetch(t,{method:e,body:n}).then(se).then(re)}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(se).then(re)}fetchRawData(e){return fetch(this.makeAbsolute(e),{headers:this.defaultHeaders}).then(se).then((e=>e.arrayBuffer()))}}e.FluidTopicsApi=oe,e.HttpError=ie,e.addUnauthenticatedUserSearchPreferencesChangeHandler=function(e,t){if(ee.localStorage){const n=ne(e),a=e=>{e.storageArea===ee.localStorage&&e.key===n&&t(JSON.parse(e.newValue??"{}"))};return ee.addEventListener("storage",a),{removeHandler:()=>ee.removeEventListener("storage",a)}}console.error("Cannot handle unauthenticated preferences: local storage is unavailable.")},e.default=oe,e.getUnauthenticatedUserSearchPreferences=function(e){if(ee.localStorage)return JSON.parse(ee.localStorage.getItem(ne(e))??"{}");console.error("Cannot get unauthenticated preferences: local storage is unavailable.")},e.isFtAuthenticatedSession=e=>j(e)&&Y(e.profile),e.isFtAuthenticationIdentifier=e=>r(e)&&u(e.identifier)&&u(e.realm),e.isFtCollectionDocument=e=>r(e)&&o(e.deleted)&&(null==e.apiUrl||u(e.apiUrl))&&(null==e.portalUrl||u(e.portalUrl))&&u(e.id)&&u(e.title)&&O(e.type),e.isFtCollectionDocumentType=O,e.isFtCredentials=e=>r(e)&&u(e.password)&&(null==e.newPassword||u(e.newPassword))&&o(e.rememberMe)&&u(e.login),e.isFtEditorialType=k,e.isFtFeedbackCreation=e=>r(e)&&u(e.message),e.isFtMap=e=>r(e)&&(null==e.prettyUrl||u(e.prettyUrl))&&Array.isArray(e.metadata)&&e.metadata.every((e=>y(e)))&&C(e.openMode)&&u(e.topicsApiEndpoint)&&(null==e.description||u(e.description))&&u(e.attachmentsApiEndpoint)&&k(e.editorialType)&&u(e.baseId)&&u(e.clusterId)&&(null==e.shouldSplitCurrentPageToc||o(e.shouldSplitCurrentPageToc))&&u(e.title)&&u(e.lastPublication)&&u(e.lastEdition)&&u(e.originId)&&u(e.rightsApiEndpoint)&&c(e.contentStyles)&&(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=>j(e)&&X(e.file)&&(null==e.size||J(e.size))&&z(e.externalLink)&&X(e.name)&&X(e.id)&&(null==e.mimeType||X(e.mimeType))&&(null==e.viewerUrl||X(e.viewerUrl)),e.isFtMapResource=e=>r(e)&&u(e.contentUrl)&&u(e.filename)&&u(e.id)&&u(e.mimeType),e.isFtMapStyles=c,e.isFtMetadata=y,e.isFtMetadataPreferenceConfiguration=I,e.isFtOpenMode=C,e.isFtPageConfiguration=Q,e.isFtPageRequest=E,e.isFtPaginatedToc=e=>j(e)&&Z(e.configuration)&&Array.isArray(e.paginatedToc)&&e.paginatedToc.every((e=>W(e))),e.isFtPaginatedTocNode=W,e.isFtPaginationConfiguration=Z,e.isFtPublicationRating=f,e.isFtPublicationRatingSummary=A,e.isFtRatingCreation=e=>r(e)&&g(e.type)&&l(e.value),e.isFtRatingSummary=e=>r(e)&&(null==e.topics||T(e.topics))&&A(e.publication),e.isFtRatingType=g,e.isFtSearchFacet=_,e.isFtSearchFacetConf=H,e.isFtSearchFacetEntry=B,e.isFtSearchFilter=F,e.isFtSearchLocale=h,e.isFtSearchLocales=e=>r(e)&&Array.isArray(e.contentLocales)&&e.contentLocales.every((e=>h(e))),e.isFtSearchPreferencesConfiguration=e=>r(e)&&r(e.metadata)&&Object.keys(e.metadata).every((e=>u(e)))&&Object.values(e.metadata).every((e=>I(e))),e.isFtSearchPreset=e=>r(e)&&u(e.name)&&Array.isArray(e.filters)&&e.filters.every((e=>F(e)))&&l(e.priority)&&(null==e.contentLocale||u(e.contentLocale)),e.isFtSearchPrior=P,e.isFtSearchRequest=e=>r(e)&&u(e.query)&&E(e.paging)&&Array.isArray(e.filters)&&e.filters.every((e=>F(e)))&&Array.isArray(e.sort)&&e.sort.every((e=>q(e)))&&(null==e.uiLocale||u(e.uiLocale))&&(null==e.contentLocale||u(e.contentLocale))&&(null==e.priors||Array.isArray(e.priors)&&e.priors.every((e=>P(e))))&&Array.isArray(e.facets)&&e.facets.every((e=>H(e))),e.isFtSearchResultCluster=D,e.isFtSearchResultClusterEntry=M,e.isFtSearchResultMap=L,e.isFtSearchResultTopic=N,e.isFtSearchResultType=$,e.isFtSearchResultUnstructuredDocument=w,e.isFtSearchResults=e=>r(e)&&(null==e.spellcheck||G(e.spellcheck))&&R(e.paging)&&Array.isArray(e.results)&&e.results.every((e=>D(e)))&&Array.isArray(e.facets)&&e.facets.every((e=>_(e))),e.isFtSearchResultsPageInfo=R,e.isFtSearchSortCriterion=q,e.isFtSession=e=>j(e)&&J(e.idleTimeoutInMillis)&&(null==e.profile||Y(e.profile))&&z(e.sessionAuthenticated),e.isFtSpellcheck=G,e.isFtSuggestRequest=e=>r(e)&&u(e.input)&&Array.isArray(e.filters)&&e.filters.every((e=>F(e)))&&Array.isArray(e.sort)&&e.sort.every((e=>q(e)))&&(null==e.maxCount||l(e.maxCount))&&(null==e.contentLocale||u(e.contentLocale)),e.isFtSuggestResult=V,e.isFtSuggestResults=e=>r(e)&&Array.isArray(e.suggestions)&&e.suggestions.every((e=>V(e))),e.isFtTocNode=p,e.isFtTopic=e=>r(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.isFtTopicRating=b,e.isFtTopicResource=K,e.isFtTopicsRatingSummary=T,e.isFtUnstructuredDocument=e=>r(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=Y,e.setUnauthenticatedUserSearchPreferences=function(e,t){if(ee.localStorage){let n={...t,metadata:te(t.metadata??{})};const a=ne(e),i=JSON.stringify(n);return ee.localStorage.setItem(a,i),ee.dispatchEvent(new StorageEvent("storage",{key:a,newValue:i,storageArea:ee.localStorage,url:ee.location.href})),n}console.error("Cannot set unauthenticated preferences: local storage is unavailable.")}}));
@@ -1,6 +1,6 @@
1
1
  import "cross-fetch/polyfill";
2
2
  import { FtCollectionDocument, FtMap, FtMapResource, FtRatingSummary, FtRatingType, FtSearchLocales, FtSearchRequest, FtSearchResults, FtSuggestRequest, FtSuggestResults, FtTocNode, FtTopic, FtTopicContentTarget, FtTopicContentTargetKeys, FtUnstructuredDocument } from "./types/ft-common/public";
3
- import { FtAuthenticatedSession, FtMapAttachment, FtSession } from "./types/ft-server/public";
3
+ import { FtAuthenticatedSession, FtMapAttachment, FtPaginatedToc, FtSession } from "./types/ft-server/public";
4
4
  export * from "./types/ft-common/public";
5
5
  export * from "./types/ft-server/public";
6
6
  export * from "./preferences/unauthenticated-preferences";
@@ -15,6 +15,75 @@ export declare class FluidTopicsApi {
15
15
  private readonly ftCallingApp;
16
16
  private authorization;
17
17
  private searchLabel;
18
+ readonly endpoints: {
19
+ authentication: {
20
+ login: string;
21
+ logout: string;
22
+ currentSession: string;
23
+ };
24
+ khub: {
25
+ maps: {
26
+ mapId: (mapId: string) => {
27
+ info: string;
28
+ toc: string;
29
+ pages: string;
30
+ feedback: string;
31
+ rating: string;
32
+ attachments: {
33
+ list: string;
34
+ attachmentId: (attachmentId: string) => {
35
+ content: string;
36
+ };
37
+ };
38
+ resources: {
39
+ list: string;
40
+ resourceId: (resourceId: string) => {
41
+ content: string;
42
+ };
43
+ };
44
+ topics: {
45
+ contentId: (contentId: string) => {
46
+ info: string;
47
+ content: string;
48
+ };
49
+ tocId: (tocId: string) => {
50
+ feedback: string;
51
+ rating: string;
52
+ };
53
+ };
54
+ };
55
+ };
56
+ documents: {
57
+ documentId: (documentId: string) => {
58
+ info: string;
59
+ content: string;
60
+ text: string;
61
+ feedback: string;
62
+ rating: string;
63
+ };
64
+ };
65
+ suggest: string;
66
+ clusteredSearch: string;
67
+ locales: string;
68
+ };
69
+ users: {
70
+ userId: (userId: string) => {
71
+ collections: {
72
+ collectionId: (collectionId: string) => {
73
+ documents: string;
74
+ };
75
+ };
76
+ };
77
+ };
78
+ stylesheets: {
79
+ fonts: string;
80
+ theme: string;
81
+ content: {
82
+ title: string;
83
+ topic: string;
84
+ };
85
+ };
86
+ };
18
87
  private get defaultHeaders();
19
88
  constructor(tenantBaseUrl: string, integrationIdentifier: string, overrideIdentifierIfOnTenant?: boolean);
20
89
  setApiKey(apiKey: string): void;
@@ -27,6 +96,7 @@ export declare class FluidTopicsApi {
27
96
  getCurrentSession(): Promise<FtSession>;
28
97
  getMap(mapId: string): Promise<FtMap>;
29
98
  getTableOfContent(mapId: string): Promise<Array<FtTocNode>>;
99
+ getPages(mapId: string): Promise<FtPaginatedToc>;
30
100
  getTopic(mapId: string, topicContentId: string): Promise<FtTopic>;
31
101
  getTopicHTMLContent(mapId: string, topicContentId: string, target?: FtTopicContentTarget | FtTopicContentTargetKeys): Promise<string>;
32
102
  getMapAttachments(mapId: string): Promise<Array<FtMapAttachment>>;
@@ -41,13 +111,13 @@ export declare class FluidTopicsApi {
41
111
  search(request: FtSearchRequest): Promise<FtSearchResults>;
42
112
  getAvailableSearchLocales(): Promise<FtSearchLocales>;
43
113
  getMapRating(mapId: string): Promise<FtRatingSummary>;
44
- getDocumentRating(docId: string): Promise<FtRatingSummary>;
45
114
  rateMap(mapId: string, type: FtRatingType, value: number): Promise<void>;
46
115
  unrateMap(mapId: string): Promise<void>;
47
116
  sendMapFeedback(mapId: string, message: string): Promise<void>;
48
117
  rateTopic(mapId: string, tocId: string, type: FtRatingType, value: number): Promise<void>;
49
118
  unrateTopic(mapId: string, tocId: string): Promise<void>;
50
119
  sendTopicFeedback(mapId: string, tocId: string, message: string): Promise<void>;
120
+ getDocumentRating(docId: string): Promise<FtRatingSummary>;
51
121
  rateDocument(docId: string, type: FtRatingType, value: number): Promise<void>;
52
122
  unrateDocument(docId: string): Promise<void>;
53
123
  sendDocumentFeedback(docId: string, message: string): Promise<void>;
@@ -55,8 +125,9 @@ export declare class FluidTopicsApi {
55
125
  post<T>(endpoint: string, data?: any): Promise<T>;
56
126
  put<T>(endpoint: string, data?: any): Promise<T>;
57
127
  delete<T>(endpoint: string): Promise<T>;
128
+ makeAbsolute(endpoint: string): string;
58
129
  fetch<FetchRequestInit, FetchResponse>(endpoint: string, init?: FetchRequestInit): Promise<FetchResponse>;
59
- upload<T>(method: string, endpoint: string, body: Document | XMLHttpRequestBodyInit, onProgress?: (e: ProgressEvent) => void): Promise<T>;
130
+ upload<T>(method: string, endpoint: string, body: any, onProgress?: (e: any) => void): Promise<T>;
60
131
  private makeRequest;
61
132
  private fetchRawData;
62
133
  }
package/dist/mjs/index.js CHANGED
@@ -31,6 +31,75 @@ export class FluidTopicsApi {
31
31
  ftCallingApp;
32
32
  authorization = {};
33
33
  searchLabel;
34
+ endpoints = {
35
+ authentication: {
36
+ login: `api/authentication/login`,
37
+ logout: `api/authentication/logout`,
38
+ currentSession: `api/authentication/current-session`,
39
+ },
40
+ khub: {
41
+ maps: {
42
+ mapId: (mapId) => ({
43
+ info: `api/khub/maps/${mapId}`,
44
+ toc: `api/khub/maps/${mapId}/toc`,
45
+ pages: `api/khub/maps/${mapId}/pages`,
46
+ feedback: `api/khub/maps/${mapId}/feedback`,
47
+ rating: `api/khub/maps/${mapId}/rating`,
48
+ attachments: {
49
+ list: `api/khub/maps/${mapId}/attachments`,
50
+ attachmentId: (attachmentId) => ({
51
+ content: `api/khub/maps/${mapId}/attachments/${attachmentId}/content`,
52
+ })
53
+ },
54
+ resources: {
55
+ list: `api/khub/maps/${mapId}/resources`,
56
+ resourceId: (resourceId) => ({
57
+ content: `api/khub/maps/${mapId}/resources/${resourceId}/content`,
58
+ })
59
+ },
60
+ topics: {
61
+ contentId: (contentId) => ({
62
+ info: `api/khub/maps/${mapId}/topics/${contentId}`,
63
+ content: `api/khub/maps/${mapId}/topics/${contentId}/content`,
64
+ }),
65
+ tocId: (tocId) => ({
66
+ feedback: `api/khub/maps/${mapId}/topics/${tocId}/feedback`,
67
+ rating: `api/khub/maps/${mapId}/topics/${tocId}/rating`,
68
+ })
69
+ },
70
+ })
71
+ },
72
+ documents: {
73
+ documentId: (documentId) => ({
74
+ info: `api/khub/documents/${documentId}`,
75
+ content: `api/khub/documents/${documentId}/content`,
76
+ text: `api/khub/documents/${documentId}/content/text`,
77
+ feedback: `api/khub/documents/${documentId}/feedback`,
78
+ rating: `api/khub/documents/${documentId}/rating`,
79
+ })
80
+ },
81
+ suggest: `api/khub/suggest`,
82
+ clusteredSearch: `api/khub/clustered-search`,
83
+ locales: `api/khub/locales`,
84
+ },
85
+ users: {
86
+ userId: (userId) => ({
87
+ collections: {
88
+ collectionId: (collectionId) => ({
89
+ documents: `api/users/${userId}/collections/${collectionId}/documents`,
90
+ })
91
+ }
92
+ })
93
+ },
94
+ stylesheets: {
95
+ fonts: `api/stylesheets/fonts.css`,
96
+ theme: `api/stylesheets/theme.css`,
97
+ content: {
98
+ title: `api/stylesheets/content/title.css`,
99
+ topic: `api/stylesheets/content/topic.css`,
100
+ },
101
+ },
102
+ };
34
103
  get defaultHeaders() {
35
104
  return {
36
105
  ...this.authorization,
@@ -40,9 +109,9 @@ export class FluidTopicsApi {
40
109
  }
41
110
  constructor(tenantBaseUrl, integrationIdentifier, overrideIdentifierIfOnTenant) {
42
111
  //@ts-ignore
43
- tenantBaseUrl = tenantBaseUrl ?? wnd.__gwt_ft_moduleBase ?? wnd.fluidtopicsclient?.__moduleBase ?? wnd.__gwt_activeModules?.fluidtopicsclient?.moduleBase;
44
- this.tenantBaseUrl = tenantBaseUrl.trim().replace(/\/$/, "");
45
- if (overrideIdentifierIfOnTenant && typeof wnd.location !== "undefined" && wnd.location.href.startsWith(this.tenantBaseUrl + "/")) {
112
+ tenantBaseUrl = (tenantBaseUrl ?? wnd.__gwt_ft_moduleBase ?? wnd.fluidtopicsclient?.__moduleBase ?? wnd.__gwt_activeModules?.fluidtopicsclient?.moduleBase ?? "").trim();
113
+ this.tenantBaseUrl = tenantBaseUrl.endsWith("/") ? tenantBaseUrl : tenantBaseUrl + "/";
114
+ if (overrideIdentifierIfOnTenant && typeof wnd.location !== "undefined" && wnd.location.href.startsWith(this.tenantBaseUrl)) {
46
115
  this.ftCallingApp = integrationIdentifier;
47
116
  }
48
117
  else {
@@ -70,96 +139,101 @@ export class FluidTopicsApi {
70
139
  password: password,
71
140
  rememberMe: true
72
141
  };
73
- return this.post(`/api/authentication/login`, credentials)
142
+ return this.post(this.endpoints.authentication.login, credentials)
74
143
  .then(result => {
75
144
  this.setCredentials(login, password);
76
145
  return result;
77
146
  });
78
147
  }
79
148
  logout() {
80
- return this.post(`/api/authentication/logout`)
149
+ return this.post(this.endpoints.authentication.logout)
81
150
  .then(() => this.clearAuthentication());
82
151
  }
83
152
  getCurrentSession() {
84
- return this.get(`/api/authentication/current-session`);
153
+ return this.get(this.endpoints.authentication.currentSession);
85
154
  }
86
155
  getMap(mapId) {
87
- return this.get(`/api/khub/maps/${mapId}`);
156
+ return this.get(this.endpoints.khub.maps.mapId(mapId).info);
88
157
  }
89
158
  getTableOfContent(mapId) {
90
- return this.get(`/api/khub/maps/${mapId}/toc`);
159
+ return this.get(this.endpoints.khub.maps.mapId(mapId).toc);
160
+ }
161
+ getPages(mapId) {
162
+ return this.get(this.endpoints.khub.maps.mapId(mapId).pages);
91
163
  }
92
164
  getTopic(mapId, topicContentId) {
93
- return this.get(`/api/khub/maps/${mapId}/topics/${topicContentId}`);
165
+ return this.get(this.endpoints.khub.maps.mapId(mapId).topics.contentId(topicContentId).info);
94
166
  }
95
167
  getTopicHTMLContent(mapId, topicContentId, target) {
96
- return this.get(`/api/khub/maps/${mapId}/topics/${topicContentId}/content${target ? "?target=" + target : ""}`);
168
+ return this.get(this.endpoints.khub.maps.mapId(mapId).topics.contentId(topicContentId).content + (target ? "?target=" + target : ""));
97
169
  }
98
170
  getMapAttachments(mapId) {
99
- return this.get(`/api/khub/maps/${mapId}/attachments`);
171
+ return this.get(this.endpoints.khub.maps.mapId(mapId).attachments.list);
100
172
  }
101
173
  getMapAttachmentContent(mapId, attachmentId) {
102
- return this.fetchRawData(`/api/khub/maps/${mapId}/attachments/${attachmentId}/content`);
174
+ return this.fetchRawData(this.endpoints.khub.maps.mapId(mapId).attachments.attachmentId(attachmentId).content);
103
175
  }
104
176
  getMapResources(mapId) {
105
- return this.get(`/api/khub/maps/${mapId}/resources`);
177
+ return this.get(this.endpoints.khub.maps.mapId(mapId).resources.list);
106
178
  }
107
179
  getMapResourceContent(mapId, resourceId) {
108
- return this.fetchRawData(`/api/khub/maps/${mapId}/resources/${resourceId}/content`);
180
+ return this.fetchRawData(this.endpoints.khub.maps.mapId(mapId).resources.resourceId(resourceId).content);
109
181
  }
110
182
  getUnstructuredDocument(documentId) {
111
- return this.get(`/api/khub/documents/${documentId}`);
183
+ return this.get(this.endpoints.khub.documents.documentId(documentId).info);
112
184
  }
113
185
  getUnstructuredDocumentContent(documentId) {
114
- return this.fetchRawData(`/api/khub/documents/${documentId}/content`);
186
+ return this.fetchRawData(this.endpoints.khub.documents.documentId(documentId).content);
115
187
  }
116
188
  getUnstructuredDocumentTextContent(documentId) {
117
- return this.get(`/api/khub/documents/${documentId}/content/text`);
189
+ return this.get(this.endpoints.khub.documents.documentId(documentId).text);
118
190
  }
119
191
  getCollectionDocuments(userId, collectionId) {
120
- return this.get(`/api/users/${userId}/collections/${collectionId}/documents`);
192
+ return this.get(this.endpoints.users.userId(userId).collections.collectionId(collectionId).documents);
121
193
  }
122
194
  getSuggestions(request) {
123
- return this.post("/api/khub/suggest", request);
195
+ return this.post(this.endpoints.khub.suggest, request);
124
196
  }
125
197
  search(request) {
126
- return this.post("/api/khub/clustered-search", request);
198
+ return this.post(this.endpoints.khub.clusteredSearch, request);
127
199
  }
128
200
  getAvailableSearchLocales() {
129
- return this.get("/api/khub/locales");
201
+ return this.get(this.endpoints.khub.locales);
130
202
  }
131
203
  getMapRating(mapId) {
132
- return this.get(`/api/khub/maps/${mapId}/rating`);
133
- }
134
- getDocumentRating(docId) {
135
- return this.get(`/api/khub/documents/${docId}/rating`);
204
+ return this.get(this.endpoints.khub.maps.mapId(mapId).rating);
136
205
  }
137
206
  rateMap(mapId, type, value) {
138
- return this.post(`/api/khub/maps/${mapId}/rating`, { type, value });
207
+ return this.post(this.endpoints.khub.maps.mapId(mapId).rating, { type, value });
139
208
  }
140
209
  unrateMap(mapId) {
141
- return this.delete(`/api/khub/maps/${mapId}/rating`);
210
+ return this.delete(this.endpoints.khub.maps.mapId(mapId).rating);
142
211
  }
143
212
  sendMapFeedback(mapId, message) {
144
- return this.post(`/api/khub/maps/${mapId}/feedback`, { message });
213
+ return this.post(this.endpoints.khub.maps.mapId(mapId).feedback, { message });
145
214
  }
146
215
  rateTopic(mapId, tocId, type, value) {
147
- return this.post(`/api/khub/maps/${mapId}/topics/${tocId}/rating`, { type, value });
216
+ return this.post(this.endpoints.khub.maps.mapId(mapId).topics.tocId(tocId).rating, {
217
+ type, value
218
+ });
148
219
  }
149
220
  unrateTopic(mapId, tocId) {
150
- return this.delete(`/api/khub/maps/${mapId}/topics/${tocId}/rating`);
221
+ return this.delete(this.endpoints.khub.maps.mapId(mapId).topics.tocId(tocId).rating);
151
222
  }
152
223
  sendTopicFeedback(mapId, tocId, message) {
153
- return this.post(`/api/khub/maps/${mapId}/topics/${tocId}/feedback`, { message });
224
+ return this.post(this.endpoints.khub.maps.mapId(mapId).topics.tocId(tocId).feedback, { message });
225
+ }
226
+ getDocumentRating(docId) {
227
+ return this.get(this.endpoints.khub.documents.documentId(docId).rating);
154
228
  }
155
229
  rateDocument(docId, type, value) {
156
- return this.post(`/api/khub/documents/${docId}/rating`, { type, value });
230
+ return this.post(this.endpoints.khub.documents.documentId(docId).rating, { type, value });
157
231
  }
158
232
  unrateDocument(docId) {
159
- return this.delete(`/api/khub/documents/${docId}/rating`);
233
+ return this.delete(this.endpoints.khub.documents.documentId(docId).rating);
160
234
  }
161
235
  sendDocumentFeedback(docId, message) {
162
- return this.post(`/api/khub/documents/${docId}/feedback`, { message });
236
+ return this.post(this.endpoints.khub.documents.documentId(docId).feedback, { message });
163
237
  }
164
238
  get(endpoint) {
165
239
  return this.makeRequest("GET", endpoint);
@@ -173,12 +247,12 @@ export class FluidTopicsApi {
173
247
  delete(endpoint) {
174
248
  return this.makeRequest("DELETE", endpoint);
175
249
  }
250
+ makeAbsolute(endpoint) {
251
+ return this.tenantBaseUrl + endpoint.replace(/^\//, "");
252
+ }
176
253
  async fetch(endpoint, init) {
177
254
  const requestInit = init;
178
- if (!endpoint.startsWith("/")) {
179
- endpoint = "/" + endpoint;
180
- }
181
- return await fetch(this.tenantBaseUrl + endpoint, {
255
+ return await fetch(this.makeAbsolute(endpoint), {
182
256
  ...(requestInit ?? {}),
183
257
  headers: {
184
258
  ...this.defaultHeaders,
@@ -186,22 +260,27 @@ export class FluidTopicsApi {
186
260
  }
187
261
  });
188
262
  }
189
- async upload(method, endpoint, body, onProgress = () => undefined) {
190
- return new Promise((resolve, reject) => {
191
- let xhr = new XMLHttpRequest();
192
- xhr.onload = () => {
193
- if (xhr.status >= 200 && xhr.status < 300) {
194
- let data = xhr.getResponseHeader("Content-Type") === "application/json" ? JSON.parse(xhr.responseText) : xhr.responseText;
195
- resolve(data);
196
- }
197
- else {
198
- reject(new HttpError(xhr.status, xhr.statusText, xhr.responseText));
199
- }
200
- };
201
- xhr.upload.onprogress = (e) => onProgress(e);
202
- xhr.open(method, this.tenantBaseUrl + endpoint, true);
203
- xhr.send(body);
204
- });
263
+ upload(method, endpoint, body, onProgress = () => undefined) {
264
+ if (typeof XMLHttpRequest !== "undefined") {
265
+ return new Promise((resolve, reject) => {
266
+ let xhr = new XMLHttpRequest();
267
+ xhr.onload = () => {
268
+ if (xhr.status >= 200 && xhr.status < 300) {
269
+ let data = xhr.getResponseHeader("Content-Type") === "application/json" ? JSON.parse(xhr.responseText) : xhr.responseText;
270
+ resolve(data);
271
+ }
272
+ else {
273
+ reject(new HttpError(xhr.status, xhr.statusText, xhr.responseText));
274
+ }
275
+ };
276
+ xhr.upload.onprogress = (e) => onProgress(e);
277
+ xhr.open(method, this.makeAbsolute(endpoint), true);
278
+ xhr.send(body);
279
+ });
280
+ }
281
+ else {
282
+ return this.fetch(endpoint, { method, body }).then(handleError).then(getBody);
283
+ }
205
284
  }
206
285
  makeRequest(method, endpoint, data) {
207
286
  return this.fetch(endpoint, {
@@ -215,7 +294,7 @@ export class FluidTopicsApi {
215
294
  .then(getBody);
216
295
  }
217
296
  fetchRawData(endpoint) {
218
- return fetch(this.tenantBaseUrl + endpoint, { headers: this.defaultHeaders })
297
+ return fetch(this.makeAbsolute(endpoint), { headers: this.defaultHeaders })
219
298
  .then(handleError)
220
299
  .then(response => response.arrayBuffer());
221
300
  }
@@ -49,16 +49,9 @@ export interface FtTocNode {
49
49
  tocId: string;
50
50
  children: Array<FtTocNode>;
51
51
  contentId: string;
52
- page?: FtTocPage;
53
52
  title: string;
54
53
  }
55
54
  export declare const isFtTocNode: (o: any) => o is FtTocNode;
56
- export interface FtTocPage {
57
- visible: boolean;
58
- onItsOwn: boolean;
59
- parentsVisibility?: Array<boolean>;
60
- }
61
- export declare const isFtTocPage: (o: any) => o is FtTocPage;
62
55
  export interface FtTopic {
63
56
  metadata: Array<FtMetadata>;
64
57
  id: string;
@@ -57,16 +57,8 @@ export const isFtTocNode = (o) => {
57
57
  && ((Array.isArray(o.children)
58
58
  && o.children.every((v) => isFtTocNode(v))))
59
59
  && (isString(o.contentId))
60
- && (o.page == null || isFtTocPage(o.page))
61
60
  && (isString(o.title));
62
61
  };
63
- export const isFtTocPage = (o) => {
64
- return isObject(o)
65
- && (isBoolean(o.visible))
66
- && (isBoolean(o.onItsOwn))
67
- && (o.parentsVisibility == null || (Array.isArray(o.parentsVisibility)
68
- && o.parentsVisibility.every((v) => isBoolean(v))));
69
- };
70
62
  export const isFtTopic = (o) => {
71
63
  return isObject(o)
72
64
  && ((Array.isArray(o.metadata)
@@ -27,3 +27,27 @@ export interface FtMapAttachment {
27
27
  viewerUrl?: string;
28
28
  }
29
29
  export declare const isFtMapAttachment: (o: any) => o is FtMapAttachment;
30
+ export interface FtPageConfiguration {
31
+ parentsVisibility?: Array<boolean>;
32
+ isVisible: boolean;
33
+ }
34
+ export declare const isFtPageConfiguration: (o: any) => o is FtPageConfiguration;
35
+ export interface FtPaginatedToc {
36
+ configuration: FtPaginationConfiguration;
37
+ paginatedToc: Array<FtPaginatedTocNode>;
38
+ }
39
+ export declare const isFtPaginatedToc: (o: any) => o is FtPaginatedToc;
40
+ export interface FtPaginatedTocNode {
41
+ prettyUrl?: string;
42
+ pageToc?: Array<any>;
43
+ tocId?: string;
44
+ children: Array<FtPaginatedTocNode>;
45
+ pageConfiguration?: FtPageConfiguration;
46
+ contentId?: string;
47
+ title?: string;
48
+ }
49
+ export declare const isFtPaginatedTocNode: (o: any) => o is FtPaginatedTocNode;
50
+ export interface FtPaginationConfiguration {
51
+ splitCurrentPageToc: boolean;
52
+ }
53
+ export declare const isFtPaginationConfiguration: (o: any) => o is FtPaginationConfiguration;
@@ -29,3 +29,30 @@ export const isFtMapAttachment = (o) => {
29
29
  && (o.mimeType == null || isString(o.mimeType))
30
30
  && (o.viewerUrl == null || isString(o.viewerUrl));
31
31
  };
32
+ export const isFtPageConfiguration = (o) => {
33
+ return isObject(o)
34
+ && (o.parentsVisibility == null || (Array.isArray(o.parentsVisibility)
35
+ && o.parentsVisibility.every((v) => isBoolean(v))))
36
+ && (isBoolean(o.isVisible));
37
+ };
38
+ export const isFtPaginatedToc = (o) => {
39
+ return isObject(o)
40
+ && (isFtPaginationConfiguration(o.configuration))
41
+ && ((Array.isArray(o.paginatedToc)
42
+ && o.paginatedToc.every((v) => isFtPaginatedTocNode(v))));
43
+ };
44
+ export const isFtPaginatedTocNode = (o) => {
45
+ return isObject(o)
46
+ && (o.prettyUrl == null || isString(o.prettyUrl))
47
+ && (o.pageToc == null || (Array.isArray(o.pageToc)))
48
+ && (o.tocId == null || isString(o.tocId))
49
+ && ((Array.isArray(o.children)
50
+ && o.children.every((v) => isFtPaginatedTocNode(v))))
51
+ && (o.pageConfiguration == null || isFtPageConfiguration(o.pageConfiguration))
52
+ && (o.contentId == null || isString(o.contentId))
53
+ && (o.title == null || isString(o.title));
54
+ };
55
+ export const isFtPaginationConfiguration = (o) => {
56
+ return isObject(o)
57
+ && (isBoolean(o.splitCurrentPageToc));
58
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/public-api",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "description": "Fluid Topics Public API",
5
5
  "author": "Fluid Topics dev team <opensource@antidot.net>",
6
6
  "license": "LGPL-3.0-only",