@elevasis/core 0.13.0 → 0.15.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 (42) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +9 -2
  3. package/dist/organization-model/index.d.ts +1 -1
  4. package/dist/organization-model/index.js +9 -2
  5. package/dist/test-utils/index.d.ts +463 -377
  6. package/dist/test-utils/index.js +9 -2
  7. package/package.json +1 -1
  8. package/src/_gen/__tests__/__snapshots__/contracts.md.snap +2336 -0
  9. package/src/business/acquisition/activity-events.test.ts +250 -0
  10. package/src/business/acquisition/activity-events.ts +7 -65
  11. package/src/business/acquisition/api-schemas.test.ts +1180 -0
  12. package/src/business/acquisition/api-schemas.ts +317 -73
  13. package/src/business/acquisition/crm-state-actions.test.ts +160 -0
  14. package/src/business/acquisition/derive-actions.test.ts +518 -0
  15. package/src/business/acquisition/derive-actions.ts +101 -78
  16. package/src/business/acquisition/index.ts +51 -9
  17. package/src/business/acquisition/stateful.ts +30 -0
  18. package/src/business/acquisition/types.ts +48 -80
  19. package/src/execution/engine/index.ts +437 -434
  20. package/src/execution/engine/tools/integration/server/adapters/attio/__tests__/attio-crud.integration.test.ts +363 -360
  21. package/src/execution/engine/tools/integration/server/adapters/attio/fetch/get-record/index.test.ts +162 -186
  22. package/src/execution/engine/tools/integration/server/adapters/attio/fetch/list-records/index.test.ts +316 -338
  23. package/src/execution/engine/tools/integration/server/adapters/gmail/gmail-adapter.ts +204 -210
  24. package/src/execution/engine/tools/integration/server/adapters/resend/fetch/send-email/index.test.ts +88 -0
  25. package/src/execution/engine/tools/integration/server/adapters/resend/fetch/send-email/index.ts +141 -134
  26. package/src/execution/engine/tools/integration/server/adapters/resend/fetch/utils/types.ts +76 -75
  27. package/src/execution/engine/tools/integration/service.test.ts +34 -9
  28. package/src/execution/engine/tools/integration/service.ts +6 -3
  29. package/src/execution/engine/tools/lead-service-types.ts +934 -874
  30. package/src/execution/engine/tools/platform/acquisition/types.ts +266 -260
  31. package/src/execution/engine/tools/registry.ts +701 -699
  32. package/src/execution/engine/tools/tool-maps.ts +30 -2
  33. package/src/execution/engine/workflow/types.ts +11 -0
  34. package/src/organization-model/contracts.ts +4 -4
  35. package/src/organization-model/domains/navigation.ts +62 -62
  36. package/src/organization-model/domains/sales.test.ts +189 -0
  37. package/src/organization-model/domains/sales.ts +456 -94
  38. package/src/organization-model/published.ts +21 -21
  39. package/src/organization-model/resolve.ts +21 -8
  40. package/src/platform/constants/versions.ts +1 -1
  41. package/src/reference/_generated/contracts.md +2336 -0
  42. package/src/supabase/database.types.ts +2958 -2886
@@ -1,338 +1,316 @@
1
- /**
2
- * Tests for Attio listRecords fetch implementation
3
- */
4
-
5
- import { describe, it, expect, vi, beforeEach } from 'vitest'
6
- import { listRecords } from './index.js'
7
- import { ToolingError } from '../../../../../../types.js'
8
-
9
- // Mock fetch globally
10
- const mockFetch = vi.fn()
11
- global.fetch = mockFetch as typeof fetch
12
-
13
- describe('listRecords', () => {
14
- beforeEach(() => {
15
- vi.clearAllMocks()
16
- })
17
-
18
- it('should list records successfully with default pagination', async () => {
19
- const mockResponse = {
20
- data: [
21
- {
22
- id: {
23
- workspace_id: 'workspace-123',
24
- object_id: 'object-456',
25
- record_id: 'record-1'
26
- },
27
- created_at: '2024-01-01T12:00:00Z',
28
- web_url: 'https://app.attio.com/workspace/record-1',
29
- values: {
30
- name: [{ first_name: 'John', last_name: 'Doe' }]
31
- }
32
- },
33
- {
34
- id: {
35
- workspace_id: 'workspace-123',
36
- object_id: 'object-456',
37
- record_id: 'record-2'
38
- },
39
- created_at: '2024-01-02T12:00:00Z',
40
- web_url: 'https://app.attio.com/workspace/record-2',
41
- values: {
42
- name: [{ first_name: 'Jane', last_name: 'Smith' }]
43
- }
44
- }
45
- ]
46
- }
47
-
48
- mockFetch.mockResolvedValue({
49
- ok: true,
50
- json: async () => mockResponse
51
- })
52
-
53
- const result = await listRecords(
54
- { apiKey: 'test-key' },
55
- { object: 'people' }
56
- )
57
-
58
- expect(result.records).toHaveLength(2)
59
- expect(result.records[0].id).toBe('record-1')
60
- expect(result.records[1].id).toBe('record-2')
61
- expect(result.hasMore).toBe(false) // Only 2 records, default limit is 500
62
-
63
- expect(mockFetch).toHaveBeenCalledWith(
64
- 'https://api.attio.com/v2/objects/people/records/query',
65
- expect.objectContaining({
66
- method: 'POST',
67
- headers: {
68
- 'Authorization': 'Bearer test-key',
69
- 'Content-Type': 'application/json',
70
- 'Accept': 'application/json'
71
- },
72
- body: JSON.stringify({
73
- limit: 500,
74
- offset: 0
75
- })
76
- })
77
- )
78
- })
79
-
80
- it('should support custom limit and offset', async () => {
81
- const mockResponse = {
82
- data: Array.from({ length: 50 }, (_, i) => ({
83
- id: {
84
- workspace_id: 'workspace-123',
85
- object_id: 'object-456',
86
- record_id: `record-${i + 50}`
87
- },
88
- created_at: '2024-01-01T12:00:00Z',
89
- web_url: `https://app.attio.com/workspace/record-${i + 50}`,
90
- values: {}
91
- }))
92
- }
93
-
94
- mockFetch.mockResolvedValue({
95
- ok: true,
96
- json: async () => mockResponse
97
- })
98
-
99
- const result = await listRecords(
100
- { apiKey: 'test-key' },
101
- { object: 'people', limit: 50, offset: 50 }
102
- )
103
-
104
- expect(result.records).toHaveLength(50)
105
- expect(result.hasMore).toBe(true) // Returned count equals limit
106
-
107
- const fetchCall = mockFetch.mock.calls[0][1] as { body: string }
108
- const calledBody = JSON.parse(fetchCall.body)
109
- expect(calledBody.limit).toBe(50)
110
- expect(calledBody.offset).toBe(50)
111
- })
112
-
113
- it('should support filter parameters', async () => {
114
- const mockResponse = { data: [] }
115
-
116
- mockFetch.mockResolvedValue({
117
- ok: true,
118
- json: async () => mockResponse
119
- })
120
-
121
- await listRecords(
122
- { apiKey: 'test-key' },
123
- {
124
- object: 'people',
125
- filter: {
126
- name: {
127
- first_name: {
128
- $eq: 'John'
129
- }
130
- }
131
- }
132
- }
133
- )
134
-
135
- const fetchCall = mockFetch.mock.calls[0][1] as { body: string }
136
- const calledBody = JSON.parse(fetchCall.body)
137
- expect(calledBody.filter).toEqual({
138
- name: {
139
- first_name: {
140
- $eq: 'John'
141
- }
142
- }
143
- })
144
- })
145
-
146
- it('should support sorts parameters', async () => {
147
- const mockResponse = { data: [] }
148
-
149
- mockFetch.mockResolvedValue({
150
- ok: true,
151
- json: async () => mockResponse
152
- })
153
-
154
- await listRecords(
155
- { apiKey: 'test-key' },
156
- {
157
- object: 'people',
158
- sorts: [
159
- {
160
- attribute: 'name',
161
- field: 'last_name',
162
- direction: 'asc'
163
- }
164
- ]
165
- }
166
- )
167
-
168
- const fetchCall = mockFetch.mock.calls[0][1] as { body: string }
169
- const calledBody = JSON.parse(fetchCall.body)
170
- expect(calledBody.sorts).toEqual([
171
- {
172
- attribute: 'name',
173
- field: 'last_name',
174
- direction: 'asc'
175
- }
176
- ])
177
- })
178
-
179
- it('should support complex filters with logical operators', async () => {
180
- const mockResponse = { data: [] }
181
-
182
- mockFetch.mockResolvedValue({
183
- ok: true,
184
- json: async () => mockResponse
185
- })
186
-
187
- await listRecords(
188
- { apiKey: 'test-key' },
189
- {
190
- object: 'deals',
191
- filter: {
192
- $and: [
193
- {
194
- value: {
195
- value: {
196
- $gte: 10000
197
- }
198
- }
199
- },
200
- {
201
- status: {
202
- $eq: 'open'
203
- }
204
- }
205
- ]
206
- }
207
- }
208
- )
209
-
210
- const fetchCall = mockFetch.mock.calls[0][1] as { body: string }
211
- const calledBody = JSON.parse(fetchCall.body)
212
- expect(calledBody.filter.$and).toHaveLength(2)
213
- })
214
-
215
- it('should throw credentials_invalid when API key is missing', async () => {
216
- await expect(
217
- listRecords(
218
- { apiKey: '' },
219
- { object: 'people' }
220
- )
221
- ).rejects.toThrow('Missing Attio API key')
222
- })
223
-
224
- it('should throw validation_error when object is missing', async () => {
225
- await expect(
226
- listRecords(
227
- { apiKey: 'test-key' },
228
- { object: '' }
229
- )
230
- ).rejects.toThrow('Missing required parameter: object')
231
- })
232
-
233
- it('should handle 401 authentication errors', async () => {
234
- mockFetch.mockResolvedValue({
235
- ok: false,
236
- status: 401,
237
- statusText: 'Unauthorized',
238
- text: async () => JSON.stringify({
239
- status_code: 401,
240
- type: 'authentication_error',
241
- code: 'unauthorized',
242
- message: 'Invalid API key'
243
- })
244
- })
245
-
246
- try {
247
- await listRecords(
248
- { apiKey: 'invalid-key' },
249
- { object: 'people' }
250
- )
251
- } catch (error) {
252
- expect((error as ToolingError).errorType).toBe('credentials_invalid')
253
- }
254
- })
255
-
256
- it('should work with different object types', async () => {
257
- const mockResponse = {
258
- data: [
259
- {
260
- id: {
261
- workspace_id: 'workspace-123',
262
- object_id: 'object-456',
263
- record_id: 'company-1'
264
- },
265
- created_at: '2024-01-01T12:00:00Z',
266
- web_url: 'https://app.attio.com/workspace/company-1',
267
- values: {
268
- name: 'Acme Corp'
269
- }
270
- }
271
- ]
272
- }
273
-
274
- mockFetch.mockResolvedValue({
275
- ok: true,
276
- json: async () => mockResponse
277
- })
278
-
279
- const result = await listRecords(
280
- { apiKey: 'test-key' },
281
- { object: 'companies' }
282
- )
283
-
284
- expect(result.records).toHaveLength(1)
285
- expect(result.records[0].values.name).toBe('Acme Corp')
286
-
287
- expect(mockFetch).toHaveBeenCalledWith(
288
- 'https://api.attio.com/v2/objects/companies/records/query',
289
- expect.anything()
290
- )
291
- })
292
-
293
- it('should determine hasMore correctly based on limit', async () => {
294
- // Case 1: Returned count < limit -> hasMore = false
295
- const mockResponse1 = {
296
- data: Array.from({ length: 25 }, (_, i) => ({
297
- id: { workspace_id: 'w', object_id: 'o', record_id: `r-${i}` },
298
- created_at: '2024-01-01T12:00:00Z',
299
- web_url: `https://app.attio.com/w/r-${i}`,
300
- values: {}
301
- }))
302
- }
303
-
304
- mockFetch.mockResolvedValueOnce({
305
- ok: true,
306
- json: async () => mockResponse1
307
- })
308
-
309
- const result1 = await listRecords(
310
- { apiKey: 'test-key' },
311
- { object: 'people', limit: 50 }
312
- )
313
-
314
- expect(result1.hasMore).toBe(false)
315
-
316
- // Case 2: Returned count = limit -> hasMore = true
317
- const mockResponse2 = {
318
- data: Array.from({ length: 50 }, (_, i) => ({
319
- id: { workspace_id: 'w', object_id: 'o', record_id: `r-${i}` },
320
- created_at: '2024-01-01T12:00:00Z',
321
- web_url: `https://app.attio.com/w/r-${i}`,
322
- values: {}
323
- }))
324
- }
325
-
326
- mockFetch.mockResolvedValueOnce({
327
- ok: true,
328
- json: async () => mockResponse2
329
- })
330
-
331
- const result2 = await listRecords(
332
- { apiKey: 'test-key' },
333
- { object: 'people', limit: 50 }
334
- )
335
-
336
- expect(result2.hasMore).toBe(true)
337
- })
338
- })
1
+ /**
2
+ * Tests for Attio listRecords fetch implementation
3
+ */
4
+
5
+ import { describe as _describe, it, expect, vi, beforeEach } from 'vitest'
6
+
7
+ // Attio integration not in use; suite skipped per project decision (2026-04-29).
8
+ const describe = _describe.skip
9
+ import { listRecords } from './index.js'
10
+ import { ToolingError } from '../../../../../../types.js'
11
+
12
+ // Mock fetch globally
13
+ const mockFetch = vi.fn()
14
+ global.fetch = mockFetch as typeof fetch
15
+
16
+ describe('listRecords', () => {
17
+ beforeEach(() => {
18
+ vi.clearAllMocks()
19
+ })
20
+
21
+ it('should list records successfully with default pagination', async () => {
22
+ const mockResponse = {
23
+ data: [
24
+ {
25
+ id: {
26
+ workspace_id: 'workspace-123',
27
+ object_id: 'object-456',
28
+ record_id: 'record-1'
29
+ },
30
+ created_at: '2024-01-01T12:00:00Z',
31
+ web_url: 'https://app.attio.com/workspace/record-1',
32
+ values: {
33
+ name: [{ first_name: 'John', last_name: 'Doe' }]
34
+ }
35
+ },
36
+ {
37
+ id: {
38
+ workspace_id: 'workspace-123',
39
+ object_id: 'object-456',
40
+ record_id: 'record-2'
41
+ },
42
+ created_at: '2024-01-02T12:00:00Z',
43
+ web_url: 'https://app.attio.com/workspace/record-2',
44
+ values: {
45
+ name: [{ first_name: 'Jane', last_name: 'Smith' }]
46
+ }
47
+ }
48
+ ]
49
+ }
50
+
51
+ mockFetch.mockResolvedValue({
52
+ ok: true,
53
+ json: async () => mockResponse
54
+ })
55
+
56
+ const result = await listRecords({ apiKey: 'test-key' }, { object: 'people' })
57
+
58
+ expect(result.records).toHaveLength(2)
59
+ expect(result.records[0].id).toBe('record-1')
60
+ expect(result.records[1].id).toBe('record-2')
61
+ expect(result.hasMore).toBe(false) // Only 2 records, default limit is 500
62
+
63
+ expect(mockFetch).toHaveBeenCalledWith(
64
+ 'https://api.attio.com/v2/objects/people/records/query',
65
+ expect.objectContaining({
66
+ method: 'POST',
67
+ headers: {
68
+ Authorization: 'Bearer test-key',
69
+ 'Content-Type': 'application/json',
70
+ Accept: 'application/json'
71
+ },
72
+ body: JSON.stringify({
73
+ limit: 500,
74
+ offset: 0
75
+ })
76
+ })
77
+ )
78
+ })
79
+
80
+ it('should support custom limit and offset', async () => {
81
+ const mockResponse = {
82
+ data: Array.from({ length: 50 }, (_, i) => ({
83
+ id: {
84
+ workspace_id: 'workspace-123',
85
+ object_id: 'object-456',
86
+ record_id: `record-${i + 50}`
87
+ },
88
+ created_at: '2024-01-01T12:00:00Z',
89
+ web_url: `https://app.attio.com/workspace/record-${i + 50}`,
90
+ values: {}
91
+ }))
92
+ }
93
+
94
+ mockFetch.mockResolvedValue({
95
+ ok: true,
96
+ json: async () => mockResponse
97
+ })
98
+
99
+ const result = await listRecords({ apiKey: 'test-key' }, { object: 'people', limit: 50, offset: 50 })
100
+
101
+ expect(result.records).toHaveLength(50)
102
+ expect(result.hasMore).toBe(true) // Returned count equals limit
103
+
104
+ const fetchCall = mockFetch.mock.calls[0][1] as { body: string }
105
+ const calledBody = JSON.parse(fetchCall.body)
106
+ expect(calledBody.limit).toBe(50)
107
+ expect(calledBody.offset).toBe(50)
108
+ })
109
+
110
+ it('should support filter parameters', async () => {
111
+ const mockResponse = { data: [] }
112
+
113
+ mockFetch.mockResolvedValue({
114
+ ok: true,
115
+ json: async () => mockResponse
116
+ })
117
+
118
+ await listRecords(
119
+ { apiKey: 'test-key' },
120
+ {
121
+ object: 'people',
122
+ filter: {
123
+ name: {
124
+ first_name: {
125
+ $eq: 'John'
126
+ }
127
+ }
128
+ }
129
+ }
130
+ )
131
+
132
+ const fetchCall = mockFetch.mock.calls[0][1] as { body: string }
133
+ const calledBody = JSON.parse(fetchCall.body)
134
+ expect(calledBody.filter).toEqual({
135
+ name: {
136
+ first_name: {
137
+ $eq: 'John'
138
+ }
139
+ }
140
+ })
141
+ })
142
+
143
+ it('should support sorts parameters', async () => {
144
+ const mockResponse = { data: [] }
145
+
146
+ mockFetch.mockResolvedValue({
147
+ ok: true,
148
+ json: async () => mockResponse
149
+ })
150
+
151
+ await listRecords(
152
+ { apiKey: 'test-key' },
153
+ {
154
+ object: 'people',
155
+ sorts: [
156
+ {
157
+ attribute: 'name',
158
+ field: 'last_name',
159
+ direction: 'asc'
160
+ }
161
+ ]
162
+ }
163
+ )
164
+
165
+ const fetchCall = mockFetch.mock.calls[0][1] as { body: string }
166
+ const calledBody = JSON.parse(fetchCall.body)
167
+ expect(calledBody.sorts).toEqual([
168
+ {
169
+ attribute: 'name',
170
+ field: 'last_name',
171
+ direction: 'asc'
172
+ }
173
+ ])
174
+ })
175
+
176
+ it('should support complex filters with logical operators', async () => {
177
+ const mockResponse = { data: [] }
178
+
179
+ mockFetch.mockResolvedValue({
180
+ ok: true,
181
+ json: async () => mockResponse
182
+ })
183
+
184
+ await listRecords(
185
+ { apiKey: 'test-key' },
186
+ {
187
+ object: 'deals',
188
+ filter: {
189
+ $and: [
190
+ {
191
+ value: {
192
+ value: {
193
+ $gte: 10000
194
+ }
195
+ }
196
+ },
197
+ {
198
+ status: {
199
+ $eq: 'open'
200
+ }
201
+ }
202
+ ]
203
+ }
204
+ }
205
+ )
206
+
207
+ const fetchCall = mockFetch.mock.calls[0][1] as { body: string }
208
+ const calledBody = JSON.parse(fetchCall.body)
209
+ expect(calledBody.filter.$and).toHaveLength(2)
210
+ })
211
+
212
+ it('should throw credentials_invalid when API key is missing', async () => {
213
+ await expect(listRecords({ apiKey: '' }, { object: 'people' })).rejects.toThrow('Missing Attio API key')
214
+ })
215
+
216
+ it('should throw validation_error when object is missing', async () => {
217
+ await expect(listRecords({ apiKey: 'test-key' }, { object: '' })).rejects.toThrow(
218
+ 'Missing required parameter: object'
219
+ )
220
+ })
221
+
222
+ it('should handle 401 authentication errors', async () => {
223
+ mockFetch.mockResolvedValue({
224
+ ok: false,
225
+ status: 401,
226
+ statusText: 'Unauthorized',
227
+ text: async () =>
228
+ JSON.stringify({
229
+ status_code: 401,
230
+ type: 'authentication_error',
231
+ code: 'unauthorized',
232
+ message: 'Invalid API key'
233
+ })
234
+ })
235
+
236
+ try {
237
+ await listRecords({ apiKey: 'invalid-key' }, { object: 'people' })
238
+ } catch (error) {
239
+ expect((error as ToolingError).errorType).toBe('credentials_invalid')
240
+ }
241
+ })
242
+
243
+ it('should work with different object types', async () => {
244
+ const mockResponse = {
245
+ data: [
246
+ {
247
+ id: {
248
+ workspace_id: 'workspace-123',
249
+ object_id: 'object-456',
250
+ record_id: 'company-1'
251
+ },
252
+ created_at: '2024-01-01T12:00:00Z',
253
+ web_url: 'https://app.attio.com/workspace/company-1',
254
+ values: {
255
+ name: 'Acme Corp'
256
+ }
257
+ }
258
+ ]
259
+ }
260
+
261
+ mockFetch.mockResolvedValue({
262
+ ok: true,
263
+ json: async () => mockResponse
264
+ })
265
+
266
+ const result = await listRecords({ apiKey: 'test-key' }, { object: 'companies' })
267
+
268
+ expect(result.records).toHaveLength(1)
269
+ expect(result.records[0].values.name).toBe('Acme Corp')
270
+
271
+ expect(mockFetch).toHaveBeenCalledWith(
272
+ 'https://api.attio.com/v2/objects/companies/records/query',
273
+ expect.anything()
274
+ )
275
+ })
276
+
277
+ it('should determine hasMore correctly based on limit', async () => {
278
+ // Case 1: Returned count < limit -> hasMore = false
279
+ const mockResponse1 = {
280
+ data: Array.from({ length: 25 }, (_, i) => ({
281
+ id: { workspace_id: 'w', object_id: 'o', record_id: `r-${i}` },
282
+ created_at: '2024-01-01T12:00:00Z',
283
+ web_url: `https://app.attio.com/w/r-${i}`,
284
+ values: {}
285
+ }))
286
+ }
287
+
288
+ mockFetch.mockResolvedValueOnce({
289
+ ok: true,
290
+ json: async () => mockResponse1
291
+ })
292
+
293
+ const result1 = await listRecords({ apiKey: 'test-key' }, { object: 'people', limit: 50 })
294
+
295
+ expect(result1.hasMore).toBe(false)
296
+
297
+ // Case 2: Returned count = limit -> hasMore = true
298
+ const mockResponse2 = {
299
+ data: Array.from({ length: 50 }, (_, i) => ({
300
+ id: { workspace_id: 'w', object_id: 'o', record_id: `r-${i}` },
301
+ created_at: '2024-01-01T12:00:00Z',
302
+ web_url: `https://app.attio.com/w/r-${i}`,
303
+ values: {}
304
+ }))
305
+ }
306
+
307
+ mockFetch.mockResolvedValueOnce({
308
+ ok: true,
309
+ json: async () => mockResponse2
310
+ })
311
+
312
+ const result2 = await listRecords({ apiKey: 'test-key' }, { object: 'people', limit: 50 })
313
+
314
+ expect(result2.hasMore).toBe(true)
315
+ })
316
+ })