@ikatec/digisac-api-sdk 1.4.0 → 2.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.
Files changed (77) hide show
  1. package/dist/_chunks/{chunk-DortyG5C.cjs → chunk-Dk0Otj32.cjs} +19 -0
  2. package/dist/_chunks/scopes-CppNX42t.mjs +29 -0
  3. package/dist/_chunks/scopes-CppNX42t.mjs.map +1 -0
  4. package/dist/apis/authHistory/AuthHistoryApi.cjs +1 -1
  5. package/dist/apis/campaigns/CampaignsApi.cjs +12 -0
  6. package/dist/apis/campaigns/CampaignsApi.cjs.map +1 -1
  7. package/dist/apis/campaigns/CampaignsApi.d.ts +2 -2
  8. package/dist/apis/campaigns/CampaignsApi.d.ts.map +1 -1
  9. package/dist/apis/campaigns/CampaignsApi.mjs +12 -0
  10. package/dist/apis/campaigns/CampaignsApi.mjs.map +1 -1
  11. package/dist/apis/campaigns/index.cjs +8 -1
  12. package/dist/apis/campaigns/index.d.ts +1 -0
  13. package/dist/apis/campaigns/index.d.ts.map +1 -1
  14. package/dist/apis/campaigns/index.mjs +2 -1
  15. package/dist/apis/campaigns/scopes/getManyViewScope.cjs +51 -0
  16. package/dist/apis/campaigns/scopes/getManyViewScope.cjs.map +1 -0
  17. package/dist/apis/campaigns/scopes/getManyViewScope.d.ts +21 -0
  18. package/dist/apis/campaigns/scopes/getManyViewScope.d.ts.map +1 -0
  19. package/dist/apis/campaigns/scopes/getManyViewScope.mjs +49 -0
  20. package/dist/apis/campaigns/scopes/getManyViewScope.mjs.map +1 -0
  21. package/dist/apis/campaigns/scopes/getOneViewScope.cjs +27 -0
  22. package/dist/apis/campaigns/scopes/getOneViewScope.cjs.map +1 -0
  23. package/dist/apis/campaigns/scopes/getOneViewScope.d.ts +5 -0
  24. package/dist/apis/campaigns/scopes/getOneViewScope.d.ts.map +1 -0
  25. package/dist/apis/campaigns/scopes/getOneViewScope.mjs +25 -0
  26. package/dist/apis/campaigns/scopes/getOneViewScope.mjs.map +1 -0
  27. package/dist/apis/campaigns/scopes/index.cjs +21 -0
  28. package/dist/apis/campaigns/scopes/index.cjs.map +1 -0
  29. package/dist/apis/campaigns/scopes/index.d.ts +3 -0
  30. package/dist/apis/campaigns/scopes/index.d.ts.map +1 -0
  31. package/dist/apis/campaigns/scopes/index.mjs +4 -0
  32. package/dist/apis/campaigns/types.d.ts +32 -16
  33. package/dist/apis/campaigns/types.d.ts.map +1 -1
  34. package/dist/apis/contacts/ContactsApi.cjs +1 -1
  35. package/dist/apis/files/types.d.ts +1 -0
  36. package/dist/apis/files/types.d.ts.map +1 -1
  37. package/dist/apis/index.cjs +8 -1
  38. package/dist/apis/index.mjs +2 -1
  39. package/dist/apis/messages/MessagesApi.cjs +1 -1
  40. package/dist/apis/messages/types.d.ts +2 -1
  41. package/dist/apis/messages/types.d.ts.map +1 -1
  42. package/dist/apis/serviceAccessManagement/ServiceAccessManagementApi.cjs +1 -1
  43. package/dist/apis/stickerUsers/StickerUsersApi.cjs +1 -1
  44. package/dist/apis/terms/TermsApi.cjs +1 -1
  45. package/dist/core/BaseCrudApi.cjs +9 -3
  46. package/dist/core/BaseCrudApi.cjs.map +1 -1
  47. package/dist/core/BaseCrudApi.d.ts +5 -5
  48. package/dist/core/BaseCrudApi.d.ts.map +1 -1
  49. package/dist/core/BaseCrudApi.mjs +8 -2
  50. package/dist/core/BaseCrudApi.mjs.map +1 -1
  51. package/dist/core/index.d.ts +1 -1
  52. package/dist/core/index.d.ts.map +1 -1
  53. package/dist/core/types.d.ts +3 -1
  54. package/dist/core/types.d.ts.map +1 -1
  55. package/package.json +1 -1
  56. package/src/apis/authHistory/AuthHistoryApi.test.ts +110 -0
  57. package/src/apis/campaigns/CampaignsApi.test.ts +344 -0
  58. package/src/apis/campaigns/CampaignsApi.ts +14 -2
  59. package/src/apis/campaigns/index.ts +1 -0
  60. package/src/apis/campaigns/scopes/getManyViewScope.ts +79 -0
  61. package/src/apis/campaigns/scopes/getOneViewScope.ts +21 -0
  62. package/src/apis/campaigns/scopes/index.ts +2 -0
  63. package/src/apis/campaigns/types.ts +28 -16
  64. package/src/apis/clientFeedback/ClientFeedbackApi.test.ts +76 -0
  65. package/src/apis/contacts/ContactsApi.test.ts +364 -0
  66. package/src/apis/files/types.ts +1 -0
  67. package/src/apis/me/MeApi.test.ts +372 -0
  68. package/src/apis/messages/MessagesApi.test.ts +460 -0
  69. package/src/apis/messages/types.ts +2 -1
  70. package/src/apis/serviceAccessManagement/ServiceAccessManagementApi.test.ts +89 -0
  71. package/src/apis/stickerUsers/StickerUsersApi.test.ts +84 -0
  72. package/src/apis/terms/TermsApi.test.ts +196 -0
  73. package/src/apis/transcripts/TranscriptsApi.test.ts +63 -0
  74. package/src/core/BaseCrudApi.test.ts +1 -1
  75. package/src/core/BaseCrudApi.ts +16 -5
  76. package/src/core/index.ts +1 -1
  77. package/src/core/types.ts +8 -1
@@ -0,0 +1,372 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest'
2
+ import { MeApi } from './MeApi'
3
+ import type { ApiClient } from '../../core/ApiClient'
4
+ import type { User } from '../users/types'
5
+ import type { Account } from '../accounts/types'
6
+ import type {
7
+ UpdateMePayload,
8
+ UpdateMeStatusPayload,
9
+ UpdateMeAccountPayload,
10
+ TakeoverPayload,
11
+ SetOtpSecretKeyPayload,
12
+ RegisterTokenPayload,
13
+ } from './types'
14
+
15
+ // ── Mock client factory ──────────────────────────────────────────────
16
+
17
+ function createMockClient(): ApiClient {
18
+ return {
19
+ setAccessToken: vi.fn().mockReturnThis(),
20
+ request: vi.fn(),
21
+ get: vi.fn(),
22
+ post: vi.fn(),
23
+ put: vi.fn(),
24
+ patch: vi.fn(),
25
+ delete: vi.fn(),
26
+ }
27
+ }
28
+
29
+ // ── Fixtures ─────────────────────────────────────────────────────────
30
+
31
+ const user: User = {
32
+ id: 'user-1',
33
+ name: 'Alice',
34
+ email: 'alice@example.com',
35
+ phoneNumber: null,
36
+ branch: null,
37
+ isSuperAdmin: false,
38
+ isClientUser: false,
39
+ active: true,
40
+ language: 'en',
41
+ isFirstLogin: false,
42
+ status: 'online',
43
+ clientsStatus: null,
44
+ offlineAt: null,
45
+ isActiveInternalChat: true,
46
+ passwordExpiresAt: null,
47
+ otpAuthActive: false,
48
+ preferences: {},
49
+ archivedAt: null,
50
+ accountId: 'acc-1',
51
+ timetableId: null,
52
+ createdAt: '2024-01-01T00:00:00Z',
53
+ updatedAt: '2024-01-01T00:00:00Z',
54
+ deletedAt: null,
55
+ }
56
+
57
+ const account: Account = {
58
+ id: 'acc-1',
59
+ name: 'Acme',
60
+ alias: 'acme',
61
+ isActive: true,
62
+ isCampaignActive: false,
63
+ createdAt: '2024-01-01T00:00:00Z',
64
+ updatedAt: '2024-01-01T00:00:00Z',
65
+ expiresAt: null,
66
+ deletedAt: null,
67
+ data: { managerNumber: '123' },
68
+ plan: {} as Account['plan'],
69
+ settings: {} as Account['settings'],
70
+ wizardProgress: '',
71
+ encryptionKey: '',
72
+ branch: '',
73
+ correlationId: '',
74
+ promptAiFinalize: null,
75
+ promptAiTransfer: null,
76
+ promptAiCsat: null,
77
+ creditsControl: {} as Account['creditsControl'],
78
+ defaultDepartmentId: '',
79
+ clusterId: null,
80
+ agnusSignatureKey: null,
81
+ twoFactorAuthMandatoryActive: false,
82
+ }
83
+
84
+ // ── Tests ────────────────────────────────────────────────────────────
85
+
86
+ describe('MeApi', () => {
87
+ let client: ReturnType<typeof createMockClient>
88
+ let api: MeApi
89
+
90
+ beforeEach(() => {
91
+ client = createMockClient()
92
+ api = new MeApi(client)
93
+ })
94
+
95
+ // ── getMe ────────────────────────────────────────────────────────
96
+
97
+ describe('getMe', () => {
98
+ it('calls client.get with /me', async () => {
99
+ vi.mocked(client.get).mockResolvedValue(user)
100
+ const result = await api.getMe()
101
+ expect(client.get).toHaveBeenCalledWith('/me', undefined)
102
+ expect(result).toEqual(user)
103
+ })
104
+
105
+ it('forwards custom headers', async () => {
106
+ vi.mocked(client.get).mockResolvedValue(user)
107
+ const headers = { 'X-Custom': 'h' }
108
+ await api.getMe(headers)
109
+ expect(client.get).toHaveBeenCalledWith('/me', headers)
110
+ })
111
+ })
112
+
113
+ // ── getAccount ───────────────────────────────────────────────────
114
+
115
+ describe('getAccount', () => {
116
+ it('calls client.get with /me/account', async () => {
117
+ vi.mocked(client.get).mockResolvedValue(account)
118
+ const result = await api.getAccount()
119
+ expect(client.get).toHaveBeenCalledWith('/me/account', undefined)
120
+ expect(result).toEqual(account)
121
+ })
122
+
123
+ it('forwards custom headers', async () => {
124
+ vi.mocked(client.get).mockResolvedValue(account)
125
+ const headers = { 'X-Custom': 'h' }
126
+ await api.getAccount(headers)
127
+ expect(client.get).toHaveBeenCalledWith('/me/account', headers)
128
+ })
129
+ })
130
+
131
+ // ── getAccountAmounts ────────────────────────────────────────────
132
+
133
+ describe('getAccountAmounts', () => {
134
+ it('calls client.get with /me/get-account-amounts', async () => {
135
+ vi.mocked(client.get).mockResolvedValue({ credits: 100 })
136
+ const result = await api.getAccountAmounts()
137
+ expect(client.get).toHaveBeenCalledWith('/me/get-account-amounts', undefined)
138
+ expect(result).toEqual({ credits: 100 })
139
+ })
140
+
141
+ it('forwards custom headers', async () => {
142
+ vi.mocked(client.get).mockResolvedValue({})
143
+ const headers = { 'X-Custom': 'h' }
144
+ await api.getAccountAmounts(headers)
145
+ expect(client.get).toHaveBeenCalledWith('/me/get-account-amounts', headers)
146
+ })
147
+ })
148
+
149
+ // ── getAgnusMyPlanUrl ────────────────────────────────────────────
150
+
151
+ describe('getAgnusMyPlanUrl', () => {
152
+ it('calls client.get with /me/account/agnus-my-plan-url', async () => {
153
+ vi.mocked(client.get).mockResolvedValue({ url: 'https://plan.example.com' })
154
+ const result = await api.getAgnusMyPlanUrl()
155
+ expect(client.get).toHaveBeenCalledWith('/me/account/agnus-my-plan-url', undefined)
156
+ expect(result).toEqual({ url: 'https://plan.example.com' })
157
+ })
158
+
159
+ it('forwards custom headers', async () => {
160
+ vi.mocked(client.get).mockResolvedValue({ url: '' })
161
+ const headers = { 'X-Custom': 'h' }
162
+ await api.getAgnusMyPlanUrl(headers)
163
+ expect(client.get).toHaveBeenCalledWith('/me/account/agnus-my-plan-url', headers)
164
+ })
165
+ })
166
+
167
+ // ── updateMe ─────────────────────────────────────────────────────
168
+
169
+ describe('updateMe', () => {
170
+ it('calls client.put with /me and body', async () => {
171
+ vi.mocked(client.put).mockResolvedValue(user)
172
+ const body: UpdateMePayload = { name: 'Alice Updated' }
173
+ const result = await api.updateMe(body)
174
+ expect(client.put).toHaveBeenCalledWith('/me', body, undefined)
175
+ expect(result).toEqual(user)
176
+ })
177
+
178
+ it('forwards custom headers', async () => {
179
+ vi.mocked(client.put).mockResolvedValue(user)
180
+ const headers = { 'X-Custom': 'h' }
181
+ await api.updateMe({ name: 'x' }, headers)
182
+ expect(client.put).toHaveBeenCalledWith('/me', { name: 'x' }, headers)
183
+ })
184
+ })
185
+
186
+ // ── updateAccount ────────────────────────────────────────────────
187
+
188
+ describe('updateAccount', () => {
189
+ it('calls client.put with /me/account and body', async () => {
190
+ vi.mocked(client.put).mockResolvedValue(account)
191
+ const body: UpdateMeAccountPayload = { name: 'New Name' }
192
+ const result = await api.updateAccount(body)
193
+ expect(client.put).toHaveBeenCalledWith('/me/account', body, undefined)
194
+ expect(result).toEqual(account)
195
+ })
196
+
197
+ it('forwards custom headers', async () => {
198
+ vi.mocked(client.put).mockResolvedValue(account)
199
+ const headers = { 'X-Custom': 'h' }
200
+ await api.updateAccount({ name: 'x' }, headers)
201
+ expect(client.put).toHaveBeenCalledWith('/me/account', { name: 'x' }, headers)
202
+ })
203
+ })
204
+
205
+ // ── updateStatus ─────────────────────────────────────────────────
206
+
207
+ describe('updateStatus', () => {
208
+ it('calls client.put with /me/status and body', async () => {
209
+ vi.mocked(client.put).mockResolvedValue(user)
210
+ const body: UpdateMeStatusPayload = { status: 'online' }
211
+ const result = await api.updateStatus(body)
212
+ expect(client.put).toHaveBeenCalledWith('/me/status', body, undefined)
213
+ expect(result).toEqual(user)
214
+ })
215
+
216
+ it('forwards custom headers', async () => {
217
+ vi.mocked(client.put).mockResolvedValue(user)
218
+ const headers = { 'X-Custom': 'h' }
219
+ await api.updateStatus({ status: 'offline' }, headers)
220
+ expect(client.put).toHaveBeenCalledWith('/me/status', { status: 'offline' }, headers)
221
+ })
222
+ })
223
+
224
+ // ── extendAccountGracePeriod ─────────────────────────────────────
225
+
226
+ describe('extendAccountGracePeriod', () => {
227
+ it('calls client.post with /me/account/extend-grace-period', async () => {
228
+ vi.mocked(client.post).mockResolvedValue(account)
229
+ const result = await api.extendAccountGracePeriod()
230
+ expect(client.post).toHaveBeenCalledWith(
231
+ '/me/account/extend-grace-period',
232
+ undefined,
233
+ undefined,
234
+ )
235
+ expect(result).toEqual(account)
236
+ })
237
+
238
+ it('forwards custom headers', async () => {
239
+ vi.mocked(client.post).mockResolvedValue(account)
240
+ const headers = { 'X-Custom': 'h' }
241
+ await api.extendAccountGracePeriod(headers)
242
+ expect(client.post).toHaveBeenCalledWith(
243
+ '/me/account/extend-grace-period',
244
+ undefined,
245
+ headers,
246
+ )
247
+ })
248
+ })
249
+
250
+ // ── registerToken ────────────────────────────────────────────────
251
+
252
+ describe('registerToken', () => {
253
+ it('calls client.post with /me/one-signal/register-token and body', async () => {
254
+ vi.mocked(client.post).mockResolvedValue(undefined)
255
+ const body: RegisterTokenPayload = { token: 'abc123', platform: 'web' }
256
+ await api.registerToken(body)
257
+ expect(client.post).toHaveBeenCalledWith('/me/one-signal/register-token', body, undefined)
258
+ })
259
+
260
+ it('forwards custom headers', async () => {
261
+ vi.mocked(client.post).mockResolvedValue(undefined)
262
+ const headers = { 'X-Custom': 'h' }
263
+ await api.registerToken({ token: 'x' }, headers)
264
+ expect(client.post).toHaveBeenCalledWith(
265
+ '/me/one-signal/register-token',
266
+ { token: 'x' },
267
+ headers,
268
+ )
269
+ })
270
+ })
271
+
272
+ // ── reportFirstLogin ─────────────────────────────────────────────
273
+
274
+ describe('reportFirstLogin', () => {
275
+ it('calls client.post with /me/report-login', async () => {
276
+ vi.mocked(client.post).mockResolvedValue(user)
277
+ const result = await api.reportFirstLogin()
278
+ expect(client.post).toHaveBeenCalledWith('/me/report-login', undefined, undefined)
279
+ expect(result).toEqual(user)
280
+ })
281
+
282
+ it('forwards custom headers', async () => {
283
+ vi.mocked(client.post).mockResolvedValue(user)
284
+ const headers = { 'X-Custom': 'h' }
285
+ await api.reportFirstLogin(headers)
286
+ expect(client.post).toHaveBeenCalledWith('/me/report-login', undefined, headers)
287
+ })
288
+ })
289
+
290
+ // ── takeover ─────────────────────────────────────────────────────
291
+
292
+ describe('takeover', () => {
293
+ it('calls client.post with /me/takeover without body', async () => {
294
+ vi.mocked(client.post).mockResolvedValue(undefined)
295
+ await api.takeover()
296
+ expect(client.post).toHaveBeenCalledWith('/me/takeover', undefined, undefined)
297
+ })
298
+
299
+ it('calls client.post with /me/takeover with body', async () => {
300
+ vi.mocked(client.post).mockResolvedValue(undefined)
301
+ const body: TakeoverPayload = { client: 'web' }
302
+ await api.takeover(body)
303
+ expect(client.post).toHaveBeenCalledWith('/me/takeover', body, undefined)
304
+ })
305
+
306
+ it('forwards custom headers', async () => {
307
+ vi.mocked(client.post).mockResolvedValue(undefined)
308
+ const headers = { 'X-Custom': 'h' }
309
+ await api.takeover(undefined, headers)
310
+ expect(client.post).toHaveBeenCalledWith('/me/takeover', undefined, headers)
311
+ })
312
+ })
313
+
314
+ // ── setOtpSecretKey ──────────────────────────────────────────────
315
+
316
+ describe('setOtpSecretKey', () => {
317
+ it('calls client.patch with /me/set-otp-secret-key and body', async () => {
318
+ vi.mocked(client.patch).mockResolvedValue(undefined)
319
+ const body: SetOtpSecretKeyPayload = { secretKey: 'ABCDEFGH12345678' }
320
+ await api.setOtpSecretKey(body)
321
+ expect(client.patch).toHaveBeenCalledWith('/me/set-otp-secret-key', body, undefined)
322
+ })
323
+
324
+ it('forwards custom headers', async () => {
325
+ vi.mocked(client.patch).mockResolvedValue(undefined)
326
+ const headers = { 'X-OTP': '123456' }
327
+ await api.setOtpSecretKey({ secretKey: 'KEY' }, headers)
328
+ expect(client.patch).toHaveBeenCalledWith(
329
+ '/me/set-otp-secret-key',
330
+ { secretKey: 'KEY' },
331
+ headers,
332
+ )
333
+ })
334
+ })
335
+
336
+ // ── activateOtpAuth ──────────────────────────────────────────────
337
+
338
+ describe('activateOtpAuth', () => {
339
+ it('calls client.post with /me/activate-otp-auth', async () => {
340
+ vi.mocked(client.post).mockResolvedValue(true)
341
+ const result = await api.activateOtpAuth()
342
+ expect(client.post).toHaveBeenCalledWith('/me/activate-otp-auth', undefined, undefined)
343
+ expect(result).toBe(true)
344
+ })
345
+
346
+ it('forwards custom headers', async () => {
347
+ vi.mocked(client.post).mockResolvedValue(true)
348
+ const headers = { 'x-digisac-otp': '123456' }
349
+ await api.activateOtpAuth(headers)
350
+ expect(client.post).toHaveBeenCalledWith('/me/activate-otp-auth', undefined, headers)
351
+ })
352
+ })
353
+
354
+ // ── Error propagation ────────────────────────────────────────────
355
+
356
+ describe('error propagation', () => {
357
+ it('propagates errors from getMe', async () => {
358
+ vi.mocked(client.get).mockRejectedValue(new Error('Unauthorized'))
359
+ await expect(api.getMe()).rejects.toThrow('Unauthorized')
360
+ })
361
+
362
+ it('propagates errors from updateMe', async () => {
363
+ vi.mocked(client.put).mockRejectedValue(new Error('Validation failed'))
364
+ await expect(api.updateMe({ name: 'x' })).rejects.toThrow('Validation failed')
365
+ })
366
+
367
+ it('propagates errors from activateOtpAuth', async () => {
368
+ vi.mocked(client.post).mockRejectedValue(new Error('Invalid OTP'))
369
+ await expect(api.activateOtpAuth()).rejects.toThrow('Invalid OTP')
370
+ })
371
+ })
372
+ })