merchi_sdk_js 0.8.0 → 0.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "merchi_sdk_js",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "type": "module",
5
5
  "main": "src/merchi.js",
6
6
  "module": "src/merchi.js",
@@ -0,0 +1,90 @@
1
+ import { generateUUID } from './uuid.js';
2
+ import {
3
+ addPropertyTo,
4
+ fromJson,
5
+ getOne,
6
+ getList,
7
+ fromJsonList,
8
+ } from './model.js';
9
+ import { Company } from './company.js';
10
+ import { Domain } from './domain.js';
11
+ import { User } from './user.js';
12
+ import { AgentConversation } from './agent_conversation.js';
13
+ import { SupportConversation } from './support_conversation.js';
14
+ import { Request } from './model.js';
15
+
16
+ export function AgentTokenUsage() {
17
+ this.resource = '/agent_token_usage';
18
+ this.json = 'agentTokenUsage';
19
+ this.temporaryId = generateUUID();
20
+
21
+ addPropertyTo(this, 'id');
22
+ addPropertyTo(this, 'createdAt');
23
+ addPropertyTo(this, 'companyId');
24
+ addPropertyTo(this, 'domainId');
25
+ addPropertyTo(this, 'userId');
26
+ addPropertyTo(this, 'company', Company);
27
+ addPropertyTo(this, 'domain', Domain);
28
+ addPropertyTo(this, 'user', User);
29
+ addPropertyTo(this, 'agentConversation', AgentConversation);
30
+ addPropertyTo(this, 'supportConversation', SupportConversation);
31
+ addPropertyTo(this, 'agentConversationId');
32
+ addPropertyTo(this, 'supportConversationId');
33
+ addPropertyTo(this, 'sourceType');
34
+ addPropertyTo(this, 'modelName');
35
+ addPropertyTo(this, 'promptTokens');
36
+ addPropertyTo(this, 'completionTokens');
37
+ addPropertyTo(this, 'totalTokens');
38
+
39
+ this.get = function (success, error, embed) {
40
+ var self = this;
41
+ function handleResponse(result) {
42
+ success(
43
+ fromJson(self, result[self.json], { makesDirty: false })
44
+ );
45
+ }
46
+ getOne({
47
+ resource: this.resource,
48
+ id: this.id(),
49
+ success: handleResponse,
50
+ error: error,
51
+ embed: embed,
52
+ });
53
+ };
54
+ }
55
+
56
+ export function AgentTokenUsages() {
57
+ this.resource = '/agent_token_usage';
58
+ this.json = 'agentTokenUsage';
59
+ this.single = AgentTokenUsage;
60
+
61
+ this.get = function (success, error, parameters) {
62
+ var self = this;
63
+ function handleResponse(result) {
64
+ success(fromJsonList(self, result, { makesDirty: false }));
65
+ }
66
+ getList(this.resource, handleResponse, error, parameters || {});
67
+ };
68
+
69
+ this.record = function (payload, success, error) {
70
+ var request = new Request();
71
+ request.resource('/agent_token_usage/').method('POST');
72
+ Object.keys(payload || {}).forEach(function(key) {
73
+ var value = payload[key];
74
+ if (value !== undefined && value !== null) {
75
+ request.data().add(key, value);
76
+ }
77
+ });
78
+ function handleResponse(status, data) {
79
+ if (status >= 200 && status < 300) {
80
+ if (success) {
81
+ success(data);
82
+ }
83
+ } else if (error) {
84
+ error(status, data);
85
+ }
86
+ }
87
+ request.responseHandler(handleResponse).errorHandler(handleResponse);
88
+ request.send();
89
+ };
90
+ }
package/src/company.js CHANGED
@@ -268,6 +268,54 @@ export function Company() {
268
268
  var logo = this.logo();
269
269
  return logo && logo.viewUrl() ? logo.viewUrl() : null;
270
270
  }
271
+
272
+ function sendAnalyticsRequest(resource, method, success, error, queryParams) {
273
+ var request = new Request();
274
+ request.resource(resource).method(method || 'GET');
275
+ if (queryParams) {
276
+ Object.keys(queryParams).forEach(function(key) {
277
+ var value = queryParams[key];
278
+ if (value !== undefined && value !== null && value !== '') {
279
+ request.query().add(key, value);
280
+ }
281
+ });
282
+ }
283
+ function handleResponse(status, data) {
284
+ if (status >= 200 && status < 300) {
285
+ if (success) {
286
+ success(data);
287
+ }
288
+ } else if (error) {
289
+ error(status, data);
290
+ }
291
+ }
292
+ request.responseHandler(handleResponse).errorHandler(handleResponse);
293
+ request.send();
294
+ }
295
+
296
+ this.getAnalytics = function (success, error) {
297
+ sendAnalyticsRequest(
298
+ '/companies/' + this.id() + '/analytics/',
299
+ 'GET',
300
+ success,
301
+ error
302
+ );
303
+ };
304
+
305
+ this.getAgentTokenAnalytics = function (queryParams, success, error) {
306
+ if (typeof queryParams === 'function') {
307
+ error = success;
308
+ success = queryParams;
309
+ queryParams = null;
310
+ }
311
+ sendAnalyticsRequest(
312
+ '/companies/' + this.id() + '/agent_token_analytics/',
313
+ 'GET',
314
+ success,
315
+ error,
316
+ queryParams
317
+ );
318
+ };
271
319
  }
272
320
 
273
321
  export function Companies() {
package/src/domain.js CHANGED
@@ -791,6 +791,32 @@ export function Domain() {
791
791
  args.error
792
792
  );
793
793
  };
794
+
795
+ this.getAnalytics = function (success, error) {
796
+ sendStorefrontRequest(
797
+ '/domains/' + this.id() + '/analytics/',
798
+ 'GET',
799
+ null,
800
+ success,
801
+ error
802
+ );
803
+ };
804
+
805
+ this.getAgentTokenAnalytics = function (queryParams, success, error) {
806
+ if (typeof queryParams === 'function') {
807
+ error = success;
808
+ success = queryParams;
809
+ queryParams = null;
810
+ }
811
+ sendStorefrontRequest(
812
+ '/domains/' + this.id() + '/agent_token_analytics/',
813
+ 'GET',
814
+ null,
815
+ success,
816
+ error,
817
+ queryParams
818
+ );
819
+ };
794
820
  }
795
821
 
796
822
  export function Domains() {
package/src/merchi.js CHANGED
@@ -85,6 +85,7 @@ import { Quotes, Quote } from './quote.js';
85
85
  import { Reminder, Reminders } from './reminder.js';
86
86
  import { InternalTag, InternalTags } from './internal_tag.js';
87
87
  import { AgentConversation, AgentConversations } from './agent_conversation.js';
88
+ import { AgentTokenUsage, AgentTokenUsages } from './agent_token_usage.js';
88
89
  import { AgentSkill, AgentSkills } from './agent_skill.js';
89
90
  import { AgentSkillVersion, AgentSkillVersions } from './agent_skill_version.js';
90
91
  import { AgentSkillApproval, AgentSkillApprovals } from './agent_skill_approval.js';
@@ -1123,6 +1124,8 @@ export function merchi(backendUri, websocketUri) {
1123
1124
  'notifications': new Notifications(),
1124
1125
  'AgentConversation': AgentConversation,
1125
1126
  'agentConversations': new AgentConversations(),
1127
+ 'AgentTokenUsage': AgentTokenUsage,
1128
+ 'agentTokenUsage': new AgentTokenUsages(),
1126
1129
  'AgentSkill': AgentSkill,
1127
1130
  'agentSkills': new AgentSkills(),
1128
1131
  'AgentSkillVersion': AgentSkillVersion,