@tellescope/sdk 1.248.0 → 1.249.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.
Files changed (80) hide show
  1. package/.env +3 -0
  2. package/lib/cjs/sdk.d.ts +1 -0
  3. package/lib/cjs/sdk.d.ts.map +1 -1
  4. package/lib/cjs/sdk.js +1 -0
  5. package/lib/cjs/sdk.js.map +1 -1
  6. package/lib/cjs/tests/api_tests/chats_analytics.test.d.ts +6 -0
  7. package/lib/cjs/tests/api_tests/chats_analytics.test.d.ts.map +1 -0
  8. package/lib/cjs/tests/api_tests/chats_analytics.test.js +256 -0
  9. package/lib/cjs/tests/api_tests/chats_analytics.test.js.map +1 -0
  10. package/lib/cjs/tests/api_tests/cross_org_api_key.test.d.ts +6 -0
  11. package/lib/cjs/tests/api_tests/cross_org_api_key.test.d.ts.map +1 -0
  12. package/lib/cjs/tests/api_tests/cross_org_api_key.test.js +748 -0
  13. package/lib/cjs/tests/api_tests/cross_org_api_key.test.js.map +1 -0
  14. package/lib/cjs/tests/api_tests/enduser_session_invalidation.test.d.ts.map +1 -1
  15. package/lib/cjs/tests/api_tests/enduser_session_invalidation.test.js +426 -2
  16. package/lib/cjs/tests/api_tests/enduser_session_invalidation.test.js.map +1 -1
  17. package/lib/cjs/tests/api_tests/eom_billing_codes.test.d.ts +6 -0
  18. package/lib/cjs/tests/api_tests/eom_billing_codes.test.d.ts.map +1 -0
  19. package/lib/cjs/tests/api_tests/eom_billing_codes.test.js +162 -0
  20. package/lib/cjs/tests/api_tests/eom_billing_codes.test.js.map +1 -0
  21. package/lib/cjs/tests/api_tests/eom_procedure_codes.test.d.ts +6 -0
  22. package/lib/cjs/tests/api_tests/eom_procedure_codes.test.d.ts.map +1 -0
  23. package/lib/cjs/tests/api_tests/eom_procedure_codes.test.js +339 -0
  24. package/lib/cjs/tests/api_tests/eom_procedure_codes.test.js.map +1 -0
  25. package/lib/cjs/tests/api_tests/managed_content_file_access.test.d.ts +13 -0
  26. package/lib/cjs/tests/api_tests/managed_content_file_access.test.d.ts.map +1 -0
  27. package/lib/cjs/tests/api_tests/managed_content_file_access.test.js +385 -0
  28. package/lib/cjs/tests/api_tests/managed_content_file_access.test.js.map +1 -0
  29. package/lib/cjs/tests/api_tests/organization_settings_duplicates.test.d.ts.map +1 -1
  30. package/lib/cjs/tests/api_tests/organization_settings_duplicates.test.js +25 -2
  31. package/lib/cjs/tests/api_tests/organization_settings_duplicates.test.js.map +1 -1
  32. package/lib/cjs/tests/tests.d.ts.map +1 -1
  33. package/lib/cjs/tests/tests.js +148 -132
  34. package/lib/cjs/tests/tests.js.map +1 -1
  35. package/lib/esm/sdk.d.ts +3 -2
  36. package/lib/esm/sdk.d.ts.map +1 -1
  37. package/lib/esm/sdk.js +1 -0
  38. package/lib/esm/sdk.js.map +1 -1
  39. package/lib/esm/session.d.ts +1 -0
  40. package/lib/esm/session.d.ts.map +1 -1
  41. package/lib/esm/tests/api_tests/chats_analytics.test.d.ts +6 -0
  42. package/lib/esm/tests/api_tests/chats_analytics.test.d.ts.map +1 -0
  43. package/lib/esm/tests/api_tests/chats_analytics.test.js +252 -0
  44. package/lib/esm/tests/api_tests/chats_analytics.test.js.map +1 -0
  45. package/lib/esm/tests/api_tests/cross_org_api_key.test.d.ts +6 -0
  46. package/lib/esm/tests/api_tests/cross_org_api_key.test.d.ts.map +1 -0
  47. package/lib/esm/tests/api_tests/cross_org_api_key.test.js +744 -0
  48. package/lib/esm/tests/api_tests/cross_org_api_key.test.js.map +1 -0
  49. package/lib/esm/tests/api_tests/enduser_session_invalidation.test.d.ts.map +1 -1
  50. package/lib/esm/tests/api_tests/enduser_session_invalidation.test.js +426 -2
  51. package/lib/esm/tests/api_tests/enduser_session_invalidation.test.js.map +1 -1
  52. package/lib/esm/tests/api_tests/eom_billing_codes.test.d.ts +6 -0
  53. package/lib/esm/tests/api_tests/eom_billing_codes.test.d.ts.map +1 -0
  54. package/lib/esm/tests/api_tests/eom_billing_codes.test.js +158 -0
  55. package/lib/esm/tests/api_tests/eom_billing_codes.test.js.map +1 -0
  56. package/lib/esm/tests/api_tests/eom_procedure_codes.test.d.ts +6 -0
  57. package/lib/esm/tests/api_tests/eom_procedure_codes.test.d.ts.map +1 -0
  58. package/lib/esm/tests/api_tests/eom_procedure_codes.test.js +335 -0
  59. package/lib/esm/tests/api_tests/eom_procedure_codes.test.js.map +1 -0
  60. package/lib/esm/tests/api_tests/managed_content_file_access.test.d.ts +13 -0
  61. package/lib/esm/tests/api_tests/managed_content_file_access.test.d.ts.map +1 -0
  62. package/lib/esm/tests/api_tests/managed_content_file_access.test.js +358 -0
  63. package/lib/esm/tests/api_tests/managed_content_file_access.test.js.map +1 -0
  64. package/lib/esm/tests/api_tests/organization_settings_duplicates.test.d.ts.map +1 -1
  65. package/lib/esm/tests/api_tests/organization_settings_duplicates.test.js +25 -2
  66. package/lib/esm/tests/api_tests/organization_settings_duplicates.test.js.map +1 -1
  67. package/lib/esm/tests/tests.d.ts.map +1 -1
  68. package/lib/esm/tests/tests.js +148 -132
  69. package/lib/esm/tests/tests.js.map +1 -1
  70. package/lib/tsconfig.tsbuildinfo +1 -1
  71. package/package.json +10 -10
  72. package/src/sdk.ts +4 -0
  73. package/src/tests/api_tests/chats_analytics.test.ts +182 -0
  74. package/src/tests/api_tests/cross_org_api_key.test.ts +665 -0
  75. package/src/tests/api_tests/enduser_session_invalidation.test.ts +223 -0
  76. package/src/tests/api_tests/eom_procedure_codes.test.ts +296 -0
  77. package/src/tests/api_tests/managed_content_file_access.test.ts +214 -0
  78. package/src/tests/api_tests/organization_settings_duplicates.test.ts +14 -0
  79. package/src/tests/tests.ts +10 -2
  80. package/test_generated.pdf +0 -0
@@ -0,0 +1,182 @@
1
+ require('source-map-support').install();
2
+
3
+ import { Session } from "../../sdk"
4
+ import {
5
+ async_test,
6
+ log_header,
7
+ wait,
8
+ } from "@tellescope/testing"
9
+ import { setup_tests } from "../setup"
10
+
11
+ const host = process.env.API_URL || 'http://localhost:8080' as const
12
+
13
+ const totalFromValues = (r: { values?: { value: number }[] }) =>
14
+ (r.values ?? []).reduce((sum, v) => sum + v.value, 0)
15
+
16
+ export const chats_analytics_tests = async ({ sdk, sdkNonAdmin } : { sdk: Session, sdkNonAdmin: Session }) => {
17
+ log_header("Chats Analytics Tests")
18
+
19
+ const testEnduser = await sdk.api.endusers.createOne({
20
+ fname: 'ChatsAnalytics',
21
+ lname: 'TestUser',
22
+ email: 'chats-analytics-test@example.com',
23
+ })
24
+
25
+ const chatRoom = await sdk.api.chat_rooms.createOne({
26
+ enduserIds: [testEnduser.id],
27
+ })
28
+
29
+ // Inbound chat (senderId === enduserId), tagged with 'tag-a'
30
+ const inboundChat = await sdk.api.chats.createOne({
31
+ roomId: chatRoom.id,
32
+ message: "Inbound message from enduser",
33
+ senderId: testEnduser.id,
34
+ enduserId: testEnduser.id,
35
+ tags: ['tag-a'],
36
+ })
37
+
38
+ // Outbound chat (senderId !== enduserId), tagged with 'tag-b'
39
+ const outboundChat = await sdk.api.chats.createOne({
40
+ roomId: chatRoom.id,
41
+ message: "Outbound message from provider",
42
+ senderId: sdk.userInfo.id,
43
+ enduserId: testEnduser.id,
44
+ tags: ['tag-b'],
45
+ })
46
+
47
+ // Inbound chat with both tags
48
+ const bothTagsChat = await sdk.api.chats.createOne({
49
+ roomId: chatRoom.id,
50
+ message: "Inbound message with both tags",
51
+ senderId: testEnduser.id,
52
+ enduserId: testEnduser.id,
53
+ tags: ['tag-a', 'tag-b'],
54
+ })
55
+
56
+ await wait(undefined, 1000)
57
+
58
+ const now = new Date()
59
+ const dayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate())
60
+ const dayEnd = new Date(dayStart.getTime() + 24 * 60 * 60 * 1000)
61
+
62
+ const baseQuery = {
63
+ resource: 'Chats' as const,
64
+ info: { method: 'Total' as const, parameters: undefined },
65
+ range: { interval: 'Daily' as const, key: 'Created At' as const },
66
+ }
67
+ const createdRange = { from: dayStart, to: dayEnd }
68
+
69
+ try {
70
+ // Test 1: Total count with no filter
71
+ await async_test(
72
+ "Chats analytics - total count (no filter)",
73
+ () => sdk.api.analytics_frames.get_result_for_query({
74
+ query: { ...baseQuery },
75
+ createdRange,
76
+ }),
77
+ { onResult: r => totalFromValues(r) === 3 }
78
+ )
79
+
80
+ // Test 2: Direction = Inbound (senderId === enduserId)
81
+ await async_test(
82
+ "Chats analytics - direction Inbound",
83
+ () => sdk.api.analytics_frames.get_result_for_query({
84
+ query: { ...baseQuery, filter: { direction: 'Inbound' } },
85
+ createdRange,
86
+ }),
87
+ { onResult: r => totalFromValues(r) === 2 }
88
+ )
89
+
90
+ // Test 3: Direction = Outbound (senderId !== enduserId)
91
+ await async_test(
92
+ "Chats analytics - direction Outbound",
93
+ () => sdk.api.analytics_frames.get_result_for_query({
94
+ query: { ...baseQuery, filter: { direction: 'Outbound' } },
95
+ createdRange,
96
+ }),
97
+ { onResult: r => totalFromValues(r) === 1 }
98
+ )
99
+
100
+ // Test 4: Chat Tags - One Of qualifier
101
+ await async_test(
102
+ "Chats analytics - Chat Tags One Of",
103
+ () => sdk.api.analytics_frames.get_result_for_query({
104
+ query: { ...baseQuery, filter: { 'Chat Tags': { qualifier: 'One Of', values: ['tag-a'] } } },
105
+ createdRange,
106
+ }),
107
+ { onResult: r => totalFromValues(r) === 2 }
108
+ )
109
+
110
+ // Test 5: Chat Tags - All Of qualifier
111
+ await async_test(
112
+ "Chats analytics - Chat Tags All Of",
113
+ () => sdk.api.analytics_frames.get_result_for_query({
114
+ query: { ...baseQuery, filter: { 'Chat Tags': { qualifier: 'All Of', values: ['tag-a', 'tag-b'] } } },
115
+ createdRange,
116
+ }),
117
+ { onResult: r => totalFromValues(r) === 1 }
118
+ )
119
+
120
+ // Test 6: Combined direction + tags filter
121
+ await async_test(
122
+ "Chats analytics - Inbound + Chat Tags",
123
+ () => sdk.api.analytics_frames.get_result_for_query({
124
+ query: {
125
+ ...baseQuery,
126
+ filter: {
127
+ direction: 'Inbound',
128
+ 'Chat Tags': { qualifier: 'One Of', values: ['tag-b'] },
129
+ },
130
+ },
131
+ createdRange,
132
+ }),
133
+ { onResult: r => totalFromValues(r) === 1 }
134
+ )
135
+
136
+ // Test 7: Chat Tags grouping
137
+ await async_test(
138
+ "Chats analytics - Chat Tags grouping",
139
+ () => sdk.api.analytics_frames.get_result_for_query({
140
+ query: { ...baseQuery, grouping: { 'Chat Tags': true, Enduser: '' } },
141
+ createdRange,
142
+ }),
143
+ { onResult: r => {
144
+ if (!r.values?.length) return false
145
+ // Grouping by tags returns entries keyed by the full tags array on each chat
146
+ // We expect entries for each unique tag combination, with total values summing to 3
147
+ const total = r.values.reduce((sum, v) => sum + v.value, 0)
148
+ const hasGroupKeys = r.values.some(v => v.key !== undefined)
149
+ return total === 3 && hasGroupKeys
150
+ }}
151
+ )
152
+
153
+ console.log("All chats analytics tests passed")
154
+ } finally {
155
+ await sdk.api.chats.deleteOne(inboundChat.id)
156
+ await sdk.api.chats.deleteOne(outboundChat.id)
157
+ await sdk.api.chats.deleteOne(bothTagsChat.id)
158
+ await sdk.api.chat_rooms.deleteOne(chatRoom.id)
159
+ await sdk.api.endusers.deleteOne(testEnduser.id)
160
+ }
161
+ }
162
+
163
+ if (require.main === module) {
164
+ console.log(`Using API URL: ${host}`)
165
+ const sdk = new Session({ host })
166
+ const sdkNonAdmin = new Session({ host })
167
+
168
+ const runTests = async () => {
169
+ await setup_tests(sdk, sdkNonAdmin)
170
+ await chats_analytics_tests({ sdk, sdkNonAdmin })
171
+ }
172
+
173
+ runTests()
174
+ .then(() => {
175
+ console.log("Chats analytics test suite completed successfully")
176
+ process.exit(0)
177
+ })
178
+ .catch((error) => {
179
+ console.error("Chats analytics test suite failed:", error)
180
+ process.exit(1)
181
+ })
182
+ }