totalum-api-sdk 3.0.5 → 3.0.7

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.
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ScrappingService = void 0;
13
+ const utils_1 = require("../utils");
14
+ const endpoints_1 = require("../common/endpoints");
15
+ // ============= Service =============
16
+ class ScrappingService {
17
+ constructor(client) {
18
+ this.client = client;
19
+ }
20
+ /**
21
+ * Scrapes a web page and returns its content in the specified format.
22
+ * Supports presets for popular platforms (Google, Amazon, Instagram, etc.).
23
+ * @param {ScrapeRequestBody} body - Scrape configuration
24
+ * @returns {Promise<TotalumApiResponse<ScrapeResponseData>>} - The scraped page content
25
+ */
26
+ scrape(body) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.webScraper.scrape);
29
+ return this.client.post(url, body);
30
+ });
31
+ }
32
+ /**
33
+ * Extracts structured data from a URL or provided HTML/markdown content using AI models.
34
+ * Can use pre-built extraction models (product, article, etc.) or custom prompts.
35
+ * @param {ExtractRequestBody} body - Extraction configuration
36
+ * @returns {Promise<TotalumApiResponse<ExtractResponseData>>} - The extracted structured data
37
+ */
38
+ extract(body) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.webScraper.extract);
41
+ return this.client.post(url, body);
42
+ });
43
+ }
44
+ /**
45
+ * Takes a screenshot of a web page.
46
+ * @param {ScreenshotRequestBody} body - Screenshot configuration
47
+ * @returns {Promise<TotalumApiResponse<ScreenshotResponseData>>} - The screenshot as base64
48
+ */
49
+ screenshot(body) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.webScraper.screenshot);
52
+ return this.client.post(url, body);
53
+ });
54
+ }
55
+ /**
56
+ * Searches Google for a query, then scrapes and extracts data from the top results.
57
+ * Supports smart AI-based source selection to only scrape the most relevant results.
58
+ * @param {SearchAndExtractRequestBody} body - Search and extraction configuration
59
+ * @returns {Promise<TotalumApiResponse<SearchAndExtractResponseData>>} - Search results with extracted data
60
+ */
61
+ searchAndExtract(body) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.webScraper.searchAndExtract);
64
+ return this.client.post(url, body);
65
+ });
66
+ }
67
+ }
68
+ exports.ScrappingService = ScrappingService;
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.totalumSdk=t():e.totalumSdk=t()}(this,(()=>(()=>{"use strict";var e={429:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.endpoints=void 0,t.endpoints={crud:{getObjectById:"api/v1/crud/:typeId/:id",getObjects:"api/v1/crud/query/:typeId",getNestedData:"api/v1/crud/nested",createObject:"api/v1/crud/:typeId",editObjectProperties:"api/v1/crud/:typeId/:id",deleteObject:"api/v1/crud/:typeId/:id",deleteObjectAndSubElements:"api/v1/crud/:typeId/:id/:pageId/subelements",updateLastUsersActions:"api/v1/crud/:typeId/:id/lastUsersActions",addManyToManyReference:"api/v1/crud/:typeId/:id/add-many-to-many-reference",dropManyToManyReference:"api/v1/crud/:typeId/:id/drop-many-to-many-reference",getManyToManyReferencesItems:"api/v1/crud/:typeId/:id/:propertyName"},updatesRecord:{getUpdateRecordByObjectId:"api/v1/updates-record/:objectId"},files:{uploadFile:"api/v1/files/upload",getDownloadUrl:"api/v1/files/download/:fileName",deleteFile:"api/v1/files/:fileName",ocrOfImage:"api/v1/files/ocr/image",ocrOfPdf:"api/v1/files/ocr/pdf",scanInvoice:"api/v1/files/scan-invoice",scanDocument:"api/v1/files/scan-document"},filter:{lookUpFilter:"api/v1/filter/:idPage",nestedFilter:"api/v1/filter/nested-filter",runCustomAggregationQuery:"api/v1/filter/custom-mongo-aggregation-query"},pdfTemplate:{generatePdfByTemplate:"api/v1/pdf-template/generatePdfByTemplate/:id",createPdfFromHtml:"api/v1/pdf-template/createPdfFromHtml"},googleIntegration:{getEmails:"api/v1/google-integration/get-emails",sendEmail:"api/v1/google-integration/send-email",getCalendarEvents:"api/v1/google-integration/get-calendar-events",createCalendarEvent:"api/v1/google-integration/create-calendar-event"},openai:{createCompletion:"api/v1/openai/completion",createChatCompletion:"api/v1/openai/chat-completion",generateImage:"api/v1/openai/image"},notifications:{createNotification:"api/v1/notifications"},statistics:{getStatistic:"api/v1/statistics/get-statistic"},email:{sendEmail:"api/v1/startum/send-email-with-default-domain"}}},731:function(e,t){var i=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function c(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,c)}a((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.FetchClient=t.TotalumError=void 0;class n extends Error{constructor(e){super(e.errorMessage),this.errorCode=e.errorCode,this.errorMessage=e.errorMessage,this.hasManyErrors=e.hasManyErrors||!1,this.multipleErrors=e.multipleErrors||[],this.name="TotalumError",Object.setPrototypeOf(this,n.prototype)}toJSON(){return{errorCode:this.errorCode,errorMessage:this.errorMessage,hasManyErrors:this.hasManyErrors,multipleErrors:this.multipleErrors}}}t.TotalumError=n,t.FetchClient=class{constructor(e,t){this.baseUrl=e,this.headers=t}handleResponse(e){return i(this,void 0,void 0,(function*(){let t;try{t=yield e.json()}catch(t){return{errors:{errorCode:"RESPONSE_PARSE_ERROR",errorMessage:`Failed to parse response: ${e.statusText}`},data:null}}return t}))}request(e,t){return i(this,void 0,void 0,(function*(){const i=this.baseUrl+e;try{const e=yield fetch(i,Object.assign(Object.assign({},t),{headers:Object.assign(Object.assign({},this.headers),null==t?void 0:t.headers)}));return this.handleResponse(e)}catch(e){return{errors:{errorCode:"NETWORK_ERROR",errorMessage:e instanceof Error?e.message:"Network request failed"},data:null}}}))}get(e,t){return i(this,void 0,void 0,(function*(){let i=e;if(t){const e=new URLSearchParams(Object.entries(t).reduce(((e,[t,i])=>(null!=i&&(e[t]=String(i)),e)),{})).toString();e&&(i+="?"+e)}return this.request(i,{method:"GET"})}))}post(e,t){return i(this,void 0,void 0,(function*(){const i=t instanceof FormData;return this.request(e,{method:"POST",headers:i?{}:{"Content-Type":"application/json"},body:i?t:JSON.stringify(t)})}))}patch(e,t){return i(this,void 0,void 0,(function*(){return this.request(e,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}))}delete(e){return i(this,void 0,void 0,(function*(){return this.request(e,{method:"DELETE"})}))}put(e,t){return i(this,void 0,void 0,(function*(){return this.request(e,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}))}}},999:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},879:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},492:function(e,t,i){var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var r=Object.getOwnPropertyDescriptor(t,i);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,r)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),r=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)};Object.defineProperty(t,"__esModule",{value:!0}),t.TotalumApiSdk=t.TotalumError=void 0;const o=i(731),s=i(730),c=i(675),a=i(589),d=i(882),l=i(386),u=i(706),p=i(279);r(i(999),t),r(i(879),t);var f=i(731);Object.defineProperty(t,"TotalumError",{enumerable:!0,get:function(){return f.TotalumError}}),t.TotalumApiSdk=class{constructor(e){var t,i;if(this._baseUrl="https://api.totalum.app/",this.authOptions=e,this._headers={},null===(t=this.authOptions.token)||void 0===t?void 0:t.accessToken)this._headers.authorization=this.authOptions.token.accessToken;else{if(!(null===(i=this.authOptions.apiKey)||void 0===i?void 0:i["api-key"]))throw new Error("Error: invalid auth options");this._headers["api-key"]=this.authOptions.apiKey["api-key"]}this.authOptions.baseUrl&&(this._baseUrl=this.authOptions.baseUrl),this.authOptions.fromEvent&&(this._headers.fromEvent="true"),this.setRequestData()}changeBaseUrl(e){this._baseUrl=e,this.setRequestData()}setRequestData(){this.client=new o.FetchClient(this._baseUrl,this._headers),this.crud=new d.CrudService(this.client),this.openai=new s.OpenaiService(this.client),this.files=new a.FilesService(this.client),this.filter=new c.FilterService(this.client),this.notification=new l.NotificationService(this.client),this.statistic=new u.StatisticService(this.client),this.email=new p.EmailService(this.client)}}},882:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function c(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,c)}a((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.CrudService=void 0;const r=i(591),o=i(429);t.CrudService=class{constructor(e){this.client=e}getRecordById(e,t){return n(this,void 0,void 0,(function*(){const i=r.UtilsService.getUrl("",o.endpoints.crud.getObjectById,{typeId:e,id:t});return this.client.get(i)}))}getHistoricRecordUpdatesById(e){return n(this,void 0,void 0,(function*(){const t=r.UtilsService.getUrl("",o.endpoints.updatesRecord.getUpdateRecordByObjectId,{objectId:e});return this.client.get(t)}))}getRecords(e,t){return n(this,void 0,void 0,(function*(){const i=r.UtilsService.getUrl("",o.endpoints.crud.getObjects,{typeId:e});return this.client.post(i,t)}))}getNestedData(e,t){return n(this,void 0,void 0,(function*(){const i=r.UtilsService.getUrl("",o.endpoints.crud.getNestedData);return this.client.post(i,{nestedQuery:e,options:t})}))}deleteRecordById(e,t){return n(this,void 0,void 0,(function*(){const i=r.UtilsService.getUrl("",o.endpoints.crud.deleteObject,{typeId:e,id:t});return this.client.delete(i)}))}editRecordById(e,t,i){return n(this,void 0,void 0,(function*(){const n=r.UtilsService.getUrl("",o.endpoints.crud.editObjectProperties,{typeId:e,id:t});return this.client.request(n,{method:"PATCH",headers:{"Content-Type":"application/json",returnoption:"fullrecord"},body:JSON.stringify(i)})}))}createRecord(e,t){return n(this,void 0,void 0,(function*(){const i=r.UtilsService.getUrl("",o.endpoints.crud.createObject,{typeId:e});return this.client.request(i,{method:"POST",headers:{"Content-Type":"application/json",returnoption:"fullrecord"},body:JSON.stringify(t)})}))}addManyToManyReferenceRecord(e,t,i,s){return n(this,void 0,void 0,(function*(){const n=r.UtilsService.getUrl("",o.endpoints.crud.addManyToManyReference,{typeId:e,id:t});return this.client.patch(n,{propertyId:i,referenceId:s})}))}dropManyToManyReferenceRecord(e,t,i,s){return n(this,void 0,void 0,(function*(){const n=r.UtilsService.getUrl("",o.endpoints.crud.dropManyToManyReference,{typeId:e,id:t});return this.client.patch(n,{propertyId:i,referenceId:s})}))}getManyToManyReferencesRecords(e,t,i,s){return n(this,void 0,void 0,(function*(){const n=r.UtilsService.getUrl("",o.endpoints.crud.getManyToManyReferencesItems,{typeId:e,id:t,propertyName:i});return this.client.get(n,s)}))}}},279:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function c(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,c)}a((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.EmailService=void 0;const r=i(429),o=i(591);t.EmailService=class{constructor(e){this.client=e}sendEmail(e){return n(this,void 0,void 0,(function*(){if(e.attachments&&e.attachments.length>10)return{errors:{errorCode:"TOO_MANY_ATTACHMENTS",errorMessage:`Maximum number of attachments is 10. Received ${e.attachments.length}.`},data:null};if(e.attachments)for(const t of e.attachments){if(!t.url||"string"!=typeof t.url)return{errors:{errorCode:"INVALID_ATTACHMENT_URL",errorMessage:`Attachment ${t.filename} must have a valid URL`},data:null};if(!t.url.startsWith("http://")&&!t.url.startsWith("https://"))return{errors:{errorCode:"INVALID_ATTACHMENT_URL",errorMessage:`Attachment ${t.filename} must have a valid HTTP/HTTPS URL`},data:null}}return this.sendEmailWithDefaultDomain(e)}))}sendEmailWithDefaultDomain(e){return n(this,void 0,void 0,(function*(){const t=o.UtilsService.getUrl("",r.endpoints.email.sendEmail,{});return this.client.post(t,e)}))}}},589:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function c(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,c)}a((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.FilesService=void 0;const r=i(591),o=i(429);t.FilesService=class{constructor(e){this.client=e}uploadFile(e,t){return n(this,void 0,void 0,(function*(){let i=r.UtilsService.getUrl("",o.endpoints.files.uploadFile);return(null==t?void 0:t.compressFile)&&(i+="?compressFile=true"),this.client.post(i,e)}))}deleteFile(e){return n(this,void 0,void 0,(function*(){const t=r.UtilsService.getUrl("",o.endpoints.files.deleteFile,{fileName:e});return this.client.delete(t)}))}getDownloadUrl(e,t){return n(this,void 0,void 0,(function*(){const i=r.UtilsService.getUrl("",o.endpoints.files.getDownloadUrl,{fileName:e});return this.client.get(i,t)}))}generatePdfByTemplate(e,t,i){return n(this,void 0,void 0,(function*(){const n=r.UtilsService.getUrl("",o.endpoints.pdfTemplate.generatePdfByTemplate,{id:e});return this.client.post(n,{templateId:e,variables:t,name:i})}))}createPdfFromHtml(e){return n(this,void 0,void 0,(function*(){const t=r.UtilsService.getUrl("",o.endpoints.pdfTemplate.createPdfFromHtml);let i;return i="undefined"==typeof window?Buffer.from(e.html,"utf-8").toString("base64"):btoa(unescape(encodeURIComponent(e.html))),this.client.post(t,{base64HtmlString:i,name:e.name})}))}ocrOfImage(e){return n(this,void 0,void 0,(function*(){const t=r.UtilsService.getUrl("",o.endpoints.files.ocrOfImage);return this.client.post(t,{fileName:e})}))}ocrOfPdf(e){return n(this,void 0,void 0,(function*(){const t=r.UtilsService.getUrl("",o.endpoints.files.ocrOfPdf);return this.client.post(t,{fileName:e})}))}scanInvoice(e,t){return n(this,void 0,void 0,(function*(){const i=r.UtilsService.getUrl("",o.endpoints.files.scanInvoice);return this.client.post(i,{fileName:e,options:t})}))}scanDocument(e,t,i){return n(this,void 0,void 0,(function*(){const n=r.UtilsService.getUrl("",o.endpoints.files.scanDocument);return this.client.post(n,{fileName:e,properties:t,options:i})}))}}},675:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function c(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,c)}a((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.FilterService=void 0;const r=i(429),o=i(591);t.FilterService=class{constructor(e){this.client=e}lookUpFilter(e,t,i,s){return n(this,void 0,void 0,(function*(){const n=o.UtilsService.getUrl("",r.endpoints.filter.lookUpFilter,{idPage:e}),c={query:encodeURIComponent(JSON.stringify(t)),idsOfMultipleNodesToSearch:i?encodeURIComponent(JSON.stringify(i)):void 0,returnCount:null==s?void 0:s.toString()};return this.client.get(n,c)}))}nestedFilter(e,t,i){return n(this,void 0,void 0,(function*(){const n=o.UtilsService.getUrl("",r.endpoints.filter.nestedFilter,{}),s={nestedFilter:e,tableNameToGetResults:t,filterOptions:i};return this.client.post(n,s)}))}runCustomMongoAggregationQuery(e,t){return n(this,void 0,void 0,(function*(){const i=o.UtilsService.getUrl("",r.endpoints.filter.runCustomAggregationQuery),n={customMongoQuery:t,type:e};return this.client.post(i,n)}))}}},386:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function c(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,c)}a((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.NotificationService=void 0;const r=i(429),o=i(591);t.NotificationService=class{constructor(e){this.client=e}createNotification(e){return n(this,void 0,void 0,(function*(){const t=o.UtilsService.getUrl("",r.endpoints.notifications.createNotification,{});return this.client.post(t,{notification:e})}))}}},730:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function c(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,c)}a((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.OpenaiService=void 0;const r=i(591),o=i(429);t.OpenaiService=class{constructor(e){this.client=e}createCompletion(e){return n(this,void 0,void 0,(function*(){const t=r.UtilsService.getUrl("",o.endpoints.openai.createCompletion);return this.client.post(t,e)}))}createChatCompletion(e){return n(this,void 0,void 0,(function*(){const t=r.UtilsService.getUrl("",o.endpoints.openai.createChatCompletion);return this.client.post(t,e)}))}generateImage(e){return n(this,void 0,void 0,(function*(){const t=r.UtilsService.getUrl("",o.endpoints.openai.generateImage);return this.client.post(t,e)}))}}},706:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function c(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,c)}a((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.StatisticService=void 0;const r=i(429),o=i(591);t.StatisticService=class{constructor(e){this.client=e}getStatistic(e,t){return n(this,void 0,void 0,(function*(){const i=o.UtilsService.getUrl("",r.endpoints.statistics.getStatistic,{}),n={query:e,options:t};return this.client.post(i,n)}))}}},591:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.UtilsService=void 0,t.UtilsService=class{static getUrl(e,t,i){let n=e+t;for(const e in i)n=n.replace(`:${e}`,i[e]);return n}}}},t={};return function i(n){var r=t[n];if(void 0!==r)return r.exports;var o=t[n]={exports:{}};return e[n].call(o.exports,o,o.exports,i),o.exports}(492)})()));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.totalumSdk=t():e.totalumSdk=t()}(this,(()=>(()=>{"use strict";var e={429:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.endpoints=void 0,t.endpoints={crud:{getObjectById:"api/v1/crud/:typeId/:id",getObjects:"api/v1/crud/query/:typeId",getNestedData:"api/v1/crud/nested",query:"api/v1/crud/advanced-query",createObject:"api/v1/crud/:typeId",editObjectProperties:"api/v1/crud/:typeId/:id",deleteObject:"api/v1/crud/:typeId/:id",deleteObjectAndSubElements:"api/v1/crud/:typeId/:id/:pageId/subelements",updateLastUsersActions:"api/v1/crud/:typeId/:id/lastUsersActions",addManyToManyReference:"api/v1/crud/:typeId/:id/add-many-to-many-reference",dropManyToManyReference:"api/v1/crud/:typeId/:id/drop-many-to-many-reference",getManyToManyReferencesItems:"api/v1/crud/:typeId/:id/:propertyName"},updatesRecord:{getUpdateRecordByObjectId:"api/v1/updates-record/:objectId"},files:{uploadFile:"api/v1/files/upload",getDownloadUrl:"api/v1/files/download/:fileName",deleteFile:"api/v1/files/:fileName",ocrOfImage:"api/v1/files/ocr/image",ocrOfPdf:"api/v1/files/ocr/pdf",scanInvoice:"api/v1/files/scan-invoice",scanDocument:"api/v1/files/scan-document"},filter:{lookUpFilter:"api/v1/filter/:idPage",nestedFilter:"api/v1/filter/nested-filter",runCustomAggregationQuery:"api/v1/filter/custom-mongo-aggregation-query"},pdfTemplate:{generatePdfByTemplate:"api/v1/pdf-template/generatePdfByTemplate/:id",createPdfFromHtml:"api/v1/pdf-template/createPdfFromHtml"},googleIntegration:{getEmails:"api/v1/google-integration/get-emails",sendEmail:"api/v1/google-integration/send-email",getCalendarEvents:"api/v1/google-integration/get-calendar-events",createCalendarEvent:"api/v1/google-integration/create-calendar-event"},openai:{createCompletion:"api/v1/openai/completion",createChatCompletion:"api/v1/openai/chat-completion",generateImage:"api/v1/openai/image",editImage:"api/v1/openai/image-edit"},notifications:{createNotification:"api/v1/notifications"},statistics:{getStatistic:"api/v1/statistics/get-statistic"},email:{sendEmail:"api/v1/startum/send-email-with-default-domain"},webScraper:{scrape:"api/v1/web-scraper/scrape",extract:"api/v1/web-scraper/extract",screenshot:"api/v1/web-scraper/screenshot",searchAndExtract:"api/v1/web-scraper/search-and-extract"}}},731:function(e,t){var i=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function c(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,c)}a((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.FetchClient=t.TotalumError=void 0;class n extends Error{constructor(e){super(e.errorMessage),this.errorCode=e.errorCode,this.errorMessage=e.errorMessage,this.hasManyErrors=e.hasManyErrors||!1,this.multipleErrors=e.multipleErrors||[],this.name="TotalumError",Object.setPrototypeOf(this,n.prototype)}toJSON(){return{errorCode:this.errorCode,errorMessage:this.errorMessage,hasManyErrors:this.hasManyErrors,multipleErrors:this.multipleErrors}}}t.TotalumError=n,t.FetchClient=class{constructor(e,t){this.baseUrl=e,this.headers=t}handleResponse(e){return i(this,void 0,void 0,(function*(){let t;try{t=yield e.json()}catch(t){return{errors:{errorCode:"RESPONSE_PARSE_ERROR",errorMessage:`Failed to parse response: ${e.statusText}`},data:null}}return t}))}request(e,t){return i(this,void 0,void 0,(function*(){const i=this.baseUrl+e;try{const e=yield fetch(i,Object.assign(Object.assign({},t),{headers:Object.assign(Object.assign({},this.headers),null==t?void 0:t.headers)}));return this.handleResponse(e)}catch(e){return{errors:{errorCode:"NETWORK_ERROR",errorMessage:e instanceof Error?e.message:"Network request failed"},data:null}}}))}get(e,t){return i(this,void 0,void 0,(function*(){let i=e;if(t){const e=new URLSearchParams(Object.entries(t).reduce(((e,[t,i])=>(null!=i&&(e[t]=String(i)),e)),{})).toString();e&&(i+="?"+e)}return this.request(i,{method:"GET"})}))}post(e,t){return i(this,void 0,void 0,(function*(){const i=t instanceof FormData;return this.request(e,{method:"POST",headers:i?{}:{"Content-Type":"application/json"},body:i?t:JSON.stringify(t)})}))}patch(e,t){return i(this,void 0,void 0,(function*(){return this.request(e,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}))}delete(e){return i(this,void 0,void 0,(function*(){return this.request(e,{method:"DELETE"})}))}put(e,t){return i(this,void 0,void 0,(function*(){return this.request(e,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}))}}},999:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},879:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},492:function(e,t,i){var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var r=Object.getOwnPropertyDescriptor(t,i);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,r)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),r=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)};Object.defineProperty(t,"__esModule",{value:!0}),t.TotalumApiSdk=t.TotalumError=void 0;const o=i(731),s=i(730),c=i(675),a=i(589),d=i(882),l=i(386),u=i(706),p=i(279),h=i(183);r(i(999),t),r(i(879),t);var v=i(731);Object.defineProperty(t,"TotalumError",{enumerable:!0,get:function(){return v.TotalumError}}),t.TotalumApiSdk=class{constructor(e){var t,i;if(this._baseUrl="https://api.totalum.app/",this.authOptions=e,this._headers={},null===(t=this.authOptions.token)||void 0===t?void 0:t.accessToken)this._headers.authorization=this.authOptions.token.accessToken;else{if(!(null===(i=this.authOptions.apiKey)||void 0===i?void 0:i["api-key"]))throw new Error("Error: invalid auth options");this._headers["api-key"]=this.authOptions.apiKey["api-key"]}this.authOptions.baseUrl&&(this._baseUrl=this.authOptions.baseUrl),this.authOptions.fromEvent&&(this._headers.fromEvent="true"),this.setRequestData()}changeBaseUrl(e){this._baseUrl=e,this.setRequestData()}setRequestData(){this.client=new o.FetchClient(this._baseUrl,this._headers),this.crud=new d.CrudService(this.client),this.openai=new s.OpenaiService(this.client),this.files=new a.FilesService(this.client),this.filter=new c.FilterService(this.client),this.notification=new l.NotificationService(this.client),this.statistic=new u.StatisticService(this.client),this.email=new p.EmailService(this.client),this.scrapping=new h.ScrappingService(this.client)}}},882:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function c(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,c)}a((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.CrudService=void 0;const r=i(591),o=i(429);t.CrudService=class{constructor(e){this.client=e}getRecordById(e,t){return n(this,void 0,void 0,(function*(){const i=r.UtilsService.getUrl("",o.endpoints.crud.getObjectById,{typeId:e,id:t});return this.client.get(i)}))}getHistoricRecordUpdatesById(e){return n(this,void 0,void 0,(function*(){const t=r.UtilsService.getUrl("",o.endpoints.updatesRecord.getUpdateRecordByObjectId,{objectId:e});return this.client.get(t)}))}getRecords(e,t){return n(this,void 0,void 0,(function*(){const i=r.UtilsService.getUrl("",o.endpoints.crud.getObjects,{typeId:e});return this.client.post(i,t)}))}getNestedData(e,t){return n(this,void 0,void 0,(function*(){const i=r.UtilsService.getUrl("",o.endpoints.crud.getNestedData);return this.client.post(i,{nestedQuery:e,options:t})}))}query(e,t){return n(this,void 0,void 0,(function*(){const i=r.UtilsService.getUrl("",o.endpoints.crud.query),n=t?this.encodeSortKeys(t):{};return this.client.post(i,{tableName:e,queryOptions:n})}))}encodeSortKeys(e){if(!e||"object"!=typeof e)return e;const t={};for(const i of Object.keys(e))if("_sort"===i&&"object"==typeof e[i]){const n={};for(const t of Object.keys(e[i]))n[t.replace(/\./g,"@")]=e[i][t];t[i]=n}else"object"!=typeof e[i]||null===e[i]||Array.isArray(e[i])?t[i]=e[i]:t[i]=this.encodeSortKeys(e[i]);return t}deleteRecordById(e,t){return n(this,void 0,void 0,(function*(){const i=r.UtilsService.getUrl("",o.endpoints.crud.deleteObject,{typeId:e,id:t});return this.client.delete(i)}))}editRecordById(e,t,i){return n(this,void 0,void 0,(function*(){const n=r.UtilsService.getUrl("",o.endpoints.crud.editObjectProperties,{typeId:e,id:t});return this.client.request(n,{method:"PATCH",headers:{"Content-Type":"application/json",returnoption:"fullrecord"},body:JSON.stringify(i)})}))}createRecord(e,t){return n(this,void 0,void 0,(function*(){const i=r.UtilsService.getUrl("",o.endpoints.crud.createObject,{typeId:e});return this.client.request(i,{method:"POST",headers:{"Content-Type":"application/json",returnoption:"fullrecord"},body:JSON.stringify(t)})}))}addManyToManyReferenceRecord(e,t,i,s){return n(this,void 0,void 0,(function*(){const n=r.UtilsService.getUrl("",o.endpoints.crud.addManyToManyReference,{typeId:e,id:t});return this.client.patch(n,{propertyId:i,referenceId:s})}))}dropManyToManyReferenceRecord(e,t,i,s){return n(this,void 0,void 0,(function*(){const n=r.UtilsService.getUrl("",o.endpoints.crud.dropManyToManyReference,{typeId:e,id:t});return this.client.patch(n,{propertyId:i,referenceId:s})}))}getManyToManyReferencesRecords(e,t,i,s){return n(this,void 0,void 0,(function*(){const n=r.UtilsService.getUrl("",o.endpoints.crud.getManyToManyReferencesItems,{typeId:e,id:t,propertyName:i});return this.client.get(n,s)}))}}},279:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function c(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,c)}a((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.EmailService=void 0;const r=i(429),o=i(591);t.EmailService=class{constructor(e){this.client=e}sendEmail(e){return n(this,void 0,void 0,(function*(){if(e.attachments&&e.attachments.length>10)return{errors:{errorCode:"TOO_MANY_ATTACHMENTS",errorMessage:`Maximum number of attachments is 10. Received ${e.attachments.length}.`},data:null};if(e.attachments)for(const t of e.attachments){if(!t.url||"string"!=typeof t.url)return{errors:{errorCode:"INVALID_ATTACHMENT_URL",errorMessage:`Attachment ${t.filename} must have a valid URL`},data:null};if(!t.url.startsWith("http://")&&!t.url.startsWith("https://"))return{errors:{errorCode:"INVALID_ATTACHMENT_URL",errorMessage:`Attachment ${t.filename} must have a valid HTTP/HTTPS URL`},data:null}}return this.sendEmailWithDefaultDomain(e)}))}sendEmailWithDefaultDomain(e){return n(this,void 0,void 0,(function*(){const t=o.UtilsService.getUrl("",r.endpoints.email.sendEmail,{});return this.client.post(t,e)}))}}},589:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function c(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,c)}a((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.FilesService=void 0;const r=i(591),o=i(429);t.FilesService=class{constructor(e){this.client=e}uploadFile(e,t){return n(this,void 0,void 0,(function*(){let i=r.UtilsService.getUrl("",o.endpoints.files.uploadFile);return(null==t?void 0:t.compressFile)&&(i+="?compressFile=true"),this.client.post(i,e)}))}deleteFile(e){return n(this,void 0,void 0,(function*(){const t=r.UtilsService.getUrl("",o.endpoints.files.deleteFile,{fileName:e});return this.client.delete(t)}))}getDownloadUrl(e,t){return n(this,void 0,void 0,(function*(){const i=r.UtilsService.getUrl("",o.endpoints.files.getDownloadUrl,{fileName:e});return this.client.get(i,t)}))}generatePdfByTemplate(e,t,i){return n(this,void 0,void 0,(function*(){const n=r.UtilsService.getUrl("",o.endpoints.pdfTemplate.generatePdfByTemplate,{id:e});return this.client.post(n,{templateId:e,variables:t,name:i})}))}createPdfFromHtml(e){return n(this,void 0,void 0,(function*(){const t=r.UtilsService.getUrl("",o.endpoints.pdfTemplate.createPdfFromHtml);let i;return i="undefined"==typeof window?Buffer.from(e.html,"utf-8").toString("base64"):btoa(unescape(encodeURIComponent(e.html))),this.client.post(t,{base64HtmlString:i,name:e.name})}))}ocrOfImage(e){return n(this,void 0,void 0,(function*(){const t=r.UtilsService.getUrl("",o.endpoints.files.ocrOfImage);return this.client.post(t,{fileName:e})}))}ocrOfPdf(e){return n(this,void 0,void 0,(function*(){const t=r.UtilsService.getUrl("",o.endpoints.files.ocrOfPdf);return this.client.post(t,{fileName:e})}))}scanInvoice(e,t){return n(this,void 0,void 0,(function*(){const i=r.UtilsService.getUrl("",o.endpoints.files.scanInvoice);return this.client.post(i,{fileName:e,options:t})}))}scanDocument(e,t,i){return n(this,void 0,void 0,(function*(){const n=r.UtilsService.getUrl("",o.endpoints.files.scanDocument);return this.client.post(n,{fileName:e,properties:t,options:i})}))}}},675:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function c(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,c)}a((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.FilterService=void 0;const r=i(429),o=i(591);t.FilterService=class{constructor(e){this.client=e}lookUpFilter(e,t,i,s){return n(this,void 0,void 0,(function*(){const n=o.UtilsService.getUrl("",r.endpoints.filter.lookUpFilter,{idPage:e}),c={query:encodeURIComponent(JSON.stringify(t)),idsOfMultipleNodesToSearch:i?encodeURIComponent(JSON.stringify(i)):void 0,returnCount:null==s?void 0:s.toString()};return this.client.get(n,c)}))}nestedFilter(e,t,i){return n(this,void 0,void 0,(function*(){const n=o.UtilsService.getUrl("",r.endpoints.filter.nestedFilter,{}),s={nestedFilter:e,tableNameToGetResults:t,filterOptions:i};return this.client.post(n,s)}))}runCustomMongoAggregationQuery(e,t){return n(this,void 0,void 0,(function*(){const i=o.UtilsService.getUrl("",r.endpoints.filter.runCustomAggregationQuery),n={customMongoQuery:t,type:e};return this.client.post(i,n)}))}}},386:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function c(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,c)}a((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.NotificationService=void 0;const r=i(429),o=i(591);t.NotificationService=class{constructor(e){this.client=e}createNotification(e){return n(this,void 0,void 0,(function*(){const t=o.UtilsService.getUrl("",r.endpoints.notifications.createNotification,{});return this.client.post(t,{notification:e})}))}}},730:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function c(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,c)}a((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.OpenaiService=void 0;const r=i(591),o=i(429);t.OpenaiService=class{constructor(e){this.client=e}createCompletion(e){return n(this,void 0,void 0,(function*(){const t=r.UtilsService.getUrl("",o.endpoints.openai.createCompletion);return this.client.post(t,e)}))}createChatCompletion(e){return n(this,void 0,void 0,(function*(){const t=r.UtilsService.getUrl("",o.endpoints.openai.createChatCompletion);return this.client.post(t,e)}))}generateImage(e){return n(this,void 0,void 0,(function*(){const t=r.UtilsService.getUrl("",o.endpoints.openai.generateImage);return this.client.post(t,e)}))}editImage(e){return n(this,void 0,void 0,(function*(){const t=r.UtilsService.getUrl("",o.endpoints.openai.editImage);return this.client.post(t,e)}))}}},183:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function c(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,c)}a((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ScrappingService=void 0;const r=i(591),o=i(429);t.ScrappingService=class{constructor(e){this.client=e}scrape(e){return n(this,void 0,void 0,(function*(){const t=r.UtilsService.getUrl("",o.endpoints.webScraper.scrape);return this.client.post(t,e)}))}extract(e){return n(this,void 0,void 0,(function*(){const t=r.UtilsService.getUrl("",o.endpoints.webScraper.extract);return this.client.post(t,e)}))}screenshot(e){return n(this,void 0,void 0,(function*(){const t=r.UtilsService.getUrl("",o.endpoints.webScraper.screenshot);return this.client.post(t,e)}))}searchAndExtract(e){return n(this,void 0,void 0,(function*(){const t=r.UtilsService.getUrl("",o.endpoints.webScraper.searchAndExtract);return this.client.post(t,e)}))}}},706:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function c(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,c)}a((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.StatisticService=void 0;const r=i(429),o=i(591);t.StatisticService=class{constructor(e){this.client=e}getStatistic(e,t){return n(this,void 0,void 0,(function*(){const i=o.UtilsService.getUrl("",r.endpoints.statistics.getStatistic,{}),n={query:e,options:t};return this.client.post(i,n)}))}}},591:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.UtilsService=void 0,t.UtilsService=class{static getUrl(e,t,i){let n=e+t;for(const e in i)n=n.replace(`:${e}`,i[e]);return n}}}},t={};return function i(n){var r=t[n];if(void 0!==r)return r.exports;var o=t[n]={exports:{}};return e[n].call(o.exports,o,o.exports,i),o.exports}(492)})()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "totalum-api-sdk",
3
- "version": "3.0.5",
3
+ "version": "3.0.7",
4
4
  "description": "Totalum sdk wrapper and utils of totalum api",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -9,6 +9,10 @@
9
9
  ],
10
10
  "scripts": {
11
11
  "build": "tsc; npx webpack",
12
+ "test": "ts-node --project tests/tsconfig.json tests/run-all.ts",
13
+ "test:query": "ts-node --project tests/tsconfig.json tests/run-all.ts query",
14
+ "test:scraper": "ts-node --project tests/tsconfig.json tests/run-all.ts scraper",
15
+ "test:endpoints": "ts-node --project tests/tsconfig.json tests/run-all.ts endpoints",
12
16
  "test-endpoints": "ts-node test-all-endpoints.ts"
13
17
  },
14
18
  "author": "Totalum",
@@ -17,6 +21,7 @@
17
21
  "@types/node": "^24.8.1",
18
22
  "@types/qs": "^6.9.7",
19
23
  "axios": "^1.12.2",
24
+ "dotenv": "^17.3.1",
20
25
  "openai": "^4.104.0",
21
26
  "ts-loader": "^9.5.0",
22
27
  "ts-node": "^10.9.2",
@@ -1 +0,0 @@
1
- export {};