totalum-api-sdk 3.0.0 → 3.0.1

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/README.MD CHANGED
@@ -1,4 +1,4 @@
1
- ## Totalum API SDK (v3.0.0)
1
+ ## Totalum API SDK (v3.0.1)
2
2
 
3
3
  Official TypeScript/JavaScript SDK for the Totalum API. This library provides a fully typed, modern interface to interact with all Totalum endpoints.
4
4
 
@@ -178,7 +178,7 @@ const result = await totalumClient.crud.getRecords('your_table_name', {});
178
178
 
179
179
  ```html
180
180
  <head>
181
- <script src="https://cdn.jsdelivr.net/npm/totalum-api-sdk@3.0.0/dist/totalum-sdk.min.js"></script>
181
+ <script src="https://cdn.jsdelivr.net/npm/totalum-api-sdk@3.0.1/dist/totalum-sdk.min.js"></script>
182
182
  </head>
183
183
  <script>
184
184
  //Example of use TotalumSdk in your custom html page
@@ -508,8 +508,11 @@ if (result.errors) {
508
508
  return;
509
509
  }
510
510
 
511
- console.log('Modified count:', result.data.modifiedCount);
512
- console.log('Matched count:', result.data.matchedCount);
511
+ // Returns the full updated record
512
+ const updatedRecord = result.data;
513
+ console.log('Updated record:', updatedRecord);
514
+ console.log('New name:', updatedRecord.name);
515
+ console.log('New email:', updatedRecord.email);
513
516
 
514
517
  ```
515
518
 
@@ -532,8 +535,11 @@ if (result.errors) {
532
535
  return;
533
536
  }
534
537
 
535
- console.log('Created record ID:', result.data.insertedId);
536
- console.log('Acknowledged:', result.data.acknowledged);
538
+ // Returns the full created record
539
+ const createdRecord = result.data;
540
+ console.log('Created record:', createdRecord);
541
+ console.log('Record ID:', createdRecord._id);
542
+ console.log('Name:', createdRecord.name);
537
543
 
538
544
  ```
539
545
 
@@ -186,22 +186,6 @@ export interface UpdatesRecordResponse {
186
186
  typeId: string;
187
187
  updates: UpdateRecordChange[];
188
188
  }
189
- export interface CreateRecordResponse {
190
- acknowledged: boolean;
191
- insertedId: string;
192
- }
193
- export interface UpdatedRecordResponse {
194
- /** Indicates whether this write result was acknowledged. If not, then all other members of this result will be undefined */
195
- acknowledged: boolean;
196
- /** The number of documents that matched the filter */
197
- matchedCount?: number;
198
- /** The number of documents that were modified */
199
- modifiedCount?: number;
200
- /** The number of documents that were upserted */
201
- upsertedCount?: number;
202
- /** The identifier of the inserted document if an upsert took place */
203
- upsertedId?: string;
204
- }
205
189
  export interface ManyToManyReferenceResponse {
206
190
  acknowledged: boolean;
207
191
  matchedCount?: number;
@@ -1,5 +1,5 @@
1
1
  import { FilterSearchQueryI, NestedQuery, TotalumApiResponse } from "../common/interfaces";
2
- import { CreateRecordResponse, DataValues, DeleteObjectResponse, UpdatedRecordResponse, UpdatesRecordResponse } from "../common/response-types";
2
+ import { DataValues, DeleteObjectResponse, UpdatesRecordResponse } from "../common/response-types";
3
3
  import { FetchClient } from "../common/fetch-client";
4
4
  export declare class CrudService {
5
5
  private client;
@@ -44,25 +44,27 @@ export declare class CrudService {
44
44
  * @param {string} tableName - The type of the record. (table name)
45
45
  * @param {string} id - The ID of the record.
46
46
  * @param {T} properties - The properties to update.
47
- * @returns {Promise<TotalumApiResponse<UpdatedRecordResponse>>} - A promise that resolves to the updated record.
47
+ * @returns {Promise<TotalumApiResponse<T>>} - A promise that resolves to the updated record.
48
48
  */
49
- editRecordById<T = DataValues>(tableName: string, id: string, properties: Partial<T>): Promise<TotalumApiResponse<UpdatedRecordResponse>>;
49
+ editRecordById<T = DataValues>(tableName: string, id: string, properties: Partial<T>): Promise<TotalumApiResponse<T>>;
50
50
  /**
51
51
  * Creates a new record.
52
52
  * @param {string} tableName - The type of the record. (table name)
53
53
  * @param {T} record - The record data to create.
54
54
  * @returns {Promise<TotalumApiResponse<T>>} - A promise that resolves to the created record.
55
55
  */
56
- createRecord<T = DataValues>(tableName: string, record: Partial<T>): Promise<TotalumApiResponse<CreateRecordResponse>>;
56
+ createRecord<T = DataValues>(tableName: string, record: Partial<T>): Promise<TotalumApiResponse<T>>;
57
57
  /**
58
58
  * Adds a many-to-many reference between records.
59
59
  * @param {string} type - The type id of the record (table name)
60
60
  * @param {string} id - The id of the record that we want to add a many to many reference
61
61
  * @param {string} propertyName - The property that we want to add a many to many reference
62
62
  * @param {string} referenceId - The id of the record that we want to add as a many to many reference
63
- * @returns {Promise<TotalumApiResponse<CreateRecordResponse>>}
63
+ * @returns {Promise<TotalumApiResponse<{acknowledged: boolean}>>}
64
64
  */
65
- addManyToManyReferenceRecord(type: string, id: string, propertyName: string, referenceId: string): Promise<TotalumApiResponse<CreateRecordResponse>>;
65
+ addManyToManyReferenceRecord(type: string, id: string, propertyName: string, referenceId: string): Promise<TotalumApiResponse<{
66
+ acknowledged: boolean;
67
+ }>>;
66
68
  /**
67
69
  * Drops a many-to-many reference between records.
68
70
  * @param {string} type - The type id of the record (table name)
@@ -81,12 +81,19 @@ class CrudService {
81
81
  * @param {string} tableName - The type of the record. (table name)
82
82
  * @param {string} id - The ID of the record.
83
83
  * @param {T} properties - The properties to update.
84
- * @returns {Promise<TotalumApiResponse<UpdatedRecordResponse>>} - A promise that resolves to the updated record.
84
+ * @returns {Promise<TotalumApiResponse<T>>} - A promise that resolves to the updated record.
85
85
  */
86
86
  editRecordById(tableName, id, properties) {
87
87
  return __awaiter(this, void 0, void 0, function* () {
88
88
  const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.crud.editObjectProperties, { typeId: tableName, id });
89
- return this.client.patch(url, properties);
89
+ return this.client.request(url, {
90
+ method: 'PATCH',
91
+ headers: {
92
+ 'Content-Type': 'application/json',
93
+ 'returnoption': 'fullrecord'
94
+ },
95
+ body: JSON.stringify(properties)
96
+ });
90
97
  });
91
98
  }
92
99
  /**
@@ -98,7 +105,14 @@ class CrudService {
98
105
  createRecord(tableName, record) {
99
106
  return __awaiter(this, void 0, void 0, function* () {
100
107
  const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.crud.createObject, { typeId: tableName });
101
- return this.client.post(url, record);
108
+ return this.client.request(url, {
109
+ method: 'POST',
110
+ headers: {
111
+ 'Content-Type': 'application/json',
112
+ 'returnoption': 'fullrecord'
113
+ },
114
+ body: JSON.stringify(record)
115
+ });
102
116
  });
103
117
  }
104
118
  // many to many functions
@@ -108,7 +122,7 @@ class CrudService {
108
122
  * @param {string} id - The id of the record that we want to add a many to many reference
109
123
  * @param {string} propertyName - The property that we want to add a many to many reference
110
124
  * @param {string} referenceId - The id of the record that we want to add as a many to many reference
111
- * @returns {Promise<TotalumApiResponse<CreateRecordResponse>>}
125
+ * @returns {Promise<TotalumApiResponse<{acknowledged: boolean}>>}
112
126
  */
113
127
  addManyToManyReferenceRecord(type, id, propertyName, referenceId) {
114
128
  return __awaiter(this, void 0, void 0, function* () {
@@ -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}`}}}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"}}}}))}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 h=i(731);Object.defineProperty(t,"TotalumError",{enumerable:!0,get:function(){return h.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.patch(n,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.post(i,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}.`}};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`}};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`}}}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",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}`}}}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"}}}}))}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}.`}};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`}};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`}}}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)})()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "totalum-api-sdk",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Totalum sdk wrapper and utils of totalum api",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",