@fluid-topics/public-api 1.0.9 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -19,18 +19,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
19
19
  });
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.FluidTopicsApi = void 0;
22
+ exports.FluidTopicsApi = exports.HttpError = void 0;
23
23
  require("cross-fetch/polyfill");
24
24
  __exportStar(require("./types/ft-common/public"), exports);
25
25
  __exportStar(require("./types/ft-server/public"), exports);
26
26
  function toBase64(s) {
27
27
  return typeof Buffer !== "undefined" ? Buffer.from(s).toString("base64") : btoa(s);
28
28
  }
29
+ class HttpError extends Error {
30
+ constructor(status, statusText, body) {
31
+ super(`${status} - ${statusText}: ${body}`);
32
+ this.status = status;
33
+ this.statusText = statusText;
34
+ this.body = body;
35
+ }
36
+ }
37
+ exports.HttpError = HttpError;
29
38
  function handleError(response) {
30
39
  return __awaiter(this, void 0, void 0, function* () {
31
- if (response.status < 200 || response.status >= 400) {
32
- console.error("Fluid Topics server returned an error: ", yield getBody(response));
33
- throw new Error(`${response.status}: ${response.statusText}`);
40
+ if (!response.ok) {
41
+ throw new HttpError(response.status, response.statusText, yield response.text());
34
42
  }
35
43
  return response;
36
44
  });
@@ -81,14 +89,14 @@ class FluidTopicsApi {
81
89
  getTopic(mapId, topicContentId) {
82
90
  return this.get(`/api/khub/maps/${mapId}/topics/${topicContentId}`);
83
91
  }
84
- getTopicHTMLContent(mapId, topicContentId) {
85
- return this.get(`/api/khub/maps/${mapId}/topics/${topicContentId}/content`);
92
+ getTopicHTMLContent(mapId, topicContentId, target) {
93
+ return this.get(`/api/khub/maps/${mapId}/topics/${topicContentId}/content${target ? "?target=" + target : ""}`);
86
94
  }
87
95
  getMapAttachments(mapId) {
88
96
  return this.get(`/api/khub/maps/${mapId}/attachments`);
89
97
  }
90
98
  getMapAttachmentContent(mapId, attachmentId) {
91
- return this.fetchRawData(`/api/khub/maps/${mapId}/attachments/${attachmentId}`);
99
+ return this.fetchRawData(`/api/khub/maps/${mapId}/attachments/${attachmentId}/content`);
92
100
  }
93
101
  getMapResources(mapId) {
94
102
  return this.get(`/api/khub/maps/${mapId}/resources`);
@@ -102,25 +110,38 @@ class FluidTopicsApi {
102
110
  getUnstructuredDocumentContent(documentId) {
103
111
  return this.fetchRawData(`/api/khub/documents/${documentId}/content`);
104
112
  }
113
+ getUnstructuredDocumentTextContent(documentId) {
114
+ return this.get(`/api/khub/documents/${documentId}/content/text`);
115
+ }
105
116
  getCollectionDocuments(userId, collectionId) {
106
117
  return this.get(`/api/users/${userId}/collections/${collectionId}/documents`);
107
118
  }
108
119
  get(endpoint) {
109
- return this.fetch("GET", endpoint);
120
+ return this.makeRequest("GET", endpoint);
110
121
  }
111
122
  post(endpoint, data) {
112
- return this.fetch("POST", endpoint, data);
123
+ return this.makeRequest("POST", endpoint, data);
113
124
  }
114
125
  put(endpoint, data) {
115
- return this.fetch("PUT", endpoint, data);
126
+ return this.makeRequest("PUT", endpoint, data);
116
127
  }
117
128
  delete(endpoint) {
118
- return this.fetch("DELETE", endpoint);
129
+ return this.makeRequest("DELETE", endpoint);
130
+ }
131
+ fetch(endpoint, init) {
132
+ var _a;
133
+ return __awaiter(this, void 0, void 0, function* () {
134
+ const requestInit = init;
135
+ if (!endpoint.startsWith("/")) {
136
+ endpoint = "/" + endpoint;
137
+ }
138
+ 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 : {})) }));
139
+ });
119
140
  }
120
- fetch(method, endpoint, data) {
121
- return fetch(this.tenantBaseUrl + endpoint, {
141
+ makeRequest(method, endpoint, data) {
142
+ return this.fetch(endpoint, {
122
143
  method: method,
123
- headers: Object.assign(Object.assign({}, this.defaultHeaders), (data != null ? { "Content-Type": "application/json" } : {})),
144
+ headers: Object.assign({}, (data != null ? { "Content-Type": "application/json" } : {})),
124
145
  body: data != null ? JSON.stringify(data) : undefined
125
146
  })
126
147
  .then(handleError)
@@ -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.isFtSearchResultType = exports.FtSearchResultType = exports.isFtOpenMode = exports.FtOpenMode = exports.isFtEditorialType = exports.FtEditorialType = exports.isFtMapResource = exports.isFtMetadata = 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";
@@ -89,6 +89,16 @@ 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;
92
102
  const isFtMetadata = (o) => {
93
103
  return isObject(o)
94
104
  && ((Array.isArray(o.values)
@@ -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:{},i={exports:{}},n={exports:{}};!function(e,t){var i=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==i)return i;throw new Error("unable to locate global object")}();e.exports=t=i.fetch,i.fetch&&(t.default=i.fetch.bind(i)),t.Headers=i.Headers,t.Request=i.Request,t.Response=i.Response}(n,n.exports),function(e,t){const i=n.exports,r=i.default||i,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=i.Headers,t.Request=i.Request,t.Response=i.Response,t.default=s}(i,i.exports);const r=i.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 g=e=>["MAP","DOCUMENT","TOPIC"].includes(e),m=e=>"object"==typeof e&&null!=e,T=e=>"string"==typeof e,b=e=>m(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.status<200||e.status>=400)throw console.error("Fluid Topics server returned an error: ",await U(e)),new Error(`${e.status}: ${e.statusText}`);return e}function U(e){return"application/json"===e.headers.get("Content-Type")?e.json():e.text()}class E{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 i;this.authorization={Authorization:"Basic "+(i=`${e}:${t}`,"undefined"!=typeof Buffer?Buffer.from(i).toString("base64"):btoa(i))}}clearAuthentication(){this.authorization={}}login(e,t){let i={login:e,password:t,rememberMe:!0};return this.post("/api/authentication/login",i).then((i=>(this.setCredentials(e,t),i)))}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}`)}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`)}getCollectionDocuments(e,t){return this.get(`/api/users/${e}/collections/${t}/documents`)}get(e){return this.fetch("GET",e)}post(e,t){return this.fetch("POST",e,t)}put(e,t){return this.fetch("PUT",e,t)}delete(e){return this.fetch("DELETE",e)}fetch(e,t,i){return fetch(this.tenantBaseUrl+t,{method:e,headers:{...this.defaultHeaders,...null!=i?{"Content-Type":"application/json"}:{}},body:null!=i?JSON.stringify(i):void 0}).then(A).then(U)}fetchRawData(e){return fetch(this.tenantBaseUrl+e,{headers:this.defaultHeaders}).then(A).then((e=>e.arrayBuffer()))}}e.FluidTopicsApi=E,e.default=E,e.isFtAuthenticatedSession=e=>m(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)&&g(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=>m(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=g,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(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).fluidtopics={})}(this,(function(t){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n={exports:{}},i={exports:{}};!function(t,e){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")}();t.exports=e=n.fetch,n.fetch&&(e.default=n.fetch.bind(n)),e.Headers=n.Headers,e.Request=n.Request,e.Response=n.Response}(i,i.exports),function(t,e){const n=i.exports,r=n.default||n,s=function(t,e){return/^\/\//.test(t)&&(t="https:"+t),r.call(this,t,e)};s.ponyfill=!0,t.exports=e=s,e.fetch=s,e.Headers=n.Headers,e.Request=n.Request,e.Response=n.Response,e.default=s}(n,n.exports);const r=n.exports,s=r.fetch.bind({});s.polyfill=!0,e.fetch||(e.fetch=s,e.Response=r.Response,e.Headers=r.Headers,e.Request=r.Request);const a=t=>"object"==typeof t&&null!=t,o=t=>"boolean"==typeof t,l=t=>"string"==typeof t,u=t=>a(t)&&l(t.tocId)&&Array.isArray(t.children)&&t.children.every((t=>u(t)))&&l(t.contentId)&&l(t.title);var p;t.FtTopicContentTarget=void 0,(p=t.FtTopicContentTarget||(t.FtTopicContentTarget={})).THIRD_PARTY="THIRD_PARTY",p.OFF_THE_GRID="OFF_THE_GRID";const d=t=>a(t)&&Array.isArray(t.values)&&t.values.every((t=>l(t)))&&l(t.label)&&l(t.key);var c;t.FtEditorialType=void 0,(c=t.FtEditorialType||(t.FtEditorialType={})).ARTICLE="ARTICLE",c.BOOK="BOOK";const h=t=>["ARTICLE","BOOK"].includes(t);var f;t.FtOpenMode=void 0,(f=t.FtOpenMode||(t.FtOpenMode={})).FLUIDTOPICS="FLUIDTOPICS",f.EXTERNAL="EXTERNAL";const y=t=>["FLUIDTOPICS","EXTERNAL"].includes(t);var T;t.FtSearchResultType=void 0,(T=t.FtSearchResultType||(t.FtSearchResultType={})).MAP="MAP",T.DOCUMENT="DOCUMENT",T.TOPIC="TOPIC";const g=t=>["MAP","DOCUMENT","TOPIC"].includes(t),m=t=>"object"==typeof t&&null!=t,b=t=>"string"==typeof t,A=t=>m(t)&&(null==t.emailAddress||b(t.emailAddress))&&(null==t.displayName||b(t.displayName))&&Array.isArray(t.roles)&&b(t.userId);class R extends Error{status;statusText;body;constructor(t,e,n){super(`${t} - ${e}: ${n}`),this.status=t,this.statusText=e,this.body=n}}async function F(t){if(!t.ok)throw new R(t.status,t.statusText,await t.text());return t}function E(t){return"application/json"===t.headers.get("Content-Type")?t.json():t.text()}class C{tenantBaseUrl;ftCallingApp;authorization={};get defaultHeaders(){return{...this.authorization,"Ft-Calling-App":this.ftCallingApp}}constructor(t,e){this.tenantBaseUrl=t.trim().replace(/\/$/,""),this.ftCallingApp=`ft-public-api/${e}`}setApiKey(t){this.authorization={Authorization:"Bearer "+t}}setCredentials(t,e){var n;this.authorization={Authorization:"Basic "+(n=`${t}:${e}`,"undefined"!=typeof Buffer?Buffer.from(n).toString("base64"):btoa(n))}}clearAuthentication(){this.authorization={}}login(t,e){let n={login:t,password:e,rememberMe:!0};return this.post("/api/authentication/login",n).then((n=>(this.setCredentials(t,e),n)))}logout(){return this.post("/api/authentication/logout").then((()=>this.clearAuthentication()))}getMap(t){return this.get(`/api/khub/maps/${t}`)}getTableOfContent(t){return this.get(`/api/khub/maps/${t}/toc`)}getTopic(t,e){return this.get(`/api/khub/maps/${t}/topics/${e}`)}getTopicHTMLContent(t,e,n){return this.get(`/api/khub/maps/${t}/topics/${e}/content${n?"?target="+n:""}`)}getMapAttachments(t){return this.get(`/api/khub/maps/${t}/attachments`)}getMapAttachmentContent(t,e){return this.fetchRawData(`/api/khub/maps/${t}/attachments/${e}/content`)}getMapResources(t){return this.get(`/api/khub/maps/${t}/resources`)}getMapResourceContent(t,e){return this.fetchRawData(`/api/khub/maps/${t}/resources/${e}/content`)}getUnstructuredDocument(t){return this.get(`/api/khub/documents/${t}`)}getUnstructuredDocumentContent(t){return this.fetchRawData(`/api/khub/documents/${t}/content`)}getUnstructuredDocumentTextContent(t){return this.get(`/api/khub/documents/${t}/content/text`)}getCollectionDocuments(t,e){return this.get(`/api/users/${t}/collections/${e}/documents`)}get(t){return this.makeRequest("GET",t)}post(t,e){return this.makeRequest("POST",t,e)}put(t,e){return this.makeRequest("PUT",t,e)}delete(t){return this.makeRequest("DELETE",t)}async fetch(t,e){const n=e;return t.startsWith("/")||(t="/"+t),await fetch(this.tenantBaseUrl+t,{...n??{},headers:{...this.defaultHeaders,...n?.headers??{}}})}makeRequest(t,e,n){return this.fetch(e,{method:t,headers:{...null!=n?{"Content-Type":"application/json"}:{}},body:null!=n?JSON.stringify(n):void 0}).then(F).then(E)}fetchRawData(t){return fetch(this.tenantBaseUrl+t,{headers:this.defaultHeaders}).then(F).then((t=>t.arrayBuffer()))}}t.FluidTopicsApi=C,t.HttpError=R,t.default=C,t.isFtAuthenticatedSession=t=>m(t)&&A(t.profile),t.isFtAuthenticationIdentifier=t=>a(t)&&l(t.identifier)&&l(t.realm),t.isFtCollectionDocument=t=>a(t)&&o(t.deleted)&&(null==t.apiUrl||l(t.apiUrl))&&(null==t.portalUrl||l(t.portalUrl))&&l(t.id)&&l(t.title)&&g(t.type),t.isFtCredentials=t=>a(t)&&l(t.password)&&(null==t.newPassword||l(t.newPassword))&&o(t.rememberMe)&&l(t.login),t.isFtEditorialType=h,t.isFtMap=t=>a(t)&&(null==t.prettyUrl||l(t.prettyUrl))&&Array.isArray(t.metadata)&&t.metadata.every((t=>d(t)))&&y(t.openMode)&&l(t.topicsApiEndpoint)&&(null==t.description||l(t.description))&&l(t.attachmentsApiEndpoint)&&h(t.editorialType)&&l(t.baseId)&&l(t.clusterId)&&l(t.title)&&l(t.lastPublication)&&l(t.lastEdition)&&l(t.originId)&&l(t.rightsApiEndpoint)&&(null==t.originUrl||l(t.originUrl))&&l(t.readerUrl)&&(null==t.khubVersion||l(t.khubVersion))&&l(t.id)&&(null==t.lang||l(t.lang)),t.isFtMapAttachment=t=>m(t)&&b(t.file)&&(null==t.size||(t=>"number"==typeof t)(t.size))&&(t=>"boolean"==typeof t)(t.externalLink)&&b(t.name)&&b(t.id)&&(null==t.mimeType||b(t.mimeType))&&(null==t.viewerUrl||b(t.viewerUrl)),t.isFtMapResource=t=>a(t)&&l(t.contentUrl)&&l(t.filename)&&l(t.id)&&l(t.mimeType),t.isFtMetadata=d,t.isFtOpenMode=y,t.isFtSearchResultType=g,t.isFtTocNode=u,t.isFtTopic=t=>a(t)&&Array.isArray(t.metadata)&&t.metadata.every((t=>d(t)))&&l(t.id)&&l(t.contentApiEndpoint)&&l(t.title),t.isFtTopicContentTarget=t=>["THIRD_PARTY","OFF_THE_GRID"].includes(t),t.isFtUnstructuredDocument=t=>a(t)&&(null==t.prettyUrl||l(t.prettyUrl))&&Array.isArray(t.metadata)&&t.metadata.every((t=>d(t)))&&l(t.openMode)&&(null==t.description||l(t.description))&&l(t.mimeType)&&(null==t.baseId||l(t.baseId))&&(null==t.clusterId||l(t.clusterId))&&l(t.contentApiEndpoint)&&l(t.title)&&(null==t.lastPublication||l(t.lastPublication))&&l(t.viewerUrl)&&l(t.lastEdition)&&l(t.filename)&&(null==t.originId||l(t.originId))&&l(t.rightsApiEndpoint)&&(null==t.originUrl||l(t.originUrl))&&(null==t.khubVersion||l(t.khubVersion))&&l(t.id)&&(null==t.lang||l(t.lang)),t.isFtUserProfile=A}));
@@ -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, 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,19 +23,21 @@ 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>>;
24
30
  getMapResourceContent(mapId: string, resourceId: string): Promise<ArrayBuffer>;
25
31
  getUnstructuredDocument(documentId: string): Promise<FtUnstructuredDocument>;
26
32
  getUnstructuredDocumentContent(documentId: string): Promise<ArrayBuffer>;
33
+ getUnstructuredDocumentTextContent(documentId: string): Promise<string>;
27
34
  getCollectionDocuments(userId: string, collectionId: string): Promise<Array<FtCollectionDocument>>;
28
35
  get<T>(endpoint: string): Promise<T>;
29
36
  post<T>(endpoint: string, data?: any): Promise<T>;
30
37
  put<T>(endpoint: string, data?: any): Promise<T>;
31
38
  delete<T>(endpoint: string): Promise<T>;
32
- private fetch;
39
+ fetch<FetchRequestInit, FetchResponse>(endpoint: string, init?: FetchRequestInit): Promise<FetchResponse>;
40
+ private makeRequest;
33
41
  private fetchRawData;
34
42
  }
35
43
  export default FluidTopicsApi;
package/dist/mjs/index.js CHANGED
@@ -4,10 +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
- if (response.status < 200 || response.status >= 400) {
9
- console.error("Fluid Topics server returned an error: ", await getBody(response));
10
- throw new Error(`${response.status}: ${response.statusText}`);
19
+ if (!response.ok) {
20
+ throw new HttpError(response.status, response.statusText, await response.text());
11
21
  }
12
22
  return response;
13
23
  }
@@ -62,14 +72,14 @@ export class FluidTopicsApi {
62
72
  getTopic(mapId, topicContentId) {
63
73
  return this.get(`/api/khub/maps/${mapId}/topics/${topicContentId}`);
64
74
  }
65
- getTopicHTMLContent(mapId, topicContentId) {
66
- 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 : ""}`);
67
77
  }
68
78
  getMapAttachments(mapId) {
69
79
  return this.get(`/api/khub/maps/${mapId}/attachments`);
70
80
  }
71
81
  getMapAttachmentContent(mapId, attachmentId) {
72
- return this.fetchRawData(`/api/khub/maps/${mapId}/attachments/${attachmentId}`);
82
+ return this.fetchRawData(`/api/khub/maps/${mapId}/attachments/${attachmentId}/content`);
73
83
  }
74
84
  getMapResources(mapId) {
75
85
  return this.get(`/api/khub/maps/${mapId}/resources`);
@@ -83,26 +93,41 @@ export class FluidTopicsApi {
83
93
  getUnstructuredDocumentContent(documentId) {
84
94
  return this.fetchRawData(`/api/khub/documents/${documentId}/content`);
85
95
  }
96
+ getUnstructuredDocumentTextContent(documentId) {
97
+ return this.get(`/api/khub/documents/${documentId}/content/text`);
98
+ }
86
99
  getCollectionDocuments(userId, collectionId) {
87
100
  return this.get(`/api/users/${userId}/collections/${collectionId}/documents`);
88
101
  }
89
102
  get(endpoint) {
90
- return this.fetch("GET", endpoint);
103
+ return this.makeRequest("GET", endpoint);
91
104
  }
92
105
  post(endpoint, data) {
93
- return this.fetch("POST", endpoint, data);
106
+ return this.makeRequest("POST", endpoint, data);
94
107
  }
95
108
  put(endpoint, data) {
96
- return this.fetch("PUT", endpoint, data);
109
+ return this.makeRequest("PUT", endpoint, data);
97
110
  }
98
111
  delete(endpoint) {
99
- return this.fetch("DELETE", endpoint);
112
+ return this.makeRequest("DELETE", endpoint);
113
+ }
114
+ async fetch(endpoint, init) {
115
+ const requestInit = init;
116
+ if (!endpoint.startsWith("/")) {
117
+ endpoint = "/" + endpoint;
118
+ }
119
+ return await fetch(this.tenantBaseUrl + endpoint, {
120
+ ...(requestInit ?? {}),
121
+ headers: {
122
+ ...this.defaultHeaders,
123
+ ...(requestInit?.headers ?? {})
124
+ }
125
+ });
100
126
  }
101
- fetch(method, endpoint, data) {
102
- return fetch(this.tenantBaseUrl + endpoint, {
127
+ makeRequest(method, endpoint, data) {
128
+ return this.fetch(endpoint, {
103
129
  method: method,
104
130
  headers: {
105
- ...this.defaultHeaders,
106
131
  ...(data != null ? { "Content-Type": "application/json" } : {})
107
132
  },
108
133
  body: data != null ? JSON.stringify(data) : undefined
@@ -72,6 +72,11 @@ export interface FtUnstructuredDocument {
72
72
  lang?: string;
73
73
  }
74
74
  export declare const isFtUnstructuredDocument: (o: any) => o is FtUnstructuredDocument;
75
+ export declare enum FtTopicContentTarget {
76
+ THIRD_PARTY = "THIRD_PARTY",
77
+ OFF_THE_GRID = "OFF_THE_GRID"
78
+ }
79
+ export declare const isFtTopicContentTarget: (o: any) => o is FtTopicContentTarget;
75
80
  export interface FtMetadata {
76
81
  values: Array<string>;
77
82
  label: string;
@@ -80,6 +80,15 @@ export const isFtUnstructuredDocument = (o) => {
80
80
  && (isString(o.id))
81
81
  && (o.lang == null || isString(o.lang));
82
82
  };
83
+ // From: WsTopicContentTarget
84
+ export var FtTopicContentTarget;
85
+ (function (FtTopicContentTarget) {
86
+ FtTopicContentTarget["THIRD_PARTY"] = "THIRD_PARTY";
87
+ FtTopicContentTarget["OFF_THE_GRID"] = "OFF_THE_GRID";
88
+ })(FtTopicContentTarget || (FtTopicContentTarget = {}));
89
+ export const isFtTopicContentTarget = (o) => {
90
+ return ["THIRD_PARTY", "OFF_THE_GRID"].includes(o);
91
+ };
83
92
  export const isFtMetadata = (o) => {
84
93
  return isObject(o)
85
94
  && ((Array.isArray(o.values)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/public-api",
3
- "version": "1.0.9",
3
+ "version": "1.0.13",
4
4
  "description": "Fluid Topics Public API",
5
5
  "author": "Fluid Topics dev team <opensource@antidot.net>",
6
6
  "license": "LGPLv3",
@@ -17,7 +17,7 @@
17
17
  "access": "public"
18
18
  },
19
19
  "dependencies": {
20
- "cross-fetch": "^3.1.4"
20
+ "cross-fetch": "^3.1.5"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@rollup/plugin-commonjs": "^20.0.0",