@forgehive/hive-sdk 0.1.6 → 0.3.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.
@@ -1,222 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const axios_1 = __importDefault(require("axios"));
7
- const index_1 = require("../index");
8
- // Mock axios
9
- jest.mock('axios');
10
- const mockedAxios = axios_1.default;
11
- describe('HiveLogClient sendLogByUuid', () => {
12
- const testConfig = {
13
- projectName: 'test-project',
14
- projectUuid: '550e8400-e29b-41d4-a716-446655440000',
15
- apiKey: 'test-key',
16
- apiSecret: 'test-secret',
17
- host: 'https://test.example.com'
18
- };
19
- beforeEach(() => {
20
- jest.clearAllMocks();
21
- });
22
- describe('UUID Generation', () => {
23
- it('should generate UUID v7 when execution record has no UUID', async () => {
24
- mockedAxios.post.mockResolvedValueOnce({ data: { success: true } });
25
- const client = new index_1.HiveLogClient(testConfig);
26
- const executionRecord = {
27
- input: { value: 'test-input' },
28
- output: { result: 'test-output' },
29
- taskName: 'test-task',
30
- type: 'success',
31
- boundaries: {},
32
- metadata: {}
33
- };
34
- const result = await client.sendLogByUuid(executionRecord, 'task-uuid-123');
35
- expect(result).toBe('success');
36
- expect(mockedAxios.post).toHaveBeenCalledTimes(1);
37
- // Check that the request was made with a UUID
38
- const callArgs = mockedAxios.post.mock.calls[0];
39
- const requestBody = callArgs[1];
40
- const logItem = JSON.parse(requestBody.logItem);
41
- expect(logItem.uuid).toBeDefined();
42
- expect(typeof logItem.uuid).toBe('string');
43
- expect(logItem.uuid).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i); // UUID v7 pattern
44
- });
45
- it('should preserve existing UUID when execution record already has one', async () => {
46
- mockedAxios.post.mockResolvedValueOnce({ data: { success: true } });
47
- const client = new index_1.HiveLogClient(testConfig);
48
- const existingUuid = '01234567-89ab-7def-8123-456789abcdef';
49
- const executionRecord = {
50
- uuid: existingUuid,
51
- input: { value: 'test-input' },
52
- output: { result: 'test-output' },
53
- taskName: 'test-task',
54
- type: 'success',
55
- boundaries: {},
56
- metadata: {}
57
- };
58
- const result = await client.sendLogByUuid(executionRecord, 'task-uuid-123');
59
- expect(result).toBe('success');
60
- expect(mockedAxios.post).toHaveBeenCalledTimes(1);
61
- // Check that the existing UUID was preserved
62
- const callArgs = mockedAxios.post.mock.calls[0];
63
- const requestBody = callArgs[1];
64
- const logItem = JSON.parse(requestBody.logItem);
65
- expect(logItem.uuid).toBe(existingUuid);
66
- });
67
- it('should generate UUID v7 when execution record has empty UUID', async () => {
68
- mockedAxios.post.mockResolvedValueOnce({ data: { success: true } });
69
- const client = new index_1.HiveLogClient(testConfig);
70
- const executionRecord = {
71
- uuid: '', // Empty string should trigger UUID generation
72
- input: { value: 'test-input' },
73
- output: { result: 'test-output' },
74
- taskName: 'test-task',
75
- type: 'success',
76
- boundaries: {},
77
- metadata: {}
78
- };
79
- const result = await client.sendLogByUuid(executionRecord, 'task-uuid-123');
80
- expect(result).toBe('success');
81
- expect(mockedAxios.post).toHaveBeenCalledTimes(1);
82
- // Check that a new UUID was generated (not empty string)
83
- const callArgs = mockedAxios.post.mock.calls[0];
84
- const requestBody = callArgs[1];
85
- const logItem = JSON.parse(requestBody.logItem);
86
- expect(logItem.uuid).toBeDefined();
87
- expect(logItem.uuid).not.toBe('');
88
- expect(typeof logItem.uuid).toBe('string');
89
- expect(logItem.uuid).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i); // UUID v7 pattern
90
- });
91
- });
92
- describe('API Integration', () => {
93
- it('should send correct request to log-ingest endpoint', async () => {
94
- mockedAxios.post.mockResolvedValueOnce({ data: { success: true } });
95
- const client = new index_1.HiveLogClient(testConfig);
96
- const taskUuid = 'f47ac10b-58cc-4372-a567-0e02b2c3d479';
97
- const executionRecord = {
98
- input: { userId: 123 },
99
- output: { result: 'processed' },
100
- taskName: 'process-user',
101
- type: 'success',
102
- boundaries: {},
103
- metadata: { session: 'abc123' }
104
- };
105
- await client.sendLogByUuid(executionRecord, taskUuid);
106
- expect(mockedAxios.post).toHaveBeenCalledWith('https://test.example.com/api/log-ingest', {
107
- projectUuid: testConfig.projectUuid,
108
- taskUuid: taskUuid,
109
- logItem: expect.any(String)
110
- }, {
111
- headers: {
112
- 'Authorization': 'Bearer test-key:test-secret',
113
- 'Content-Type': 'application/json'
114
- }
115
- });
116
- // Verify the logItem contains the execution record with UUID
117
- const callArgs = mockedAxios.post.mock.calls[0];
118
- const requestBody = callArgs[1];
119
- const logItem = JSON.parse(requestBody.logItem);
120
- expect(logItem.uuid).toBeDefined();
121
- expect(logItem.input).toEqual({ userId: 123 });
122
- expect(logItem.output).toEqual({ result: 'processed' });
123
- expect(logItem.taskName).toBe('process-user');
124
- expect(logItem.type).toBe('success');
125
- expect(logItem.metadata).toEqual({ session: 'abc123' });
126
- });
127
- it('should return "silent" when client is not initialized', async () => {
128
- const client = new index_1.HiveLogClient({
129
- projectName: 'test-project',
130
- projectUuid: testConfig.projectUuid
131
- // Missing apiKey and apiSecret
132
- });
133
- const executionRecord = {
134
- input: { value: 'test' },
135
- taskName: 'test-task',
136
- type: 'success',
137
- boundaries: {},
138
- metadata: {}
139
- };
140
- const result = await client.sendLogByUuid(executionRecord, 'task-uuid-123');
141
- expect(result).toBe('silent');
142
- expect(mockedAxios.post).not.toHaveBeenCalled();
143
- });
144
- it('should return "error" when projectUuid is missing', async () => {
145
- const client = new index_1.HiveLogClient({
146
- projectName: 'test-project',
147
- apiKey: 'test-key',
148
- apiSecret: 'test-secret',
149
- host: 'https://test.example.com'
150
- // Missing projectUuid
151
- });
152
- const executionRecord = {
153
- input: { value: 'test' },
154
- taskName: 'test-task',
155
- type: 'success',
156
- boundaries: {},
157
- metadata: {}
158
- };
159
- const result = await client.sendLogByUuid(executionRecord, 'task-uuid-123');
160
- expect(result).toBe('error');
161
- expect(mockedAxios.post).not.toHaveBeenCalled();
162
- });
163
- it('should handle API error responses', async () => {
164
- mockedAxios.post.mockRejectedValueOnce(new Error('Network error'));
165
- const client = new index_1.HiveLogClient(testConfig);
166
- const executionRecord = {
167
- input: { value: 'test' },
168
- taskName: 'test-task',
169
- type: 'success',
170
- boundaries: {},
171
- metadata: {}
172
- };
173
- const result = await client.sendLogByUuid(executionRecord, 'task-uuid-123');
174
- expect(result).toBe('error');
175
- expect(mockedAxios.post).toHaveBeenCalledTimes(1);
176
- });
177
- it('should return response data when API returns object with uuid', async () => {
178
- const responseData = { uuid: 'log-uuid-123', success: true };
179
- mockedAxios.post.mockResolvedValueOnce({ data: responseData });
180
- const client = new index_1.HiveLogClient(testConfig);
181
- const executionRecord = {
182
- input: { value: 'test' },
183
- taskName: 'test-task',
184
- type: 'success',
185
- boundaries: {},
186
- metadata: {}
187
- };
188
- const result = await client.sendLogByUuid(executionRecord, 'task-uuid-123');
189
- expect(result).toEqual(responseData);
190
- });
191
- });
192
- describe('Metadata Handling', () => {
193
- it('should merge metadata correctly with UUID generation', async () => {
194
- mockedAxios.post.mockResolvedValueOnce({ data: { success: true } });
195
- const baseMetadata = { environment: 'test', version: '1.0' };
196
- const client = new index_1.HiveLogClient({ ...testConfig, metadata: baseMetadata });
197
- const recordMetadata = { session: 'abc123' };
198
- const sendLogMetadata = { priority: 'high' };
199
- const executionRecord = {
200
- input: { value: 'test' },
201
- taskName: 'test-task',
202
- type: 'success',
203
- boundaries: {},
204
- metadata: recordMetadata
205
- };
206
- await client.sendLogByUuid(executionRecord, 'task-uuid-123', sendLogMetadata);
207
- const callArgs = mockedAxios.post.mock.calls[0];
208
- const requestBody = callArgs[1];
209
- const logItem = JSON.parse(requestBody.logItem);
210
- // Should have UUID generated
211
- expect(logItem.uuid).toBeDefined();
212
- expect(typeof logItem.uuid).toBe('string');
213
- // Should have merged metadata (sendLog > record > client)
214
- expect(logItem.metadata).toEqual({
215
- environment: 'test', // from client
216
- version: '1.0', // from client
217
- session: 'abc123', // from record
218
- priority: 'high' // from sendLog (highest priority)
219
- });
220
- });
221
- });
222
- });
@@ -1,272 +0,0 @@
1
- import axios from 'axios'
2
- import { HiveLogClient } from '../index'
3
-
4
- // Mock axios
5
- jest.mock('axios')
6
- const mockedAxios = axios as jest.Mocked<typeof axios>
7
-
8
- describe('HiveLogClient sendLogByUuid', () => {
9
- const testConfig = {
10
- projectName: 'test-project',
11
- projectUuid: '550e8400-e29b-41d4-a716-446655440000',
12
- apiKey: 'test-key',
13
- apiSecret: 'test-secret',
14
- host: 'https://test.example.com'
15
- }
16
-
17
- beforeEach(() => {
18
- jest.clearAllMocks()
19
- })
20
-
21
- describe('UUID Generation', () => {
22
- it('should generate UUID v7 when execution record has no UUID', async () => {
23
- mockedAxios.post.mockResolvedValueOnce({ data: { success: true } })
24
-
25
- const client = new HiveLogClient(testConfig)
26
- const executionRecord = {
27
- input: { value: 'test-input' },
28
- output: { result: 'test-output' },
29
- taskName: 'test-task',
30
- type: 'success' as const,
31
- boundaries: {},
32
- metadata: {}
33
- }
34
-
35
- const result = await client.sendLogByUuid(executionRecord, 'task-uuid-123')
36
-
37
- expect(result).toBe('success')
38
- expect(mockedAxios.post).toHaveBeenCalledTimes(1)
39
-
40
- // Check that the request was made with a UUID
41
- const callArgs = mockedAxios.post.mock.calls[0]
42
- const requestBody = callArgs[1] as { projectUuid: string; taskUuid: string; logItem: string }
43
- const logItem = JSON.parse(requestBody.logItem)
44
-
45
- expect(logItem.uuid).toBeDefined()
46
- expect(typeof logItem.uuid).toBe('string')
47
- expect(logItem.uuid).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i) // UUID v7 pattern
48
- })
49
-
50
- it('should preserve existing UUID when execution record already has one', async () => {
51
- mockedAxios.post.mockResolvedValueOnce({ data: { success: true } })
52
-
53
- const client = new HiveLogClient(testConfig)
54
- const existingUuid = '01234567-89ab-7def-8123-456789abcdef'
55
- const executionRecord = {
56
- uuid: existingUuid,
57
- input: { value: 'test-input' },
58
- output: { result: 'test-output' },
59
- taskName: 'test-task',
60
- type: 'success' as const,
61
- boundaries: {},
62
- metadata: {}
63
- }
64
-
65
- const result = await client.sendLogByUuid(executionRecord, 'task-uuid-123')
66
-
67
- expect(result).toBe('success')
68
- expect(mockedAxios.post).toHaveBeenCalledTimes(1)
69
-
70
- // Check that the existing UUID was preserved
71
- const callArgs = mockedAxios.post.mock.calls[0]
72
- const requestBody = callArgs[1] as { projectUuid: string; taskUuid: string; logItem: string }
73
- const logItem = JSON.parse(requestBody.logItem)
74
-
75
- expect(logItem.uuid).toBe(existingUuid)
76
- })
77
-
78
- it('should generate UUID v7 when execution record has empty UUID', async () => {
79
- mockedAxios.post.mockResolvedValueOnce({ data: { success: true } })
80
-
81
- const client = new HiveLogClient(testConfig)
82
- const executionRecord = {
83
- uuid: '', // Empty string should trigger UUID generation
84
- input: { value: 'test-input' },
85
- output: { result: 'test-output' },
86
- taskName: 'test-task',
87
- type: 'success' as const,
88
- boundaries: {},
89
- metadata: {}
90
- }
91
-
92
- const result = await client.sendLogByUuid(executionRecord, 'task-uuid-123')
93
-
94
- expect(result).toBe('success')
95
- expect(mockedAxios.post).toHaveBeenCalledTimes(1)
96
-
97
- // Check that a new UUID was generated (not empty string)
98
- const callArgs = mockedAxios.post.mock.calls[0]
99
- const requestBody = callArgs[1] as { projectUuid: string; taskUuid: string; logItem: string }
100
- const logItem = JSON.parse(requestBody.logItem)
101
-
102
- expect(logItem.uuid).toBeDefined()
103
- expect(logItem.uuid).not.toBe('')
104
- expect(typeof logItem.uuid).toBe('string')
105
- expect(logItem.uuid).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i) // UUID v7 pattern
106
- })
107
- })
108
-
109
- describe('API Integration', () => {
110
- it('should send correct request to log-ingest endpoint', async () => {
111
- mockedAxios.post.mockResolvedValueOnce({ data: { success: true } })
112
-
113
- const client = new HiveLogClient(testConfig)
114
- const taskUuid = 'f47ac10b-58cc-4372-a567-0e02b2c3d479'
115
- const executionRecord = {
116
- input: { userId: 123 },
117
- output: { result: 'processed' },
118
- taskName: 'process-user',
119
- type: 'success' as const,
120
- boundaries: {},
121
- metadata: { session: 'abc123' }
122
- }
123
-
124
- await client.sendLogByUuid(executionRecord, taskUuid)
125
-
126
- expect(mockedAxios.post).toHaveBeenCalledWith(
127
- 'https://test.example.com/api/log-ingest',
128
- {
129
- projectUuid: testConfig.projectUuid,
130
- taskUuid: taskUuid,
131
- logItem: expect.any(String)
132
- },
133
- {
134
- headers: {
135
- 'Authorization': 'Bearer test-key:test-secret',
136
- 'Content-Type': 'application/json'
137
- }
138
- }
139
- )
140
-
141
- // Verify the logItem contains the execution record with UUID
142
- const callArgs = mockedAxios.post.mock.calls[0]
143
- const requestBody = callArgs[1] as { projectUuid: string; taskUuid: string; logItem: string }
144
- const logItem = JSON.parse(requestBody.logItem)
145
-
146
- expect(logItem.uuid).toBeDefined()
147
- expect(logItem.input).toEqual({ userId: 123 })
148
- expect(logItem.output).toEqual({ result: 'processed' })
149
- expect(logItem.taskName).toBe('process-user')
150
- expect(logItem.type).toBe('success')
151
- expect(logItem.metadata).toEqual({ session: 'abc123' })
152
- })
153
-
154
- it('should return "silent" when client is not initialized', async () => {
155
- const client = new HiveLogClient({
156
- projectName: 'test-project',
157
- projectUuid: testConfig.projectUuid
158
- // Missing apiKey and apiSecret
159
- })
160
-
161
- const executionRecord = {
162
- input: { value: 'test' },
163
- taskName: 'test-task',
164
- type: 'success' as const,
165
- boundaries: {},
166
- metadata: {}
167
- }
168
-
169
- const result = await client.sendLogByUuid(executionRecord, 'task-uuid-123')
170
-
171
- expect(result).toBe('silent')
172
- expect(mockedAxios.post).not.toHaveBeenCalled()
173
- })
174
-
175
- it('should return "error" when projectUuid is missing', async () => {
176
- const client = new HiveLogClient({
177
- projectName: 'test-project',
178
- apiKey: 'test-key',
179
- apiSecret: 'test-secret',
180
- host: 'https://test.example.com'
181
- // Missing projectUuid
182
- })
183
-
184
- const executionRecord = {
185
- input: { value: 'test' },
186
- taskName: 'test-task',
187
- type: 'success' as const,
188
- boundaries: {},
189
- metadata: {}
190
- }
191
-
192
- const result = await client.sendLogByUuid(executionRecord, 'task-uuid-123')
193
-
194
- expect(result).toBe('error')
195
- expect(mockedAxios.post).not.toHaveBeenCalled()
196
- })
197
-
198
- it('should handle API error responses', async () => {
199
- mockedAxios.post.mockRejectedValueOnce(new Error('Network error'))
200
-
201
- const client = new HiveLogClient(testConfig)
202
- const executionRecord = {
203
- input: { value: 'test' },
204
- taskName: 'test-task',
205
- type: 'success' as const,
206
- boundaries: {},
207
- metadata: {}
208
- }
209
-
210
- const result = await client.sendLogByUuid(executionRecord, 'task-uuid-123')
211
-
212
- expect(result).toBe('error')
213
- expect(mockedAxios.post).toHaveBeenCalledTimes(1)
214
- })
215
-
216
- it('should return response data when API returns object with uuid', async () => {
217
- const responseData = { uuid: 'log-uuid-123', success: true }
218
- mockedAxios.post.mockResolvedValueOnce({ data: responseData })
219
-
220
- const client = new HiveLogClient(testConfig)
221
- const executionRecord = {
222
- input: { value: 'test' },
223
- taskName: 'test-task',
224
- type: 'success' as const,
225
- boundaries: {},
226
- metadata: {}
227
- }
228
-
229
- const result = await client.sendLogByUuid(executionRecord, 'task-uuid-123')
230
-
231
- expect(result).toEqual(responseData)
232
- })
233
- })
234
-
235
- describe('Metadata Handling', () => {
236
- it('should merge metadata correctly with UUID generation', async () => {
237
- mockedAxios.post.mockResolvedValueOnce({ data: { success: true } })
238
-
239
- const baseMetadata = { environment: 'test', version: '1.0' }
240
- const client = new HiveLogClient({ ...testConfig, metadata: baseMetadata })
241
-
242
- const recordMetadata = { session: 'abc123' }
243
- const sendLogMetadata = { priority: 'high' }
244
-
245
- const executionRecord = {
246
- input: { value: 'test' },
247
- taskName: 'test-task',
248
- type: 'success' as const,
249
- boundaries: {},
250
- metadata: recordMetadata
251
- }
252
-
253
- await client.sendLogByUuid(executionRecord, 'task-uuid-123', sendLogMetadata)
254
-
255
- const callArgs = mockedAxios.post.mock.calls[0]
256
- const requestBody = callArgs[1] as { projectUuid: string; taskUuid: string; logItem: string }
257
- const logItem = JSON.parse(requestBody.logItem)
258
-
259
- // Should have UUID generated
260
- expect(logItem.uuid).toBeDefined()
261
- expect(typeof logItem.uuid).toBe('string')
262
-
263
- // Should have merged metadata (sendLog > record > client)
264
- expect(logItem.metadata).toEqual({
265
- environment: 'test', // from client
266
- version: '1.0', // from client
267
- session: 'abc123', // from record
268
- priority: 'high' // from sendLog (highest priority)
269
- })
270
- })
271
- })
272
- })