@forgehive/hive-sdk 0.2.0 → 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.
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forgehive/hive-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@forgehive/task": "^0.
|
|
10
|
+
"@forgehive/task": "^0.3.0"
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"axios": "^1.8.4",
|
|
25
25
|
"debug": "^4.4.1",
|
|
26
26
|
"uuid": "^11.1.0",
|
|
27
|
-
"@forgehive/task": "0.
|
|
27
|
+
"@forgehive/task": "0.3.0"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build": "tsc",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -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
|
-
});
|