@supsis/supsis-js 1.0.0 → 1.1.0
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/supsis.cjs.js +132 -15
- package/dist/supsis.d.ts +4 -0
- package/dist/supsis.esm.js +132 -15
- package/dist/supsis.js +132 -15
- package/dist/supsis.min.js +3 -3
- package/dist/supsis.min.js.map +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +4 -0
package/dist/supsis.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Supsis API SDK - Browser ve Node.js için omnichannel messaging, chatbot, automation, task, ticket ve voice agent entegrasyonu
|
|
4
4
|
*
|
|
5
5
|
* @license MIT
|
|
6
|
-
* @author Supsis <info@
|
|
6
|
+
* @author Supsis Ai <info@softcand.com>
|
|
7
7
|
* @see https://supsis.com
|
|
8
8
|
*/
|
|
9
9
|
(function (global, factory) {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
/** Stage/Beta API - beta-api.supsis.live */
|
|
24
24
|
stage: 'https://beta-api.supsis.live',
|
|
25
25
|
/** Local development API */
|
|
26
|
-
local: 'https://tablet-api-local.supsis.live'
|
|
26
|
+
local: 'https://tablet-api-local.supsis.live:50101'
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
/**
|
|
@@ -40,7 +40,9 @@
|
|
|
40
40
|
/** Başarısız isteklerde retry sayısı */
|
|
41
41
|
retryCount: 3,
|
|
42
42
|
/** Retry'lar arası bekleme süresi (ms) */
|
|
43
|
-
retryDelay: 1000
|
|
43
|
+
retryDelay: 1000,
|
|
44
|
+
/** Debug logları göster */
|
|
45
|
+
verbose: false
|
|
44
46
|
};
|
|
45
47
|
|
|
46
48
|
/**
|
|
@@ -91,12 +93,48 @@
|
|
|
91
93
|
* @param {number} [config.timeout=30000] - İstek timeout süresi (ms)
|
|
92
94
|
* @param {number} [config.retryCount=3] - Retry sayısı
|
|
93
95
|
* @param {number} [config.retryDelay=1000] - Retry arası bekleme (ms)
|
|
96
|
+
* @param {boolean} [config.verbose=false] - Debug logları göster
|
|
94
97
|
*/
|
|
95
98
|
constructor(config) {
|
|
96
99
|
this.config = Object.assign({}, DEFAULT_CONFIG, config);
|
|
97
100
|
this.baseUrl = this._resolveBaseUrl();
|
|
98
101
|
this.token = null;
|
|
99
102
|
this.siteId = config.siteId || null;
|
|
103
|
+
this.verbose = config.verbose || false;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Verbose log yazdırır
|
|
108
|
+
* @private
|
|
109
|
+
* @param {string} type - Log tipi (info, warn, error, request, response)
|
|
110
|
+
* @param {...any} args - Log argümanları
|
|
111
|
+
*/
|
|
112
|
+
_log(type) {
|
|
113
|
+
if (!this.verbose) return;
|
|
114
|
+
|
|
115
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
|
116
|
+
var prefix = '[SupsisJS]';
|
|
117
|
+
var timestamp = new Date().toISOString();
|
|
118
|
+
|
|
119
|
+
switch (type) {
|
|
120
|
+
case 'info':
|
|
121
|
+
console.log.apply(console, [prefix, timestamp, 'INFO:'].concat(args));
|
|
122
|
+
break;
|
|
123
|
+
case 'warn':
|
|
124
|
+
console.warn.apply(console, [prefix, timestamp, 'WARN:'].concat(args));
|
|
125
|
+
break;
|
|
126
|
+
case 'error':
|
|
127
|
+
console.error.apply(console, [prefix, timestamp, 'ERROR:'].concat(args));
|
|
128
|
+
break;
|
|
129
|
+
case 'request':
|
|
130
|
+
console.log.apply(console, [prefix, timestamp, '→ REQUEST:'].concat(args));
|
|
131
|
+
break;
|
|
132
|
+
case 'response':
|
|
133
|
+
console.log.apply(console, [prefix, timestamp, '← RESPONSE:'].concat(args));
|
|
134
|
+
break;
|
|
135
|
+
default:
|
|
136
|
+
console.log.apply(console, [prefix, timestamp].concat(args));
|
|
137
|
+
}
|
|
100
138
|
}
|
|
101
139
|
|
|
102
140
|
/**
|
|
@@ -155,16 +193,28 @@
|
|
|
155
193
|
fetchOptions.body = JSON.stringify(options.body);
|
|
156
194
|
}
|
|
157
195
|
|
|
196
|
+
this._log('request', method.toUpperCase(), url, options.body ? JSON.stringify(options.body).substring(0, 200) : '');
|
|
197
|
+
|
|
158
198
|
let lastError;
|
|
159
199
|
const retryCount = options.retryCount !== undefined ? options.retryCount : this.config.retryCount;
|
|
160
200
|
|
|
161
201
|
for (let attempt = 0; attempt <= retryCount; attempt++) {
|
|
162
202
|
try {
|
|
203
|
+
if (attempt > 0) {
|
|
204
|
+
this._log('info', 'Retry attempt', attempt, 'of', retryCount);
|
|
205
|
+
}
|
|
206
|
+
|
|
163
207
|
const response = await this._fetchWithTimeout(url, fetchOptions);
|
|
164
|
-
|
|
208
|
+
const data = await this._handleResponse(response);
|
|
209
|
+
|
|
210
|
+
this._log('response', response.status, endpoint, typeof data === 'object' ? JSON.stringify(data).substring(0, 200) : data);
|
|
211
|
+
|
|
212
|
+
return data;
|
|
165
213
|
} catch (error) {
|
|
166
214
|
lastError = error;
|
|
167
215
|
|
|
216
|
+
this._log('error', 'Request failed:', error.message, 'Status:', error.statusCode || 'N/A');
|
|
217
|
+
|
|
168
218
|
// Auth hatalarında retry yapma
|
|
169
219
|
if (error.statusCode === HTTP_STATUS.UNAUTHORIZED ||
|
|
170
220
|
error.statusCode === HTTP_STATUS.FORBIDDEN) {
|
|
@@ -173,6 +223,7 @@
|
|
|
173
223
|
|
|
174
224
|
// Son deneme değilse bekle ve tekrar dene
|
|
175
225
|
if (attempt < retryCount) {
|
|
226
|
+
this._log('info', 'Waiting', this.config.retryDelay * (attempt + 1), 'ms before retry...');
|
|
176
227
|
await this._sleep(this.config.retryDelay * (attempt + 1));
|
|
177
228
|
}
|
|
178
229
|
}
|
|
@@ -186,23 +237,34 @@
|
|
|
186
237
|
* @private
|
|
187
238
|
*/
|
|
188
239
|
async _fetchWithTimeout(url, options) {
|
|
189
|
-
|
|
190
|
-
|
|
240
|
+
var self = this;
|
|
241
|
+
var controller = new AbortController();
|
|
242
|
+
var timeoutId = setTimeout(function() {
|
|
191
243
|
controller.abort();
|
|
192
244
|
}, this.config.timeout);
|
|
193
245
|
|
|
194
246
|
try {
|
|
195
|
-
|
|
247
|
+
var response = await fetch(url, Object.assign({}, options, {
|
|
196
248
|
signal: controller.signal
|
|
197
249
|
}));
|
|
198
250
|
clearTimeout(timeoutId);
|
|
199
251
|
return response;
|
|
200
252
|
} catch (error) {
|
|
201
253
|
clearTimeout(timeoutId);
|
|
254
|
+
|
|
255
|
+
self._log('error', 'Fetch error:', error.name, error.message);
|
|
256
|
+
|
|
202
257
|
if (error.name === 'AbortError') {
|
|
203
|
-
throw new SupsisAPIError('Request timeout', 408);
|
|
258
|
+
throw new SupsisAPIError('Request timeout after ' + self.config.timeout + 'ms', 408, { originalError: error.message });
|
|
204
259
|
}
|
|
205
|
-
|
|
260
|
+
|
|
261
|
+
// Network hataları için daha açıklayıcı hata mesajı
|
|
262
|
+
if (error.code === 'ECONNREFUSED' || error.code === 'ENOTFOUND' || error.message.indexOf('fetch') !== -1) {
|
|
263
|
+
throw new SupsisAPIError('Network error: ' + error.message, 0, { originalError: error.message, code: error.code });
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Diğer hatalar için SupsisAPIError'a çevir
|
|
267
|
+
throw new SupsisAPIError(error.message || 'Unknown fetch error', 0, { originalError: error.message });
|
|
206
268
|
}
|
|
207
269
|
}
|
|
208
270
|
|
|
@@ -3670,13 +3732,17 @@
|
|
|
3670
3732
|
/** @private */
|
|
3671
3733
|
this._config = config;
|
|
3672
3734
|
|
|
3735
|
+
/** @private */
|
|
3736
|
+
this._verbose = config.verbose || false;
|
|
3737
|
+
|
|
3673
3738
|
/** @private */
|
|
3674
3739
|
this._http = new HttpClient({
|
|
3675
3740
|
env: config.env || 'production',
|
|
3676
3741
|
baseApiAddress: config.baseApiAddress,
|
|
3677
3742
|
siteId: config.siteId,
|
|
3678
3743
|
timeout: config.timeout,
|
|
3679
|
-
retryCount: config.retryCount
|
|
3744
|
+
retryCount: config.retryCount,
|
|
3745
|
+
verbose: config.verbose
|
|
3680
3746
|
});
|
|
3681
3747
|
|
|
3682
3748
|
/** @private */
|
|
@@ -3690,6 +3756,38 @@
|
|
|
3690
3756
|
|
|
3691
3757
|
// Modülleri oluştur
|
|
3692
3758
|
this._initModules();
|
|
3759
|
+
|
|
3760
|
+
this._log('info', 'SupsisJS initialized', {
|
|
3761
|
+
env: config.env || 'production',
|
|
3762
|
+
baseApiAddress: config.baseApiAddress || 'default',
|
|
3763
|
+
siteId: config.siteId
|
|
3764
|
+
});
|
|
3765
|
+
}
|
|
3766
|
+
|
|
3767
|
+
/**
|
|
3768
|
+
* Verbose log yazdırır
|
|
3769
|
+
* @private
|
|
3770
|
+
*/
|
|
3771
|
+
_log(type) {
|
|
3772
|
+
if (!this._verbose) return;
|
|
3773
|
+
|
|
3774
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
|
3775
|
+
var prefix = '[SupsisJS]';
|
|
3776
|
+
var timestamp = new Date().toISOString();
|
|
3777
|
+
|
|
3778
|
+
switch (type) {
|
|
3779
|
+
case 'info':
|
|
3780
|
+
console.log.apply(console, [prefix, timestamp, 'INFO:'].concat(args));
|
|
3781
|
+
break;
|
|
3782
|
+
case 'warn':
|
|
3783
|
+
console.warn.apply(console, [prefix, timestamp, 'WARN:'].concat(args));
|
|
3784
|
+
break;
|
|
3785
|
+
case 'error':
|
|
3786
|
+
console.error.apply(console, [prefix, timestamp, 'ERROR:'].concat(args));
|
|
3787
|
+
break;
|
|
3788
|
+
default:
|
|
3789
|
+
console.log.apply(console, [prefix, timestamp].concat(args));
|
|
3790
|
+
}
|
|
3693
3791
|
}
|
|
3694
3792
|
|
|
3695
3793
|
/**
|
|
@@ -3795,17 +3893,34 @@
|
|
|
3795
3893
|
* console.log('Connected as:', supsis.currentUser.fullname);
|
|
3796
3894
|
*/
|
|
3797
3895
|
async connect() {
|
|
3896
|
+
var self = this;
|
|
3897
|
+
|
|
3798
3898
|
if (this._connected) {
|
|
3899
|
+
this._log('info', 'Already connected');
|
|
3799
3900
|
return this._user;
|
|
3800
3901
|
}
|
|
3801
3902
|
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3903
|
+
this._log('info', 'Connecting to Supsis API...');
|
|
3904
|
+
this._log('info', 'Base URL:', this._http.baseUrl);
|
|
3905
|
+
|
|
3906
|
+
var response;
|
|
3907
|
+
try {
|
|
3908
|
+
response = await this._http.post('/api/users/login', {
|
|
3909
|
+
email: this._config.email,
|
|
3910
|
+
password: this._config.password
|
|
3911
|
+
}, { skipAuth: true, retryCount: 0 });
|
|
3912
|
+
} catch (error) {
|
|
3913
|
+
self._log('error', 'Login failed:', error.message);
|
|
3914
|
+
throw error;
|
|
3915
|
+
}
|
|
3806
3916
|
|
|
3807
3917
|
if (!response || !response.token) {
|
|
3808
|
-
|
|
3918
|
+
var errorMsg = 'Login failed: No token received';
|
|
3919
|
+
if (response && response.message) {
|
|
3920
|
+
errorMsg = 'Login failed: ' + response.message;
|
|
3921
|
+
}
|
|
3922
|
+
self._log('error', errorMsg);
|
|
3923
|
+
throw new SupsisAPIError(errorMsg, 401, response);
|
|
3809
3924
|
}
|
|
3810
3925
|
|
|
3811
3926
|
this._token = response.token;
|
|
@@ -3813,6 +3928,8 @@
|
|
|
3813
3928
|
this._http.setToken(this._token);
|
|
3814
3929
|
this._connected = true;
|
|
3815
3930
|
|
|
3931
|
+
this._log('info', 'Connected successfully as:', this._user.fullname || this._user.email);
|
|
3932
|
+
|
|
3816
3933
|
return this._user;
|
|
3817
3934
|
}
|
|
3818
3935
|
|
package/dist/supsis.min.js
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* Supsis API SDK - Browser ve Node.js için omnichannel messaging, chatbot, automation, task, ticket ve voice agent entegrasyonu
|
|
4
4
|
*
|
|
5
5
|
* @license MIT
|
|
6
|
-
* @author Supsis <info@
|
|
6
|
+
* @author Supsis Ai <info@softcand.com>
|
|
7
7
|
* @see https://supsis.com
|
|
8
8
|
*/
|
|
9
|
-
!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).SupsisJS={})}(this,function(t){"use strict";const e={production:"https://api.supsis.live",stage:"https://beta-api.supsis.live",local:"https://tablet-api-local.supsis.live"},a={env:"production",baseApiAddress:null,timeout:3e4,retryCount:3,retryDelay:1e3},i=401,s=403,r="1.0.0";class n extends Error{constructor(t,e,a){super(t),this.name="SupsisAPIError",this.statusCode=e,this.response=a}}class d{constructor(t){this.config=Object.assign({},a,t),this.baseUrl=this._resolveBaseUrl(),this.token=null,this.siteId=t.siteId||null}_resolveBaseUrl(){return this.config.baseApiAddress?this.config.baseApiAddress.replace(/\/$/,""):e[this.config.env]||e.production}setToken(t){this.token=t}setSiteId(t){this.siteId=t}async request(t,e,a){a=a||{};const r=this._buildUrl(e,a.query),n=this._buildHeaders(a.headers,a.skipAuth),d={method:t.toUpperCase(),headers:n};let o;a.body&&"GET"!==t.toUpperCase()&&(d.body=JSON.stringify(a.body));const l=void 0!==a.retryCount?a.retryCount:this.config.retryCount;for(let t=0;t<=l;t++)try{const t=await this._fetchWithTimeout(r,d);return await this._handleResponse(t)}catch(e){if(o=e,e.statusCode===i||e.statusCode===s)throw e;t<l&&await this._sleep(this.config.retryDelay*(t+1))}throw o}async _fetchWithTimeout(t,e){const a=new AbortController,i=setTimeout(function(){a.abort()},this.config.timeout);try{const s=await fetch(t,Object.assign({},e,{signal:a.signal}));return clearTimeout(i),s}catch(t){if(clearTimeout(i),"AbortError"===t.name)throw new n("Request timeout",408);throw t}}_buildUrl(t,e){let a=this.baseUrl+t;if(e&&Object.keys(e).length>0){const t=new URLSearchParams;Object.keys(e).forEach(function(a){void 0!==e[a]&&null!==e[a]&&t.append(a,e[a])}),a=a+"?"+t.toString()}return a}_buildHeaders(t,e){const a={"Content-Type":"application/json",Accept:"application/json"};return this.siteId&&(a["site-id"]=this.siteId),!e&&this.token&&(a.Authorization="Bearer "+this.token),t&&Object.assign(a,t),a}async _handleResponse(t){let e;try{const a=t.headers.get("content-type");e=a&&-1!==a.indexOf("application/json")?await t.json():await t.text()}catch(t){e=null}if(!t.ok){const a=e&&e.message||e&&e.error||t.statusText||"API Error";throw new n(a,t.status,e)}return e}_sleep(t){return new Promise(function(e){setTimeout(e,t)})}get(t,e){return this.request("GET",t,e)}post(t,e,a){return this.request("POST",t,Object.assign({},a,{body:e}))}put(t,e,a){return this.request("PUT",t,Object.assign({},a,{body:e}))}patch(t,e,a){return this.request("PATCH",t,Object.assign({},a,{body:e}))}delete(t,e){return this.request("DELETE",t,e)}}class o{constructor(t){if(!t)throw new Error("HttpClient is required");this.http=t}_normalizePagination(t){const e=(t=t||{}).page||1,a=t.limit||20;return{page:e,limit:a,offset:void 0!==t.offset?t.offset:(e-1)*a}}_isValidObjectId(t){return!(!t||"string"!=typeof t)&&/^[a-fA-F0-9]{24}$/.test(t)}_validateRequired(t,e){const a=[];if(e.forEach(function(e){void 0!==t[e]&&null!==t[e]||a.push(e)}),a.length>0)throw new Error("Missing required parameters: "+a.join(", "))}_toISODate(t){return t?t instanceof Date?t.toISOString():"number"==typeof t||"string"==typeof t?new Date(t).toISOString():null:null}_cleanObject(t){if(!t||"object"!=typeof t)return t;const e={};return Object.keys(t).forEach(function(a){void 0!==t[a]&&(e[a]=t[a])}),e}}class l extends o{async get(t){return this._validateRequired({chatId:t},["chatId"]),await this.http.get("/api/conversations/"+t)}async getMessages(t,e){return this._validateRequired({chatId:t},["chatId"]),e=e||{},await this.http.get("/api/conversations/"+t+"/messages",{query:this._cleanObject({limit:e.limit,before:e.before})})}async getMessageHistory(t,e){this._validateRequired({chatId:t},["chatId"]),e=e||{};const a=this._normalizePagination(e);return await this.http.get("/api/conversations/"+t+"/v2-message-history",{query:{page:a.page,limit:a.limit}})}async list(t){t=t||{};const e=this._normalizePagination(t);return await this.http.get("/api/conversations/history",{query:this._cleanObject({status:t.status,channel:t.channel,userId:t.userId,visitorId:t.visitorId,startDate:this._toISODate(t.startDate),endDate:this._toISODate(t.endDate),page:e.page,limit:e.limit})})}async getStats(){return await this.http.get("/api/conversations/conversation-stat-realtime")}async addNote(t,e){return this._validateRequired({chatId:t,note:e},["chatId","note"]),await this.http.post("/api/conversations/"+t+"/note",{note:e})}async updateTags(t,e){return this._validateRequired({chatId:t},["chatId"]),await this.http.post("/api/conversations/"+t+"/tags",{tags:e||[]})}async rate(t,e,a){return this._validateRequired({chatId:t,rating:e},["chatId","rating"]),await this.http.post("/api/conversations/"+t+"/rate",{point:e,description:a})}async sendTranscript(t,e){return this._validateRequired({chatId:t,email:e},["chatId","email"]),await this.http.get("/api/conversations/"+t+"/sendTranscript",{query:{email:e}})}async destroy(t){return this._validateRequired({chatId:t},["chatId"]),await this.http.post("/api/conversations/"+t+"/destroy")}async getByUser(t,e){return this._validateRequired({userId:t},["userId"]),e=e||{},await this.http.get("/api/conversations/user/"+t,{query:this._cleanObject(e)})}async getWhatsAppContactList(t){return t=t||{},await this.http.get("/api/conversations/contact-list/whatsapp",{query:this._cleanObject(t)})}async getContactListByChannel(t,e){return this._validateRequired({channelId:t},["channelId"]),e=e||{},await this.http.get("/api/conversations/contact-list-by-channels",{query:this._cleanObject({channels:t,page:e.page,limit:e.limit})})}async getLastMessages(t){return this._validateRequired({chatIds:t},["chatIds"]),await this.http.post("/api/conversations/last-messages",{conversationIds:t})}async updateField(t,e,a){return this._validateRequired({chatId:t,key:e},["chatId","key"]),await this.http.put("/api/conversations/"+t+"/update-single-key",{key:e,value:a})}}class h extends o{async get(t){return this._validateRequired({contactId:t},["contactId"]),await this.http.get("/api/visitors/"+t)}async list(t){t=t||{};const e=this._normalizePagination(t);return await this.http.post("/api/visitors/visitor-list",{page:e.page,limit:e.limit,search:t.search,owner:t.owner,tags:t.tags,channel:t.channel})}async search(t,e){t=t||{},e=e||{};const a=this._normalizePagination(e);return await this.http.get("/api/visitors/search",{query:this._cleanObject({email:t.email,phone:t.phone,fullname:t.fullname,query:t.query,page:a.page,limit:a.limit})})}async advancedSearch(t,e,a){e=e||{};const i=this._normalizePagination(e);return await this.http.post("/api/visitors/contacts-by-advanced-filter",{filterGroups:t,cursor:{offset:i.offset,limit:i.limit},projectionFields:a})}async create(t){return this._validateRequired(t,["fullname"]),await this.http.post("/api/visitors/contacts",t)}async update(t,e){return this._validateRequired({contactId:t},["contactId"]),await this.http.post("/api/visitors/"+t+"/update",e)}async delete(t){return this._validateRequired({contactId:t},["contactId"]),await this.http.delete("/api/visitors/"+t)}async deleteMany(t){return this._validateRequired({contactIds:t},["contactIds"]),await this.http.post("/api/visitors/delete-multi-visitor",{visitorIds:t})}async addTag(t,e){return this._validateRequired({contactId:t,tagId:e},["contactId","tagId"]),await this.http.post("/api/visitors/updateTagVisitor/"+t,{tagId:e,action:"add"})}async removeTag(t,e){return this._validateRequired({contactId:t,tagId:e},["contactId","tagId"]),await this.http.post("/api/visitors/updateTagVisitor/"+t,{tagId:e,action:"remove"})}async block(t,e){return this._validateRequired({contactId:t},["contactId"]),await this.http.post("/api/visitors/"+t+"/block",{reason:e})}async unblock(t){return this._validateRequired({contactId:t},["contactId"]),await this.http.post("/api/visitors/"+t+"/unblock")}async getChatHistory(t,e){this._validateRequired({contactId:t},["contactId"]),e=e||{};const a=this._normalizePagination(e);return await this.http.get("/api/visitors/"+t+"/conversations-paged",{query:{page:a.page,limit:a.limit}})}async getNotes(t){return this._validateRequired({contactId:t},["contactId"]),await this.http.get("/api/visitors/"+t+"/notes-v2")}async addNote(t,e){return this._validateRequired({contactId:t,content:e},["contactId","content"]),await this.http.post("/api/visitors/"+t+"/notes-v2",{content:e})}async updateNote(t,e,a){return this._validateRequired({contactId:t,noteId:e,content:a},["contactId","noteId","content"]),await this.http.post("/api/visitors/"+t+"/notes-v2/"+e,{content:a})}async deleteNote(t){return this._validateRequired({noteId:t},["noteId"]),await this.http.delete("/api/visitors/notes-v2/"+t)}async updateProperty(t,e,a){return this._validateRequired({contactId:t,propertyId:e},["contactId","propertyId"]),await this.http.put("/api/visitors/"+t+"/contact-property/"+e,{value:a})}async changeOwner(t,e){return this._validateRequired({contactId:t,ownerId:e},["contactId","ownerId"]),await this.http.post("/api/visitors/"+t+"/update",{owner:e})}async updatePreferredAgents(t,e){return this._validateRequired({contactId:t},["contactId"]),await this.http.post("/api/visitors/"+t+"/update-preferred-agents",{agents:e||[]})}async getMedia(t,e){return this._validateRequired({contactId:t},["contactId"]),await this.http.get("/api/visitors/"+t+"/media",{query:this._cleanObject(e)})}async merge(t,e){return this._validateRequired({primaryContactId:t,secondaryContactId:e},["primaryContactId","secondaryContactId"]),await this.http.post("/api/visitors/merge-visitors",{primaryVisitorId:t,secondaryVisitorId:e})}async downloadExcel(t){return await this.http.post("/api/visitors/visitor-list/download",t||{})}}class c extends o{async get(t){return this._validateRequired({messageId:t},["messageId"]),await this.http.post("/api/messages/get-message",{messageId:t})}async list(t,e){return this._validateRequired({conversationId:t},["conversationId"]),e=e||{},await this.http.get("/api/messages/"+t,{query:this._cleanObject({limit:e.limit,before:e.before,after:e.after})})}async search(t){this._validateRequired(t,["query"]);const e=this._normalizePagination(t);return await this.http.post("/api/messages/search-messages",{query:t.query,conversationId:t.conversationId,visitorId:t.visitorId,userId:t.userId,startDate:this._toISODate(t.startDate),endDate:this._toISODate(t.endDate),page:e.page,limit:e.limit})}async getMany(t){return this._validateRequired({messageIds:t},["messageIds"]),await this.http.post("/api/messages/get-message",{messageIds:t})}}class p extends o{async get(t){return this._validateRequired({taskId:t},["taskId"]),await this.http.get("/api/tasks/"+t+"/detail")}async list(t,e){return this._validateRequired({workflowId:t},["workflowId"]),(e=e||{}).pipelineId?await this.http.get("/api/tasks/"+t+"/"+e.pipelineId):await this.http.get("/api/tasks/"+t)}async create(t){return this._validateRequired(t,["title","workflowId","pipelineId"]),await this.http.post("/api/tasks",{title:t.title,workflowId:t.workflowId,pipelineId:t.pipelineId,description:t.description,assignee:t.assignee,dueDate:this._toISODate(t.dueDate),priority:t.priority,contactId:t.contactId,customFields:t.customFields})}async createSimple(t){return this._validateRequired(t,["title","workflowId","pipelineId"]),await this.http.post("/api/tasks/simple",t)}async update(t,e){return this._validateRequired({taskId:t},["taskId"]),await this.http.patch("/api/tasks/"+t,e)}async delete(t){return this._validateRequired({taskId:t},["taskId"]),await this.http.delete("/api/tasks/"+t)}async move(t,e,a){return this._validateRequired({taskId:t,pipelineId:e},["taskId","pipelineId"]),await this.http.patch("/api/tasks/"+t+"/position",{pipelineId:e,position:a})}async complete(t){return this._validateRequired({taskId:t},["taskId"]),await this.http.patch("/api/tasks/"+t+"/done")}async archive(t){return this._validateRequired({taskId:t},["taskId"]),await this.http.patch("/api/tasks/"+t+"/archive")}async deleteMany(t){return this._validateRequired({taskIds:t},["taskIds"]),await this.http.post("/api/tasks/multiple/delete",{taskIds:t})}async moveMany(t,e){return this._validateRequired({taskIds:t,pipelineId:e},["taskIds","pipelineId"]),await this.http.post("/api/tasks/multiple/change-pipeline",{taskIds:t,pipelineId:e})}async completeMany(t){return this._validateRequired({taskIds:t},["taskIds"]),await this.http.post("/api/tasks/multiple/done",{taskIds:t})}async getActivities(t){return this._validateRequired({taskId:t},["taskId"]),await this.http.get("/api/tasks/get-task-activity/"+t)}async listCompleted(t){return await this.http.get("/api/tasks/done-tasks",{query:this._cleanObject(t)})}async listArchived(t){return await this.http.get("/api/tasks/archive-tasks",{query:this._cleanObject(t)})}async listByDate(t){return this._validateRequired({date:t},["date"]),await this.http.get("/api/tasks/get-event-list-by-date",{query:{date:this._toISODate(t)}})}async listByContact(t){return this._validateRequired({contactId:t},["contactId"]),await this.http.get("/api/tasks/visitor-tasks",{query:{visitorId:t}})}async listWorkflows(){return await this.http.get("/api/tasks/workflows")}async getWorkflow(t){return this._validateRequired({workflowId:t},["workflowId"]),await this.http.get("/api/tasks/workflows/"+t)}async createWorkflow(t){return this._validateRequired(t,["name"]),await this.http.post("/api/tasks/workflows",t)}async updateWorkflow(t,e){return this._validateRequired({workflowId:t},["workflowId"]),await this.http.patch("/api/tasks/workflows/"+t,e)}async deleteWorkflow(t){return this._validateRequired({workflowId:t},["workflowId"]),await this.http.delete("/api/tasks/workflows/"+t)}async getWorkflowFull(t){return this._validateRequired({workflowId:t},["workflowId"]),await this.http.get("/api/tasks/workflows/"+t+"/full")}async getWorkflowReports(t){return this._validateRequired({workflowId:t},["workflowId"]),await this.http.get("/api/tasks/workflows/"+t+"/reports")}async listPipelines(t){return this._validateRequired({workflowId:t},["workflowId"]),await this.http.get("/api/tasks/workflows/"+t+"/pipelines")}async createPipeline(t,e){return this._validateRequired({workflowId:t},["workflowId"]),this._validateRequired(e,["name"]),await this.http.post("/api/tasks/workflows/"+t+"/pipelines",e)}async updatePipeline(t,e){return this._validateRequired({pipelineId:t},["pipelineId"]),await this.http.patch("/api/tasks/pipelines/"+t,e)}async deletePipeline(t){return this._validateRequired({pipelineId:t},["pipelineId"]),await this.http.delete("/api/tasks/pipelines/"+t)}async updatePipelinePosition(t,e,a){return this._validateRequired({workflowId:t,pipelineId:e},["workflowId","pipelineId"]),await this.http.patch("/api/tasks/"+t+"/"+e+"/position",{position:a})}}class u extends o{async makeCall(t){return this._validateRequired(t,["agentId","toNumber","fromNumber"]),await this.http.post("/api/voice-agent/calls/phone",{overrideAgentId:t.agentId,toNumber:t.toNumber,fromNumber:t.fromNumber,retellLlmDynamicVariables:t.variables||{},metadata:t.metadata})}async makeWebCall(t){return this._validateRequired(t,["agentId"]),await this.http.post("/api/voice-agent/calls/web",{agentId:t.agentId,retellLlmDynamicVariables:t.variables||{}})}async makeBatchCall(t){return this._validateRequired(t,["agentId","fromNumber","calls"]),await this.http.post("/api/voice-agent/calls/batch",t)}async getCall(t){return this._validateRequired({callId:t},["callId"]),await this.http.get("/api/voice-agent/calls/"+t)}async listCalls(t){t=t||{};const e=this._normalizePagination(t);return await this.http.post("/api/voice-agent/calls/list",{agentId:t.agentId,status:t.status,startDate:this._toISODate(t.startDate),endDate:this._toISODate(t.endDate),page:e.page,limit:e.limit})}async listBatchCalls(){return await this.http.get("/api/voice-agent/calls/batch")}async listAgents(){return await this.http.get("/api/voice-agent/agents")}async getAgent(t){return this._validateRequired({agentId:t},["agentId"]),await this.http.get("/api/voice-agent/agents/"+t)}async createAgent(t){return this._validateRequired(t,["name"]),await this.http.post("/api/voice-agent/agents",t)}async updateAgent(t,e){return this._validateRequired({agentId:t},["agentId"]),await this.http.patch("/api/voice-agent/agents/"+t,e)}async deleteAgent(t){return this._validateRequired({agentId:t},["agentId"]),await this.http.delete("/api/voice-agent/agents/"+t)}async listNumbers(){return await this.http.get("/api/voice-agent/numbers")}async getNumber(t){return this._validateRequired({phoneNumber:t},["phoneNumber"]),await this.http.get("/api/voice-agent/numbers/"+encodeURIComponent(t))}async listVoices(){return await this.http.get("/api/voice-agent/voices")}async getVoice(t){return this._validateRequired({voiceId:t},["voiceId"]),await this.http.get("/api/voice-agent/voices/"+t)}async listKnowledgeBases(){return await this.http.get("/api/voice-agent/knowledgebases")}async getKnowledgeBase(t){return this._validateRequired({knowledgeBaseId:t},["knowledgeBaseId"]),await this.http.get("/api/voice-agent/knowledgebases/"+t)}async deleteKnowledgeBase(t){return this._validateRequired({knowledgeBaseId:t},["knowledgeBaseId"]),await this.http.delete("/api/voice-agent/knowledgebases/"+t)}async listLLMs(){return await this.http.get("/api/voice-agent/llms")}async getLLM(t){return this._validateRequired({llmId:t},["llmId"]),await this.http.get("/api/voice-agent/llms/"+t)}async createLLM(t){return await this.http.post("/api/voice-agent/llms",t)}async updateLLM(t,e){return this._validateRequired({llmId:t},["llmId"]),await this.http.patch("/api/voice-agent/llms/"+t,e)}async deleteLLM(t){return this._validateRequired({llmId:t},["llmId"]),await this.http.delete("/api/voice-agent/llms/"+t)}}class w extends o{async get(t){return this._validateRequired({assetId:t},["assetId"]),await this.http.get("/api/assets/id/"+t)}getUrl(t){return t?"https://supsis-storage.s3.amazonaws.com/"+t:null}}class I extends o{async list(){return await this.http.get("/api/tables")}async get(t){return this._validateRequired({tableId:t},["tableId"]),await this.http.get("/api/tables/"+t)}async create(t){return this._validateRequired(t,["name"]),await this.http.put("/api/tables",t)}async update(t,e){return this._validateRequired({tableId:t},["tableId"]),await this.http.post("/api/tables/"+t,e)}async delete(t){return this._validateRequired({tableId:t},["tableId"]),await this.http.delete("/api/tables/"+t)}async duplicate(t){return this._validateRequired({tableId:t},["tableId"]),await this.http.post("/api/tables/"+t+"/duplicate")}async export(t){return this._validateRequired({tableId:t},["tableId"]),await this.http.get("/api/tables/"+t+"/export")}async import(t){return await this.http.post("/api/tables/import",t)}async listFields(t){return this._validateRequired({tableId:t},["tableId"]),await this.http.get("/api/tables/"+t+"/fields")}async createField(t,e){return this._validateRequired({tableId:t},["tableId"]),this._validateRequired(e,["name","type"]),await this.http.put("/api/tables/"+t+"/fields",e)}async updateField(t,e,a){return this._validateRequired({tableId:t,fieldId:e},["tableId","fieldId"]),await this.http.post("/api/tables/"+t+"/fields/"+e,a)}async deleteField(t,e){return this._validateRequired({tableId:t,fieldId:e},["tableId","fieldId"]),await this.http.delete("/api/tables/"+t+"/fields/"+e)}async listRecords(t,e){this._validateRequired({tableId:t},["tableId"]),e=e||{};const a=this._normalizePagination(e);return await this.http.post("/api/tables/"+t+"/records",{filters:e.filters,sort:e.sort,page:a.page,limit:a.limit,viewId:e.viewId})}async getRecord(t,e){return this._validateRequired({tableId:t,recordId:e},["tableId","recordId"]),await this.http.get("/api/tables/"+t+"/records/"+e)}async createRecord(t,e){return this._validateRequired({tableId:t},["tableId"]),await this.http.put("/api/tables/"+t+"/records",e)}async createEmptyRecord(t){return this._validateRequired({tableId:t},["tableId"]),await this.http.put("/api/tables/"+t+"/records/empty")}async createManyRecords(t,e){return this._validateRequired({tableId:t,records:e},["tableId","records"]),await this.http.put("/api/tables/"+t+"/records/multi",{records:e})}async updateRecord(t,e,a){return this._validateRequired({tableId:t,recordId:e},["tableId","recordId"]),await this.http.post("/api/tables/"+t+"/records/"+e+"/update",a)}async updateManyRecords(t,e,a,i){return this._validateRequired({tableId:t,fieldId:e,recordIds:a},["tableId","fieldId","recordIds"]),await this.http.put("/api/tables/"+t+"/fields/"+e+"/records",{recordIds:a,value:i})}async deleteRecord(t,e){return this._validateRequired({tableId:t,recordId:e},["tableId","recordId"]),await this.http.delete("/api/tables/"+t+"/records/"+e)}async deleteManyRecords(t,e){return this._validateRequired({tableId:t,recordIds:e},["tableId","recordIds"]),await this.http.post("/api/tables/"+t+"/records/delete",{recordIds:e})}async duplicateRecords(t,e){return this._validateRequired({tableId:t,recordIds:e},["tableId","recordIds"]),await this.http.post("/api/tables/"+t+"/records/duplicate",{recordIds:e})}async searchFieldValues(t,e,a){return this._validateRequired({tableId:t,fieldId:e},["tableId","fieldId"]),await this.http.get("/api/tables/"+t+"/"+e+"/search",{query:{q:a}})}async listViews(t){return this._validateRequired({tableId:t},["tableId"]),await this.http.get("/api/tables/"+t+"/views")}async createView(t,e){return this._validateRequired({tableId:t},["tableId"]),this._validateRequired(e,["name"]),await this.http.put("/api/tables/"+t+"/views",e)}async updateView(t,e,a){return this._validateRequired({tableId:t,viewId:e},["tableId","viewId"]),await this.http.post("/api/tables/"+t+"/views/"+e,a)}async deleteView(t,e){return this._validateRequired({tableId:t,viewId:e},["tableId","viewId"]),await this.http.delete("/api/tables/"+t+"/views/"+e)}async listPages(t){return this._validateRequired({tableId:t},["tableId"]),await this.http.get("/api/tables/"+t+"/pages")}async getPage(t,e){return this._validateRequired({tableId:t,pageId:e},["tableId","pageId"]),await this.http.get("/api/tables/"+t+"/pages/"+e)}async createPage(t,e){return this._validateRequired({tableId:t},["tableId"]),await this.http.put("/api/tables/"+t+"/pages",e)}async listWidgets(t,e){return this._validateRequired({tableId:t,pageId:e},["tableId","pageId"]),await this.http.get("/api/tables/"+t+"/pages/"+e+"/widgets")}async getWidgetChartData(t,e,a){return this._validateRequired({tableId:t,widgetId:e},["tableId","widgetId"]),await this.http.post("/api/tables/"+t+"/widgets/"+e+"/chart-data",a||{})}}class g extends o{async list(){return await this.http.get("/api/module")}async create(t){return this._validateRequired(t,["name","displayName"]),await this.http.post("/api/module",t)}async update(t,e){return this._validateRequired({moduleName:t},["moduleName"]),await this.http.post("/api/module/"+t,e)}async delete(t){return this._validateRequired({moduleId:t},["moduleId"]),await this.http.delete("/api/module/"+t)}async listRecords(t,e){this._validateRequired({moduleName:t},["moduleName"]),e=e||{};const a=this._normalizePagination(e);return await this.http.post("/api/module/"+t+"/records",{filters:e.filters,sort:e.sort,page:a.page,limit:a.limit})}async listAllRecords(t){return this._validateRequired({moduleName:t},["moduleName"]),await this.http.get("/api/module/"+t+"/records")}async searchRecords(t,e){return this._validateRequired({moduleName:t,query:e},["moduleName","query"]),await this.http.get("/api/module/"+t+"/records/search",{query:{q:e}})}async getRecord(t,e){return this._validateRequired({moduleName:t,recordId:e},["moduleName","recordId"]),await this.http.get("/api/module/"+t+"/records/"+e)}async createRecord(t,e){return this._validateRequired({moduleName:t},["moduleName"]),await this.http.put("/api/module/"+t+"/records",e)}async createManyRecords(t,e){return this._validateRequired({moduleName:t,records:e},["moduleName","records"]),await this.http.put("/api/module/"+t+"/records/multi",{records:e})}async updateRecord(t,e,a){return this._validateRequired({moduleName:t,recordId:e},["moduleName","recordId"]),await this.http.put("/api/module/"+t+"/records/"+e,a)}async deleteRecord(t,e){return this._validateRequired({moduleName:t,recordId:e},["moduleName","recordId"]),await this.http.delete("/api/module/"+t+"/records/"+e)}async listContactRelatedRecords(t){return this._validateRequired({contactId:t},["contactId"]),await this.http.get("/api/module/records/contact-related-list",{query:{contactId:t}})}async listModuleRelatedRecords(t,e){return this._validateRequired({moduleName:t,recordId:e},["moduleName","recordId"]),await this.http.get("/api/module/records/module-related-list",{query:{moduleName:t,recordId:e}})}}class y extends o{async me(){return await this.http.get("/api/users/me")}async updateMe(t){return await this.http.put("/api/users/me",t)}async get(t){return this._validateRequired({userId:t},["userId"]),await this.http.get("/api/users/user/"+t)}async list(t){t=t||{};const e=this._normalizePagination(t);return await this.http.get("/api/users/pagination",{query:this._cleanObject({page:e.page,limit:e.limit,status:t.status})})}async listOnline(){return await this.http.get("/api/users/list-online-users")}async create(t){return this._validateRequired(t,["fullname","email","password"]),await this.http.post("/api/users",t)}async update(t,e){return this._validateRequired({userId:t},["userId"]),await this.http.put("/api/users/"+t,e)}async delete(t){return this._validateRequired({userId:t},["userId"]),await this.http.delete("/api/users/"+t)}async updatePassword(t,e){return this._validateRequired({userId:t,newPassword:e},["userId","newPassword"]),await this.http.put("/api/users/"+t+"/updatePassword",{password:e})}async updateOnlineStatus(t,e){return this._validateRequired({userId:t},["userId"]),await this.http.put("/api/users/"+t+"/onlineStatus",{isOnline:e})}async updateStatus(t,e){return this._validateRequired({userId:t,status:e},["userId","status"]),await this.http.put("/api/users/"+t+"/status",{status:e})}async getActiveCount(){return await this.http.get("/api/users/active-user-count")}async getNotificationSettings(){return await this.http.get("/api/users/me/notification-settings")}async completeTutorial(t){return this._validateRequired({tutorialKey:t},["tutorialKey"]),await this.http.post("/api/users/me/setup-guide/"+t)}async logout(){return await this.http.get("/api/users/logout")}}class v extends o{async list(t){const e=t?"/api/tags/"+t:"/api/tags";return await this.http.get(e)}async create(t){return this._validateRequired(t,["name"]),await this.http.post("/api/tags",t)}async update(t){return this._validateRequired(t,["_id"]),await this.http.patch("/api/tags",t)}async delete(t){return this._validateRequired({tagId:t},["tagId"]),await this.http.delete("/api/tags/"+t)}}class _ extends o{async getCurrentPlan(){return await this.http.get("/api/sites/current-plan")}async getFeatures(){return await this.http.get("/api/sites/features")}async getWallet(){return await this.http.get("/api/sites/wallet")}async getWalletActivities(t){return t=t||{},await this.http.get("/api/sites/wallet/activities",{query:this._cleanObject({walletType:t.walletType,startDate:this._toISODate(t.startDate),endDate:this._toISODate(t.endDate)})})}async depositWallet(t,e){return this._validateRequired({walletType:t,amount:e},["walletType","amount"]),await this.http.post("/api/sites/wallet/"+t,{amount:e})}async getAutoRebalanceSettings(t){return this._validateRequired({walletType:t},["walletType"]),await this.http.get("/api/sites/wallet/"+t+"/auto-rebalance")}async updateAutoRebalanceSettings(t,e){return this._validateRequired({walletType:t},["walletType"]),await this.http.put("/api/sites/wallet/"+t+"/auto-rebalance",e)}async getConversationUsage(){return await this.http.get("/api/sites/conversation-usages")}async getStorageUsage(t){return await this.http.post("/api/sites/storage-usages",t||{})}async checkIntegrationStatus(t){return await this.http.post("/api/public/sites/check-integration-status",t||{})}}class m extends o{async list(t){t=t||{};const e=this._normalizePagination(t);return await this.http.post("/api/cache/list",{pattern:t.pattern,type:t.type,actorType:t.actorType,page:e.page,limit:e.limit})}async write(t,e,a){this._validateRequired({key:t},["key"]);const i={key:t,value:e,type:(a=a||{}).type||"public",dataType:a.dataType||"mixed"};if(a.expiresIn){const t=new Date,e={seconds:1e3,minutes:6e4,hours:36e5,days:864e5,weeks:6048e5,months:2592e6},s=a.expiresIn.value*(e[a.expiresIn.unit]||e.hours);i.expiresAt=new Date(t.getTime()+s).toISOString()}else a.expiresAt&&(i.expiresAt=this._toISODate(a.expiresAt));return await this.http.post("/api/cache/write",i)}async read(t,e){this._validateRequired({key:t},["key"]);try{const a=await this.http.post("/api/cache/list",{pattern:t,limit:1});return a&&a.data&&a.data.length>0?a.data[0].value:void 0!==e?e:null}catch(t){return void 0!==e?e:null}}async update(t,e){return this._validateRequired({cacheId:t},["cacheId"]),await this.http.post("/api/cache/"+t+"/update",{value:e})}async extend(t,e){this._validateRequired({cacheId:t,expiresIn:e},["cacheId","expiresIn"]);const a={seconds:1e3,minutes:6e4,hours:36e5,days:864e5,weeks:6048e5,months:2592e6},i=new Date,s=e.value*(a[e.unit]||a.hours),r=new Date(i.getTime()+s);return await this.http.post("/api/cache/"+t+"/extend",{expiresAt:r.toISOString()})}async makeNeverExpire(t){return this._validateRequired({cacheId:t},["cacheId"]),await this.http.post("/api/cache/"+t+"/never-expire")}async delete(t){return this._validateRequired({cacheId:t},["cacheId"]),await this.http.delete("/api/cache/"+t)}async deleteMany(t){return this._validateRequired({cacheIds:t},["cacheIds"]),await this.http.post("/api/cache/bulk-delete",{cacheIds:t})}async deleteByActor(t,e){return this._validateRequired({actorType:t,actorId:e},["actorType","actorId"]),await this.http.post("/api/cache/delete-by-actor",{actorType:t,actorId:e})}async deleteByPattern(t){return this._validateRequired({pattern:t},["pattern"]),await this.http.post("/api/cache/delete-by-pattern",{pattern:t})}}class q{constructor(t){if(!t)throw new Error("Config is required");this._validateConfig(t),this._config=t,this._http=new d({env:t.env||"production",baseApiAddress:t.baseApiAddress,siteId:t.siteId,timeout:t.timeout,retryCount:t.retryCount}),this._connected=!1,this._token=null,this._user=null,this._initModules()}_validateConfig(t){if(!t.email)throw new Error("email is required");if(!t.password)throw new Error("password is required");if(!t.siteId)throw new Error("siteId is required")}_initModules(){this.chat=new l(this._http),this.contact=new h(this._http),this.message=new c(this._http),this.task=new p(this._http),this.aicall=new u(this._http),this.asset=new w(this._http),this.table=new I(this._http),this.module=new g(this._http),this.user=new y(this._http),this.tag=new v(this._http),this.site=new _(this._http),this.cache=new m(this._http)}async connect(){if(this._connected)return this._user;const t=await this._http.post("/api/users/login",{email:this._config.email,password:this._config.password},{skipAuth:!0});if(!t||!t.token)throw new n("Login failed: No token received",401);return this._token=t.token,this._user=t.user||t,this._http.setToken(this._token),this._connected=!0,this._user}async disconnect(){if(this._connected){try{await this._http.get("/api/users/logout")}catch(t){}this._token=null,this._user=null,this._http.setToken(null),this._connected=!1}}get isConnected(){return this._connected}get currentUser(){return this._user}get token(){return this._token}get version(){return r}get http(){return this._http}setToken(t){this._token=t,this._http.setToken(t),this._connected=!0}}
|
|
9
|
+
!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).SupsisJS={})}(this,function(t){"use strict";const e={production:"https://api.supsis.live",stage:"https://beta-api.supsis.live",local:"https://tablet-api-local.supsis.live:50101"},a={env:"production",baseApiAddress:null,timeout:3e4,retryCount:3,retryDelay:1e3,verbose:!1},i=401,s=403,r="1.0.0";class n extends Error{constructor(t,e,a){super(t),this.name="SupsisAPIError",this.statusCode=e,this.response=a}}class d{constructor(t){this.config=Object.assign({},a,t),this.baseUrl=this._resolveBaseUrl(),this.token=null,this.siteId=t.siteId||null,this.verbose=t.verbose||!1}_log(t){if(this.verbose){var e=Array.prototype.slice.call(arguments,1),a="[SupsisJS]",i=(new Date).toISOString();switch(t){case"info":console.log.apply(console,[a,i,"INFO:"].concat(e));break;case"warn":console.warn.apply(console,[a,i,"WARN:"].concat(e));break;case"error":console.error.apply(console,[a,i,"ERROR:"].concat(e));break;case"request":console.log.apply(console,[a,i,"→ REQUEST:"].concat(e));break;case"response":console.log.apply(console,[a,i,"← RESPONSE:"].concat(e));break;default:console.log.apply(console,[a,i].concat(e))}}}_resolveBaseUrl(){return this.config.baseApiAddress?this.config.baseApiAddress.replace(/\/$/,""):e[this.config.env]||e.production}setToken(t){this.token=t}setSiteId(t){this.siteId=t}async request(t,e,a){a=a||{};const r=this._buildUrl(e,a.query),n=this._buildHeaders(a.headers,a.skipAuth),d={method:t.toUpperCase(),headers:n};let o;a.body&&"GET"!==t.toUpperCase()&&(d.body=JSON.stringify(a.body)),this._log("request",t.toUpperCase(),r,a.body?JSON.stringify(a.body).substring(0,200):"");const l=void 0!==a.retryCount?a.retryCount:this.config.retryCount;for(let t=0;t<=l;t++)try{t>0&&this._log("info","Retry attempt",t,"of",l);const a=await this._fetchWithTimeout(r,d),i=await this._handleResponse(a);return this._log("response",a.status,e,"object"==typeof i?JSON.stringify(i).substring(0,200):i),i}catch(e){if(o=e,this._log("error","Request failed:",e.message,"Status:",e.statusCode||"N/A"),e.statusCode===i||e.statusCode===s)throw e;t<l&&(this._log("info","Waiting",this.config.retryDelay*(t+1),"ms before retry..."),await this._sleep(this.config.retryDelay*(t+1)))}throw o}async _fetchWithTimeout(t,e){var a=new AbortController,i=setTimeout(function(){a.abort()},this.config.timeout);try{var s=await fetch(t,Object.assign({},e,{signal:a.signal}));return clearTimeout(i),s}catch(t){if(clearTimeout(i),this._log("error","Fetch error:",t.name,t.message),"AbortError"===t.name)throw new n("Request timeout after "+this.config.timeout+"ms",408,{originalError:t.message});if("ECONNREFUSED"===t.code||"ENOTFOUND"===t.code||-1!==t.message.indexOf("fetch"))throw new n("Network error: "+t.message,0,{originalError:t.message,code:t.code});throw new n(t.message||"Unknown fetch error",0,{originalError:t.message})}}_buildUrl(t,e){let a=this.baseUrl+t;if(e&&Object.keys(e).length>0){const t=new URLSearchParams;Object.keys(e).forEach(function(a){void 0!==e[a]&&null!==e[a]&&t.append(a,e[a])}),a=a+"?"+t.toString()}return a}_buildHeaders(t,e){const a={"Content-Type":"application/json",Accept:"application/json"};return this.siteId&&(a["site-id"]=this.siteId),!e&&this.token&&(a.Authorization="Bearer "+this.token),t&&Object.assign(a,t),a}async _handleResponse(t){let e;try{const a=t.headers.get("content-type");e=a&&-1!==a.indexOf("application/json")?await t.json():await t.text()}catch(t){e=null}if(!t.ok){const a=e&&e.message||e&&e.error||t.statusText||"API Error";throw new n(a,t.status,e)}return e}_sleep(t){return new Promise(function(e){setTimeout(e,t)})}get(t,e){return this.request("GET",t,e)}post(t,e,a){return this.request("POST",t,Object.assign({},a,{body:e}))}put(t,e,a){return this.request("PUT",t,Object.assign({},a,{body:e}))}patch(t,e,a){return this.request("PATCH",t,Object.assign({},a,{body:e}))}delete(t,e){return this.request("DELETE",t,e)}}class o{constructor(t){if(!t)throw new Error("HttpClient is required");this.http=t}_normalizePagination(t){const e=(t=t||{}).page||1,a=t.limit||20;return{page:e,limit:a,offset:void 0!==t.offset?t.offset:(e-1)*a}}_isValidObjectId(t){return!(!t||"string"!=typeof t)&&/^[a-fA-F0-9]{24}$/.test(t)}_validateRequired(t,e){const a=[];if(e.forEach(function(e){void 0!==t[e]&&null!==t[e]||a.push(e)}),a.length>0)throw new Error("Missing required parameters: "+a.join(", "))}_toISODate(t){return t?t instanceof Date?t.toISOString():"number"==typeof t||"string"==typeof t?new Date(t).toISOString():null:null}_cleanObject(t){if(!t||"object"!=typeof t)return t;const e={};return Object.keys(t).forEach(function(a){void 0!==t[a]&&(e[a]=t[a])}),e}}class l extends o{async get(t){return this._validateRequired({chatId:t},["chatId"]),await this.http.get("/api/conversations/"+t)}async getMessages(t,e){return this._validateRequired({chatId:t},["chatId"]),e=e||{},await this.http.get("/api/conversations/"+t+"/messages",{query:this._cleanObject({limit:e.limit,before:e.before})})}async getMessageHistory(t,e){this._validateRequired({chatId:t},["chatId"]),e=e||{};const a=this._normalizePagination(e);return await this.http.get("/api/conversations/"+t+"/v2-message-history",{query:{page:a.page,limit:a.limit}})}async list(t){t=t||{};const e=this._normalizePagination(t);return await this.http.get("/api/conversations/history",{query:this._cleanObject({status:t.status,channel:t.channel,userId:t.userId,visitorId:t.visitorId,startDate:this._toISODate(t.startDate),endDate:this._toISODate(t.endDate),page:e.page,limit:e.limit})})}async getStats(){return await this.http.get("/api/conversations/conversation-stat-realtime")}async addNote(t,e){return this._validateRequired({chatId:t,note:e},["chatId","note"]),await this.http.post("/api/conversations/"+t+"/note",{note:e})}async updateTags(t,e){return this._validateRequired({chatId:t},["chatId"]),await this.http.post("/api/conversations/"+t+"/tags",{tags:e||[]})}async rate(t,e,a){return this._validateRequired({chatId:t,rating:e},["chatId","rating"]),await this.http.post("/api/conversations/"+t+"/rate",{point:e,description:a})}async sendTranscript(t,e){return this._validateRequired({chatId:t,email:e},["chatId","email"]),await this.http.get("/api/conversations/"+t+"/sendTranscript",{query:{email:e}})}async destroy(t){return this._validateRequired({chatId:t},["chatId"]),await this.http.post("/api/conversations/"+t+"/destroy")}async getByUser(t,e){return this._validateRequired({userId:t},["userId"]),e=e||{},await this.http.get("/api/conversations/user/"+t,{query:this._cleanObject(e)})}async getWhatsAppContactList(t){return t=t||{},await this.http.get("/api/conversations/contact-list/whatsapp",{query:this._cleanObject(t)})}async getContactListByChannel(t,e){return this._validateRequired({channelId:t},["channelId"]),e=e||{},await this.http.get("/api/conversations/contact-list-by-channels",{query:this._cleanObject({channels:t,page:e.page,limit:e.limit})})}async getLastMessages(t){return this._validateRequired({chatIds:t},["chatIds"]),await this.http.post("/api/conversations/last-messages",{conversationIds:t})}async updateField(t,e,a){return this._validateRequired({chatId:t,key:e},["chatId","key"]),await this.http.put("/api/conversations/"+t+"/update-single-key",{key:e,value:a})}}class c extends o{async get(t){return this._validateRequired({contactId:t},["contactId"]),await this.http.get("/api/visitors/"+t)}async list(t){t=t||{};const e=this._normalizePagination(t);return await this.http.post("/api/visitors/visitor-list",{page:e.page,limit:e.limit,search:t.search,owner:t.owner,tags:t.tags,channel:t.channel})}async search(t,e){t=t||{},e=e||{};const a=this._normalizePagination(e);return await this.http.get("/api/visitors/search",{query:this._cleanObject({email:t.email,phone:t.phone,fullname:t.fullname,query:t.query,page:a.page,limit:a.limit})})}async advancedSearch(t,e,a){e=e||{};const i=this._normalizePagination(e);return await this.http.post("/api/visitors/contacts-by-advanced-filter",{filterGroups:t,cursor:{offset:i.offset,limit:i.limit},projectionFields:a})}async create(t){return this._validateRequired(t,["fullname"]),await this.http.post("/api/visitors/contacts",t)}async update(t,e){return this._validateRequired({contactId:t},["contactId"]),await this.http.post("/api/visitors/"+t+"/update",e)}async delete(t){return this._validateRequired({contactId:t},["contactId"]),await this.http.delete("/api/visitors/"+t)}async deleteMany(t){return this._validateRequired({contactIds:t},["contactIds"]),await this.http.post("/api/visitors/delete-multi-visitor",{visitorIds:t})}async addTag(t,e){return this._validateRequired({contactId:t,tagId:e},["contactId","tagId"]),await this.http.post("/api/visitors/updateTagVisitor/"+t,{tagId:e,action:"add"})}async removeTag(t,e){return this._validateRequired({contactId:t,tagId:e},["contactId","tagId"]),await this.http.post("/api/visitors/updateTagVisitor/"+t,{tagId:e,action:"remove"})}async block(t,e){return this._validateRequired({contactId:t},["contactId"]),await this.http.post("/api/visitors/"+t+"/block",{reason:e})}async unblock(t){return this._validateRequired({contactId:t},["contactId"]),await this.http.post("/api/visitors/"+t+"/unblock")}async getChatHistory(t,e){this._validateRequired({contactId:t},["contactId"]),e=e||{};const a=this._normalizePagination(e);return await this.http.get("/api/visitors/"+t+"/conversations-paged",{query:{page:a.page,limit:a.limit}})}async getNotes(t){return this._validateRequired({contactId:t},["contactId"]),await this.http.get("/api/visitors/"+t+"/notes-v2")}async addNote(t,e){return this._validateRequired({contactId:t,content:e},["contactId","content"]),await this.http.post("/api/visitors/"+t+"/notes-v2",{content:e})}async updateNote(t,e,a){return this._validateRequired({contactId:t,noteId:e,content:a},["contactId","noteId","content"]),await this.http.post("/api/visitors/"+t+"/notes-v2/"+e,{content:a})}async deleteNote(t){return this._validateRequired({noteId:t},["noteId"]),await this.http.delete("/api/visitors/notes-v2/"+t)}async updateProperty(t,e,a){return this._validateRequired({contactId:t,propertyId:e},["contactId","propertyId"]),await this.http.put("/api/visitors/"+t+"/contact-property/"+e,{value:a})}async changeOwner(t,e){return this._validateRequired({contactId:t,ownerId:e},["contactId","ownerId"]),await this.http.post("/api/visitors/"+t+"/update",{owner:e})}async updatePreferredAgents(t,e){return this._validateRequired({contactId:t},["contactId"]),await this.http.post("/api/visitors/"+t+"/update-preferred-agents",{agents:e||[]})}async getMedia(t,e){return this._validateRequired({contactId:t},["contactId"]),await this.http.get("/api/visitors/"+t+"/media",{query:this._cleanObject(e)})}async merge(t,e){return this._validateRequired({primaryContactId:t,secondaryContactId:e},["primaryContactId","secondaryContactId"]),await this.http.post("/api/visitors/merge-visitors",{primaryVisitorId:t,secondaryVisitorId:e})}async downloadExcel(t){return await this.http.post("/api/visitors/visitor-list/download",t||{})}}class h extends o{async get(t){return this._validateRequired({messageId:t},["messageId"]),await this.http.post("/api/messages/get-message",{messageId:t})}async list(t,e){return this._validateRequired({conversationId:t},["conversationId"]),e=e||{},await this.http.get("/api/messages/"+t,{query:this._cleanObject({limit:e.limit,before:e.before,after:e.after})})}async search(t){this._validateRequired(t,["query"]);const e=this._normalizePagination(t);return await this.http.post("/api/messages/search-messages",{query:t.query,conversationId:t.conversationId,visitorId:t.visitorId,userId:t.userId,startDate:this._toISODate(t.startDate),endDate:this._toISODate(t.endDate),page:e.page,limit:e.limit})}async getMany(t){return this._validateRequired({messageIds:t},["messageIds"]),await this.http.post("/api/messages/get-message",{messageIds:t})}}class p extends o{async get(t){return this._validateRequired({taskId:t},["taskId"]),await this.http.get("/api/tasks/"+t+"/detail")}async list(t,e){return this._validateRequired({workflowId:t},["workflowId"]),(e=e||{}).pipelineId?await this.http.get("/api/tasks/"+t+"/"+e.pipelineId):await this.http.get("/api/tasks/"+t)}async create(t){return this._validateRequired(t,["title","workflowId","pipelineId"]),await this.http.post("/api/tasks",{title:t.title,workflowId:t.workflowId,pipelineId:t.pipelineId,description:t.description,assignee:t.assignee,dueDate:this._toISODate(t.dueDate),priority:t.priority,contactId:t.contactId,customFields:t.customFields})}async createSimple(t){return this._validateRequired(t,["title","workflowId","pipelineId"]),await this.http.post("/api/tasks/simple",t)}async update(t,e){return this._validateRequired({taskId:t},["taskId"]),await this.http.patch("/api/tasks/"+t,e)}async delete(t){return this._validateRequired({taskId:t},["taskId"]),await this.http.delete("/api/tasks/"+t)}async move(t,e,a){return this._validateRequired({taskId:t,pipelineId:e},["taskId","pipelineId"]),await this.http.patch("/api/tasks/"+t+"/position",{pipelineId:e,position:a})}async complete(t){return this._validateRequired({taskId:t},["taskId"]),await this.http.patch("/api/tasks/"+t+"/done")}async archive(t){return this._validateRequired({taskId:t},["taskId"]),await this.http.patch("/api/tasks/"+t+"/archive")}async deleteMany(t){return this._validateRequired({taskIds:t},["taskIds"]),await this.http.post("/api/tasks/multiple/delete",{taskIds:t})}async moveMany(t,e){return this._validateRequired({taskIds:t,pipelineId:e},["taskIds","pipelineId"]),await this.http.post("/api/tasks/multiple/change-pipeline",{taskIds:t,pipelineId:e})}async completeMany(t){return this._validateRequired({taskIds:t},["taskIds"]),await this.http.post("/api/tasks/multiple/done",{taskIds:t})}async getActivities(t){return this._validateRequired({taskId:t},["taskId"]),await this.http.get("/api/tasks/get-task-activity/"+t)}async listCompleted(t){return await this.http.get("/api/tasks/done-tasks",{query:this._cleanObject(t)})}async listArchived(t){return await this.http.get("/api/tasks/archive-tasks",{query:this._cleanObject(t)})}async listByDate(t){return this._validateRequired({date:t},["date"]),await this.http.get("/api/tasks/get-event-list-by-date",{query:{date:this._toISODate(t)}})}async listByContact(t){return this._validateRequired({contactId:t},["contactId"]),await this.http.get("/api/tasks/visitor-tasks",{query:{visitorId:t}})}async listWorkflows(){return await this.http.get("/api/tasks/workflows")}async getWorkflow(t){return this._validateRequired({workflowId:t},["workflowId"]),await this.http.get("/api/tasks/workflows/"+t)}async createWorkflow(t){return this._validateRequired(t,["name"]),await this.http.post("/api/tasks/workflows",t)}async updateWorkflow(t,e){return this._validateRequired({workflowId:t},["workflowId"]),await this.http.patch("/api/tasks/workflows/"+t,e)}async deleteWorkflow(t){return this._validateRequired({workflowId:t},["workflowId"]),await this.http.delete("/api/tasks/workflows/"+t)}async getWorkflowFull(t){return this._validateRequired({workflowId:t},["workflowId"]),await this.http.get("/api/tasks/workflows/"+t+"/full")}async getWorkflowReports(t){return this._validateRequired({workflowId:t},["workflowId"]),await this.http.get("/api/tasks/workflows/"+t+"/reports")}async listPipelines(t){return this._validateRequired({workflowId:t},["workflowId"]),await this.http.get("/api/tasks/workflows/"+t+"/pipelines")}async createPipeline(t,e){return this._validateRequired({workflowId:t},["workflowId"]),this._validateRequired(e,["name"]),await this.http.post("/api/tasks/workflows/"+t+"/pipelines",e)}async updatePipeline(t,e){return this._validateRequired({pipelineId:t},["pipelineId"]),await this.http.patch("/api/tasks/pipelines/"+t,e)}async deletePipeline(t){return this._validateRequired({pipelineId:t},["pipelineId"]),await this.http.delete("/api/tasks/pipelines/"+t)}async updatePipelinePosition(t,e,a){return this._validateRequired({workflowId:t,pipelineId:e},["workflowId","pipelineId"]),await this.http.patch("/api/tasks/"+t+"/"+e+"/position",{position:a})}}class u extends o{async makeCall(t){return this._validateRequired(t,["agentId","toNumber","fromNumber"]),await this.http.post("/api/voice-agent/calls/phone",{overrideAgentId:t.agentId,toNumber:t.toNumber,fromNumber:t.fromNumber,retellLlmDynamicVariables:t.variables||{},metadata:t.metadata})}async makeWebCall(t){return this._validateRequired(t,["agentId"]),await this.http.post("/api/voice-agent/calls/web",{agentId:t.agentId,retellLlmDynamicVariables:t.variables||{}})}async makeBatchCall(t){return this._validateRequired(t,["agentId","fromNumber","calls"]),await this.http.post("/api/voice-agent/calls/batch",t)}async getCall(t){return this._validateRequired({callId:t},["callId"]),await this.http.get("/api/voice-agent/calls/"+t)}async listCalls(t){t=t||{};const e=this._normalizePagination(t);return await this.http.post("/api/voice-agent/calls/list",{agentId:t.agentId,status:t.status,startDate:this._toISODate(t.startDate),endDate:this._toISODate(t.endDate),page:e.page,limit:e.limit})}async listBatchCalls(){return await this.http.get("/api/voice-agent/calls/batch")}async listAgents(){return await this.http.get("/api/voice-agent/agents")}async getAgent(t){return this._validateRequired({agentId:t},["agentId"]),await this.http.get("/api/voice-agent/agents/"+t)}async createAgent(t){return this._validateRequired(t,["name"]),await this.http.post("/api/voice-agent/agents",t)}async updateAgent(t,e){return this._validateRequired({agentId:t},["agentId"]),await this.http.patch("/api/voice-agent/agents/"+t,e)}async deleteAgent(t){return this._validateRequired({agentId:t},["agentId"]),await this.http.delete("/api/voice-agent/agents/"+t)}async listNumbers(){return await this.http.get("/api/voice-agent/numbers")}async getNumber(t){return this._validateRequired({phoneNumber:t},["phoneNumber"]),await this.http.get("/api/voice-agent/numbers/"+encodeURIComponent(t))}async listVoices(){return await this.http.get("/api/voice-agent/voices")}async getVoice(t){return this._validateRequired({voiceId:t},["voiceId"]),await this.http.get("/api/voice-agent/voices/"+t)}async listKnowledgeBases(){return await this.http.get("/api/voice-agent/knowledgebases")}async getKnowledgeBase(t){return this._validateRequired({knowledgeBaseId:t},["knowledgeBaseId"]),await this.http.get("/api/voice-agent/knowledgebases/"+t)}async deleteKnowledgeBase(t){return this._validateRequired({knowledgeBaseId:t},["knowledgeBaseId"]),await this.http.delete("/api/voice-agent/knowledgebases/"+t)}async listLLMs(){return await this.http.get("/api/voice-agent/llms")}async getLLM(t){return this._validateRequired({llmId:t},["llmId"]),await this.http.get("/api/voice-agent/llms/"+t)}async createLLM(t){return await this.http.post("/api/voice-agent/llms",t)}async updateLLM(t,e){return this._validateRequired({llmId:t},["llmId"]),await this.http.patch("/api/voice-agent/llms/"+t,e)}async deleteLLM(t){return this._validateRequired({llmId:t},["llmId"]),await this.http.delete("/api/voice-agent/llms/"+t)}}class g extends o{async get(t){return this._validateRequired({assetId:t},["assetId"]),await this.http.get("/api/assets/id/"+t)}getUrl(t){return t?"https://supsis-storage.s3.amazonaws.com/"+t:null}}class w extends o{async list(){return await this.http.get("/api/tables")}async get(t){return this._validateRequired({tableId:t},["tableId"]),await this.http.get("/api/tables/"+t)}async create(t){return this._validateRequired(t,["name"]),await this.http.put("/api/tables",t)}async update(t,e){return this._validateRequired({tableId:t},["tableId"]),await this.http.post("/api/tables/"+t,e)}async delete(t){return this._validateRequired({tableId:t},["tableId"]),await this.http.delete("/api/tables/"+t)}async duplicate(t){return this._validateRequired({tableId:t},["tableId"]),await this.http.post("/api/tables/"+t+"/duplicate")}async export(t){return this._validateRequired({tableId:t},["tableId"]),await this.http.get("/api/tables/"+t+"/export")}async import(t){return await this.http.post("/api/tables/import",t)}async listFields(t){return this._validateRequired({tableId:t},["tableId"]),await this.http.get("/api/tables/"+t+"/fields")}async createField(t,e){return this._validateRequired({tableId:t},["tableId"]),this._validateRequired(e,["name","type"]),await this.http.put("/api/tables/"+t+"/fields",e)}async updateField(t,e,a){return this._validateRequired({tableId:t,fieldId:e},["tableId","fieldId"]),await this.http.post("/api/tables/"+t+"/fields/"+e,a)}async deleteField(t,e){return this._validateRequired({tableId:t,fieldId:e},["tableId","fieldId"]),await this.http.delete("/api/tables/"+t+"/fields/"+e)}async listRecords(t,e){this._validateRequired({tableId:t},["tableId"]),e=e||{};const a=this._normalizePagination(e);return await this.http.post("/api/tables/"+t+"/records",{filters:e.filters,sort:e.sort,page:a.page,limit:a.limit,viewId:e.viewId})}async getRecord(t,e){return this._validateRequired({tableId:t,recordId:e},["tableId","recordId"]),await this.http.get("/api/tables/"+t+"/records/"+e)}async createRecord(t,e){return this._validateRequired({tableId:t},["tableId"]),await this.http.put("/api/tables/"+t+"/records",e)}async createEmptyRecord(t){return this._validateRequired({tableId:t},["tableId"]),await this.http.put("/api/tables/"+t+"/records/empty")}async createManyRecords(t,e){return this._validateRequired({tableId:t,records:e},["tableId","records"]),await this.http.put("/api/tables/"+t+"/records/multi",{records:e})}async updateRecord(t,e,a){return this._validateRequired({tableId:t,recordId:e},["tableId","recordId"]),await this.http.post("/api/tables/"+t+"/records/"+e+"/update",a)}async updateManyRecords(t,e,a,i){return this._validateRequired({tableId:t,fieldId:e,recordIds:a},["tableId","fieldId","recordIds"]),await this.http.put("/api/tables/"+t+"/fields/"+e+"/records",{recordIds:a,value:i})}async deleteRecord(t,e){return this._validateRequired({tableId:t,recordId:e},["tableId","recordId"]),await this.http.delete("/api/tables/"+t+"/records/"+e)}async deleteManyRecords(t,e){return this._validateRequired({tableId:t,recordIds:e},["tableId","recordIds"]),await this.http.post("/api/tables/"+t+"/records/delete",{recordIds:e})}async duplicateRecords(t,e){return this._validateRequired({tableId:t,recordIds:e},["tableId","recordIds"]),await this.http.post("/api/tables/"+t+"/records/duplicate",{recordIds:e})}async searchFieldValues(t,e,a){return this._validateRequired({tableId:t,fieldId:e},["tableId","fieldId"]),await this.http.get("/api/tables/"+t+"/"+e+"/search",{query:{q:a}})}async listViews(t){return this._validateRequired({tableId:t},["tableId"]),await this.http.get("/api/tables/"+t+"/views")}async createView(t,e){return this._validateRequired({tableId:t},["tableId"]),this._validateRequired(e,["name"]),await this.http.put("/api/tables/"+t+"/views",e)}async updateView(t,e,a){return this._validateRequired({tableId:t,viewId:e},["tableId","viewId"]),await this.http.post("/api/tables/"+t+"/views/"+e,a)}async deleteView(t,e){return this._validateRequired({tableId:t,viewId:e},["tableId","viewId"]),await this.http.delete("/api/tables/"+t+"/views/"+e)}async listPages(t){return this._validateRequired({tableId:t},["tableId"]),await this.http.get("/api/tables/"+t+"/pages")}async getPage(t,e){return this._validateRequired({tableId:t,pageId:e},["tableId","pageId"]),await this.http.get("/api/tables/"+t+"/pages/"+e)}async createPage(t,e){return this._validateRequired({tableId:t},["tableId"]),await this.http.put("/api/tables/"+t+"/pages",e)}async listWidgets(t,e){return this._validateRequired({tableId:t,pageId:e},["tableId","pageId"]),await this.http.get("/api/tables/"+t+"/pages/"+e+"/widgets")}async getWidgetChartData(t,e,a){return this._validateRequired({tableId:t,widgetId:e},["tableId","widgetId"]),await this.http.post("/api/tables/"+t+"/widgets/"+e+"/chart-data",a||{})}}class I extends o{async list(){return await this.http.get("/api/module")}async create(t){return this._validateRequired(t,["name","displayName"]),await this.http.post("/api/module",t)}async update(t,e){return this._validateRequired({moduleName:t},["moduleName"]),await this.http.post("/api/module/"+t,e)}async delete(t){return this._validateRequired({moduleId:t},["moduleId"]),await this.http.delete("/api/module/"+t)}async listRecords(t,e){this._validateRequired({moduleName:t},["moduleName"]),e=e||{};const a=this._normalizePagination(e);return await this.http.post("/api/module/"+t+"/records",{filters:e.filters,sort:e.sort,page:a.page,limit:a.limit})}async listAllRecords(t){return this._validateRequired({moduleName:t},["moduleName"]),await this.http.get("/api/module/"+t+"/records")}async searchRecords(t,e){return this._validateRequired({moduleName:t,query:e},["moduleName","query"]),await this.http.get("/api/module/"+t+"/records/search",{query:{q:e}})}async getRecord(t,e){return this._validateRequired({moduleName:t,recordId:e},["moduleName","recordId"]),await this.http.get("/api/module/"+t+"/records/"+e)}async createRecord(t,e){return this._validateRequired({moduleName:t},["moduleName"]),await this.http.put("/api/module/"+t+"/records",e)}async createManyRecords(t,e){return this._validateRequired({moduleName:t,records:e},["moduleName","records"]),await this.http.put("/api/module/"+t+"/records/multi",{records:e})}async updateRecord(t,e,a){return this._validateRequired({moduleName:t,recordId:e},["moduleName","recordId"]),await this.http.put("/api/module/"+t+"/records/"+e,a)}async deleteRecord(t,e){return this._validateRequired({moduleName:t,recordId:e},["moduleName","recordId"]),await this.http.delete("/api/module/"+t+"/records/"+e)}async listContactRelatedRecords(t){return this._validateRequired({contactId:t},["contactId"]),await this.http.get("/api/module/records/contact-related-list",{query:{contactId:t}})}async listModuleRelatedRecords(t,e){return this._validateRequired({moduleName:t,recordId:e},["moduleName","recordId"]),await this.http.get("/api/module/records/module-related-list",{query:{moduleName:t,recordId:e}})}}class y extends o{async me(){return await this.http.get("/api/users/me")}async updateMe(t){return await this.http.put("/api/users/me",t)}async get(t){return this._validateRequired({userId:t},["userId"]),await this.http.get("/api/users/user/"+t)}async list(t){t=t||{};const e=this._normalizePagination(t);return await this.http.get("/api/users/pagination",{query:this._cleanObject({page:e.page,limit:e.limit,status:t.status})})}async listOnline(){return await this.http.get("/api/users/list-online-users")}async create(t){return this._validateRequired(t,["fullname","email","password"]),await this.http.post("/api/users",t)}async update(t,e){return this._validateRequired({userId:t},["userId"]),await this.http.put("/api/users/"+t,e)}async delete(t){return this._validateRequired({userId:t},["userId"]),await this.http.delete("/api/users/"+t)}async updatePassword(t,e){return this._validateRequired({userId:t,newPassword:e},["userId","newPassword"]),await this.http.put("/api/users/"+t+"/updatePassword",{password:e})}async updateOnlineStatus(t,e){return this._validateRequired({userId:t},["userId"]),await this.http.put("/api/users/"+t+"/onlineStatus",{isOnline:e})}async updateStatus(t,e){return this._validateRequired({userId:t,status:e},["userId","status"]),await this.http.put("/api/users/"+t+"/status",{status:e})}async getActiveCount(){return await this.http.get("/api/users/active-user-count")}async getNotificationSettings(){return await this.http.get("/api/users/me/notification-settings")}async completeTutorial(t){return this._validateRequired({tutorialKey:t},["tutorialKey"]),await this.http.post("/api/users/me/setup-guide/"+t)}async logout(){return await this.http.get("/api/users/logout")}}class v extends o{async list(t){const e=t?"/api/tags/"+t:"/api/tags";return await this.http.get(e)}async create(t){return this._validateRequired(t,["name"]),await this.http.post("/api/tags",t)}async update(t){return this._validateRequired(t,["_id"]),await this.http.patch("/api/tags",t)}async delete(t){return this._validateRequired({tagId:t},["tagId"]),await this.http.delete("/api/tags/"+t)}}class _ extends o{async getCurrentPlan(){return await this.http.get("/api/sites/current-plan")}async getFeatures(){return await this.http.get("/api/sites/features")}async getWallet(){return await this.http.get("/api/sites/wallet")}async getWalletActivities(t){return t=t||{},await this.http.get("/api/sites/wallet/activities",{query:this._cleanObject({walletType:t.walletType,startDate:this._toISODate(t.startDate),endDate:this._toISODate(t.endDate)})})}async depositWallet(t,e){return this._validateRequired({walletType:t,amount:e},["walletType","amount"]),await this.http.post("/api/sites/wallet/"+t,{amount:e})}async getAutoRebalanceSettings(t){return this._validateRequired({walletType:t},["walletType"]),await this.http.get("/api/sites/wallet/"+t+"/auto-rebalance")}async updateAutoRebalanceSettings(t,e){return this._validateRequired({walletType:t},["walletType"]),await this.http.put("/api/sites/wallet/"+t+"/auto-rebalance",e)}async getConversationUsage(){return await this.http.get("/api/sites/conversation-usages")}async getStorageUsage(t){return await this.http.post("/api/sites/storage-usages",t||{})}async checkIntegrationStatus(t){return await this.http.post("/api/public/sites/check-integration-status",t||{})}}class m extends o{async list(t){t=t||{};const e=this._normalizePagination(t);return await this.http.post("/api/cache/list",{pattern:t.pattern,type:t.type,actorType:t.actorType,page:e.page,limit:e.limit})}async write(t,e,a){this._validateRequired({key:t},["key"]);const i={key:t,value:e,type:(a=a||{}).type||"public",dataType:a.dataType||"mixed"};if(a.expiresIn){const t=new Date,e={seconds:1e3,minutes:6e4,hours:36e5,days:864e5,weeks:6048e5,months:2592e6},s=a.expiresIn.value*(e[a.expiresIn.unit]||e.hours);i.expiresAt=new Date(t.getTime()+s).toISOString()}else a.expiresAt&&(i.expiresAt=this._toISODate(a.expiresAt));return await this.http.post("/api/cache/write",i)}async read(t,e){this._validateRequired({key:t},["key"]);try{const a=await this.http.post("/api/cache/list",{pattern:t,limit:1});return a&&a.data&&a.data.length>0?a.data[0].value:void 0!==e?e:null}catch(t){return void 0!==e?e:null}}async update(t,e){return this._validateRequired({cacheId:t},["cacheId"]),await this.http.post("/api/cache/"+t+"/update",{value:e})}async extend(t,e){this._validateRequired({cacheId:t,expiresIn:e},["cacheId","expiresIn"]);const a={seconds:1e3,minutes:6e4,hours:36e5,days:864e5,weeks:6048e5,months:2592e6},i=new Date,s=e.value*(a[e.unit]||a.hours),r=new Date(i.getTime()+s);return await this.http.post("/api/cache/"+t+"/extend",{expiresAt:r.toISOString()})}async makeNeverExpire(t){return this._validateRequired({cacheId:t},["cacheId"]),await this.http.post("/api/cache/"+t+"/never-expire")}async delete(t){return this._validateRequired({cacheId:t},["cacheId"]),await this.http.delete("/api/cache/"+t)}async deleteMany(t){return this._validateRequired({cacheIds:t},["cacheIds"]),await this.http.post("/api/cache/bulk-delete",{cacheIds:t})}async deleteByActor(t,e){return this._validateRequired({actorType:t,actorId:e},["actorType","actorId"]),await this.http.post("/api/cache/delete-by-actor",{actorType:t,actorId:e})}async deleteByPattern(t){return this._validateRequired({pattern:t},["pattern"]),await this.http.post("/api/cache/delete-by-pattern",{pattern:t})}}class b{constructor(t){if(!t)throw new Error("Config is required");this._validateConfig(t),this._config=t,this._verbose=t.verbose||!1,this._http=new d({env:t.env||"production",baseApiAddress:t.baseApiAddress,siteId:t.siteId,timeout:t.timeout,retryCount:t.retryCount,verbose:t.verbose}),this._connected=!1,this._token=null,this._user=null,this._initModules(),this._log("info","SupsisJS initialized",{env:t.env||"production",baseApiAddress:t.baseApiAddress||"default",siteId:t.siteId})}_log(t){if(this._verbose){var e=Array.prototype.slice.call(arguments,1),a="[SupsisJS]",i=(new Date).toISOString();switch(t){case"info":console.log.apply(console,[a,i,"INFO:"].concat(e));break;case"warn":console.warn.apply(console,[a,i,"WARN:"].concat(e));break;case"error":console.error.apply(console,[a,i,"ERROR:"].concat(e));break;default:console.log.apply(console,[a,i].concat(e))}}}_validateConfig(t){if(!t.email)throw new Error("email is required");if(!t.password)throw new Error("password is required");if(!t.siteId)throw new Error("siteId is required")}_initModules(){this.chat=new l(this._http),this.contact=new c(this._http),this.message=new h(this._http),this.task=new p(this._http),this.aicall=new u(this._http),this.asset=new g(this._http),this.table=new w(this._http),this.module=new I(this._http),this.user=new y(this._http),this.tag=new v(this._http),this.site=new _(this._http),this.cache=new m(this._http)}async connect(){var t;if(this._connected)return this._log("info","Already connected"),this._user;this._log("info","Connecting to Supsis API..."),this._log("info","Base URL:",this._http.baseUrl);try{t=await this._http.post("/api/users/login",{email:this._config.email,password:this._config.password},{skipAuth:!0,retryCount:0})}catch(t){throw this._log("error","Login failed:",t.message),t}if(!t||!t.token){var e="Login failed: No token received";throw t&&t.message&&(e="Login failed: "+t.message),this._log("error",e),new n(e,401,t)}return this._token=t.token,this._user=t.user||t,this._http.setToken(this._token),this._connected=!0,this._log("info","Connected successfully as:",this._user.fullname||this._user.email),this._user}async disconnect(){if(this._connected){try{await this._http.get("/api/users/logout")}catch(t){}this._token=null,this._user=null,this._http.setToken(null),this._connected=!1}}get isConnected(){return this._connected}get currentUser(){return this._user}get token(){return this._token}get version(){return r}get http(){return this._http}setToken(t){this._token=t,this._http.setToken(t),this._connected=!0}}
|
|
10
10
|
/**
|
|
11
11
|
* Supsis JS SDK
|
|
12
12
|
*
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
* // Node.js (ESM)
|
|
35
35
|
* import { SupsisJS, SupsisModuleAPI } from '@supsis/supsis-js';
|
|
36
36
|
*/
|
|
37
|
-
t.AICall=u,t.Asset=
|
|
37
|
+
t.AICall=u,t.Asset=g,t.BaseModule=o,t.Cache=m,t.Chat=l,t.Contact=c,t.DEFAULT_CONFIG=a,t.ENVIRONMENTS=e,t.HttpClient=d,t.Message=h,t.Module=I,t.SDK_VERSION=r,t.Site=_,t.SupsisAPIError=n,t.SupsisJS=b,t.SupsisModuleAPI=class{constructor(t){if(!t)throw new Error("Config is required");if(!t.accessToken)throw new Error("accessToken is required");if(!t.siteId)throw new Error("siteId is required");this._config=t,this._http=new d({env:t.env||"production",baseApiAddress:t.baseApiAddress,siteId:t.siteId,timeout:t.timeout,retryCount:t.retryCount}),this._http.setToken(t.accessToken),this._initModules()}_initModules(){this.table=new w(this._http),this.module=new I(this._http),this.cache=new m(this._http)}get version(){return r}get http(){return this._http}setAccessToken(t){this._http.setToken(t)}},t.Table=w,t.Tag=v,t.Task=p,t.User=y,t.default=b,Object.defineProperty(t,"__esModule",{value:!0})});
|
|
38
38
|
//# sourceMappingURL=supsis.min.js.map
|