@forgehive/hive-sdk 0.1.3 → 0.1.5

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/README.md CHANGED
@@ -2,15 +2,36 @@
2
2
 
3
3
  A TypeScript/JavaScript SDK for interacting with the Forge Hive logging and quality assessment platform.
4
4
 
5
+ ## ⚠️ Deprecation Notices
6
+
7
+ - **`sendLog()` method**: Deprecated. Use `sendLogByName()` or `sendLogByUuid()` instead.
8
+ - **`projectName`-only configuration**: Deprecated. Use `createClientFromForgeConf()` or include `projectUuid` in your configuration.
9
+
10
+ Future versions will require `projectUuid` and remove support for the legacy `sendLog()` method and name-based project identification.
11
+
5
12
  ## Quick Start
6
13
 
7
- Create a client with:
14
+ Create a client from forge.json (recommended):
15
+ ```typescript
16
+ import { createClientFromForgeConf } from '@forgehive/hive-sdk'
17
+
18
+ // Create client from forge.json (recommended)
19
+ const client = createClientFromForgeConf('./forge.json', {
20
+ metadata: {
21
+ environment: 'production',
22
+ version: '1.0.0'
23
+ }
24
+ })
25
+ ```
26
+
27
+ Or create with explicit configuration:
8
28
  ```typescript
9
29
  import { HiveLogClient } from '@forgehive/hive-sdk'
10
30
 
11
- // Create client with explicit configuration (recommended)
31
+ // Create client with explicit configuration
12
32
  const client = new HiveLogClient({
13
33
  projectName: 'My Project',
34
+ projectUuid: 'your-project-uuid',
14
35
  apiKey: 'your_api_key',
15
36
  apiSecret: 'your_api_secret'
16
37
  })
@@ -22,8 +43,8 @@ On your app
22
43
  // Run a task
23
44
  const [res, error, record] = await someTask.safeRun(args)
24
45
 
25
- // Send a log
26
- await client.sendLog('task-name', record)
46
+ // Send a log using task name (recommended)
47
+ await client.sendLogByName('stock:getPrice', record)
27
48
  ```
28
49
 
29
50
  ## Installation
@@ -149,17 +170,61 @@ const clientWithConfig = new HiveLogClient(config)
149
170
  ```
150
171
 
151
172
  **Configuration Object:**
152
- - `projectName`: Name of your project (required)
173
+ - `projectName`: Name of your project (required, ⚠️ deprecated - use `createClientFromForgeConf` instead)
174
+ - `projectUuid`: UUID of your project (recommended for new implementations)
153
175
  - `apiKey`: API key (optional, falls back to `HIVE_API_KEY` environment variable)
154
176
  - `apiSecret`: API secret (optional, falls back to `HIVE_API_SECRET` environment variable)
155
177
  - `host`: Hive instance URL (optional, falls back to `HIVE_HOST` environment variable, then defaults to `https://www.forgehive.cloud`)
156
178
  - `metadata`: Base metadata that will be included with every log (optional)
179
+ - `forgeConfigPath`: Path to forge.json file (optional, defaults to './forge.json')
157
180
 
158
181
  **Returns:** `HiveLogClient` - Configured client instance
159
182
 
183
+ ### `createClientFromForgeConf(forgeConfigPath?: string, additionalConfig?: Partial<HiveLogClientConfig>): HiveLogClient` (Recommended)
184
+
185
+ Creates a Hive log client automatically configured from your forge.json file. This is the recommended way to create clients as it automatically loads project name, UUID, and task configurations.
186
+
187
+ ```typescript
188
+ import { createClientFromForgeConf } from '@forgehive/hive-sdk'
189
+
190
+ // Use default forge.json path (./forge.json)
191
+ const client = createClientFromForgeConf()
192
+
193
+ // Use custom forge.json path
194
+ const client = createClientFromForgeConf('./config/forge.json')
195
+
196
+ // Use default path with additional config
197
+ const client = createClientFromForgeConf(undefined, {
198
+ metadata: {
199
+ environment: 'production',
200
+ version: '1.0.0'
201
+ }
202
+ })
203
+
204
+ // Use custom path with additional config
205
+ const client = createClientFromForgeConf('./forge.json', {
206
+ apiKey: 'override-key', // Override any forge.json values
207
+ metadata: {
208
+ environment: 'production'
209
+ }
210
+ })
211
+ ```
212
+
213
+ **Parameters:**
214
+ - `forgeConfigPath` (optional): Path to forge.json file (defaults to './forge.json')
215
+ - `additionalConfig` (optional): Additional config to override forge.json values
216
+
217
+ **Returns:** `HiveLogClient` - Configured client with project name, UUID, and task mappings from forge.json
218
+
219
+ **Benefits:**
220
+ - Automatically loads project name and UUID from forge.json
221
+ - Enables `sendLogByName()` method for easy task logging
222
+ - Supports task verification with `testConfig()`
223
+ - Reduces configuration boilerplate
224
+
160
225
  ### `createHiveLogClient(config: HiveLogClientConfig): HiveLogClient`
161
226
 
162
- Factory function that creates a new Hive log client instance.
227
+ Factory function that creates a new Hive log client instance with explicit configuration.
163
228
 
164
229
  ```typescript
165
230
  import { createHiveLogClient } from '@forgehive/hive-sdk'
@@ -178,6 +243,61 @@ const client = createHiveLogClient({
178
243
  **Parameters:** Same as `HiveLogClient` constructor
179
244
  **Returns:** `HiveLogClient` - Configured client instance
180
245
 
246
+ ### `sendLog(record: ExecutionRecord, metadata?: Metadata): Promise<'success' | 'error' | 'silent' | LogApiSuccess>` ⚠️ DEPRECATED
247
+
248
+ > **⚠️ DEPRECATION WARNING**: `sendLog()` is deprecated and will be removed in a future version. Use `sendLogByName()` or `sendLogByUuid()` instead for better performance and enhanced features.
249
+
250
+ Sends a log entry to Hive using the legacy endpoint. This method still works but lacks the enhanced features of the newer UUID-based endpoints.
251
+
252
+ ```typescript
253
+ // DEPRECATED - Use sendLogByName() instead
254
+ const status = await client.sendLog(record, metadata)
255
+
256
+ // RECOMMENDED - Use sendLogByName() for automatic UUID lookup
257
+ const status = await client.sendLogByName('stock:getPrice', record, metadata)
258
+ ```
259
+
260
+ ### `sendLogByName(taskName: string, record: ExecutionRecord, metadata?: Metadata): Promise<'success' | 'error' | 'silent' | LogApiSuccess>` (Recommended)
261
+
262
+ Sends a log entry to Hive using task name for automatic UUID lookup. Requires `projectUuid` to be set and forge.json to be loaded.
263
+
264
+ ```typescript
265
+ // Run a task and send log by name
266
+ const [result, error, record] = await myTask.safeRun(args)
267
+ const status = await client.sendLogByName('stock:getPrice', record, {
268
+ environment: 'production',
269
+ requestId: 'req-123'
270
+ })
271
+ ```
272
+
273
+ ### `sendLogByUuid(record: ExecutionRecord, taskUuid: string, metadata?: Metadata): Promise<'success' | 'error' | 'silent' | LogApiSuccess>`
274
+
275
+ Sends a log entry to Hive using explicit task UUID. Requires `projectUuid` to be set in client config.
276
+
277
+ ```typescript
278
+ const status = await client.sendLogByUuid(record, 'a45aafe3-8b01-4b58-b15d-9a96274858ee', metadata)
279
+ ```
280
+
281
+ ### `testConfig(): Promise<TestConfigResult>`
282
+
283
+ Tests the client configuration by verifying credentials, project access, and task synchronization.
284
+
285
+ ```typescript
286
+ const result = await client.testConfig()
287
+ console.log('Config test:', result)
288
+ // Returns: { success, teamName, userName, projectName, projectExists, tasksVerified, error? }
289
+ ```
290
+
291
+ ### `getConf(): Record<string, unknown>`
292
+
293
+ Returns the client configuration with masked secrets (shows first 4 + last 4 characters).
294
+
295
+ ```typescript
296
+ const config = client.getConf()
297
+ console.log('Client config:', config)
298
+ // Returns: { projectName, projectUuid, host, apiKey: 'abcd****wxyz', ... }
299
+ ```
300
+
181
301
  ### `isActive(): boolean`
182
302
 
183
303
  Check if the client is properly initialized with credentials.
@@ -206,7 +326,7 @@ Sends a log entry to Hive for a specific task with optional metadata. Accepts bo
206
326
 
207
327
  ```typescript
208
328
  // Using a manual log item
209
- const status = await hiveLogger.sendLog('user-authentication', {
329
+ const status = await hiveLogger.sendLogByName('user-authentication', {
210
330
  input: { username: 'john_doe', timestamp: Date.now() },
211
331
  output: { success: true, userId: 12345 },
212
332
  boundaries: {
@@ -226,7 +346,7 @@ const status = await hiveLogger.sendLog('user-authentication', {
226
346
 
227
347
  // Using a task execution record directly
228
348
  const [result, error, record] = await someTask.safeRun(args)
229
- await hiveLogger.sendLog('task-name', record, {
349
+ await hiveLogger.sendLogByName('task-name', record, {
230
350
  environment: 'production'
231
351
  })
232
352
 
@@ -320,7 +440,7 @@ The Hive SDK supports a flexible metadata system that allows you to attach conte
320
440
 
321
441
  Metadata is merged using the following priority order (highest to lowest):
322
442
 
323
- 1. **sendLog metadata** - Metadata passed directly to the `sendLog` method
443
+ 1. **sendLogByName metadata** - Metadata passed directly to the `sendLogByName` method
324
444
  2. **logItem metadata** - Metadata already present in the `logItem` object
325
445
  3. **Client base metadata** - Metadata set when creating the client
326
446
 
@@ -348,7 +468,7 @@ const logItem = {
348
468
  }
349
469
 
350
470
  // Send log with additional metadata
351
- await client.sendLog('task-name', logItem, {
471
+ await client.sendLogByName('task-name', logItem, {
352
472
  requestId: 'req-456',
353
473
  version: '1.2.0' // This overrides both logItem and client version
354
474
  })
@@ -358,8 +478,8 @@ await client.sendLog('task-name', logItem, {
358
478
  // environment: 'production', // from client
359
479
  // team: 'backend', // from client
360
480
  // sessionId: 'session-123', // from logItem
361
- // version: '1.2.0', // from sendLog (highest priority)
362
- // requestId: 'req-456' // from sendLog
481
+ // version: '1.2.0', // from sendLogByName (highest priority)
482
+ // requestId: 'req-456' // from sendLogByName
363
483
  // }
364
484
  ```
365
485
 
@@ -382,7 +502,7 @@ const client = new HiveLogClient({
382
502
  **Request-specific metadata:**
383
503
  ```typescript
384
504
  app.post('/api/users', async (req, res) => {
385
- const result = await client.sendLog('create-user', {
505
+ const result = await client.sendLogByName('create-user', {
386
506
  input: req.body,
387
507
  output: newUser
388
508
  }, {
@@ -405,7 +525,7 @@ const logItem = {
405
525
  }
406
526
  }
407
527
 
408
- await client.sendLog('search', logItem)
528
+ await client.sendLogByName('search', logItem)
409
529
  ```
410
530
 
411
531
  ## Types
@@ -414,14 +534,33 @@ await client.sendLog('search', logItem)
414
534
 
415
535
  ```typescript
416
536
  interface HiveLogClientConfig {
417
- projectName: string
537
+ projectName: string // ⚠️ DEPRECATED - use createClientFromForgeConf() instead
538
+ projectUuid?: string // Recommended for new implementations
418
539
  apiKey?: string
419
540
  apiSecret?: string
420
541
  host?: string
421
542
  metadata?: Metadata
543
+ forgeConfigPath?: string // Path to forge.json file
422
544
  }
423
545
  ```
424
546
 
547
+ **⚠️ Migration Guide:**
548
+ ```typescript
549
+ // OLD (deprecated) - projectName only
550
+ const client = new HiveLogClient({
551
+ projectName: 'My Project'
552
+ })
553
+
554
+ // NEW (recommended) - use createClientFromForgeConf
555
+ const client = createClientFromForgeConf('./forge.json')
556
+
557
+ // NEW (alternative) - explicit projectUuid
558
+ const client = new HiveLogClient({
559
+ projectName: 'My Project',
560
+ projectUuid: 'your-project-uuid'
561
+ })
562
+ ```
563
+
425
564
  ### `LogItemInput` (also exported as `LogItem`)
426
565
 
427
566
  ```typescript
@@ -552,7 +691,7 @@ const hiveLogger = new HiveLogClient({
552
691
  // No credentials provided - will use environment variables or go silent
553
692
  })
554
693
 
555
- const status = await hiveLogger.sendLog('task-name', { data: 'example' })
694
+ const status = await hiveLogger.sendLogByName('task-name', { data: 'example' })
556
695
  if (status === 'error') {
557
696
  console.error('Network or API error')
558
697
  } else if (status === 'silent') {
@@ -578,9 +717,9 @@ if (hiveLogger.isActive()) {
578
717
  }
579
718
  ```
580
719
 
581
- **sendLog** - Returns status strings (never throws):
720
+ **sendLogByName** - Returns status strings (never throws):
582
721
  ```typescript
583
- const status = await hiveLogger.sendLog('task', { data: 'test' })
722
+ const status = await hiveLogger.sendLogByName('task', { data: 'test' })
584
723
  // Returns: 'success', 'error', or 'silent'
585
724
  ```
586
725
 
@@ -636,7 +775,7 @@ async function main() {
636
775
  }
637
776
 
638
777
  // Send log with additional high-priority metadata
639
- const status = await hiveLogger.sendLog('document-search', logData, {
778
+ const status = await hiveLogger.sendLogByName('document-search', logData, {
640
779
  requestId: 'req-123456',
641
780
  userId: 'user-789',
642
781
  sessionId: 'sess-abc123'
package/dist/index.d.ts CHANGED
@@ -5,10 +5,12 @@ export interface Metadata {
5
5
  export type { ExecutionRecord } from '@forgehive/task';
6
6
  export interface HiveLogClientConfig {
7
7
  projectName: string;
8
+ projectUuid?: string;
8
9
  apiKey?: string;
9
10
  apiSecret?: string;
10
11
  host?: string;
11
12
  metadata?: Metadata;
13
+ forgeConfigPath?: string;
12
14
  }
13
15
  export interface LogApiResponse {
14
16
  uuid: string;
@@ -35,15 +37,37 @@ export declare class HiveLogClient {
35
37
  private apiSecret;
36
38
  private host;
37
39
  private projectName;
40
+ private projectUuid;
38
41
  private baseMetadata;
39
42
  private isInitialized;
43
+ private forgeConfig;
40
44
  constructor(config: HiveLogClientConfig);
41
45
  isActive(): boolean;
46
+ private maskSecret;
47
+ getConf(): Record<string, unknown>;
48
+ testConfig(): Promise<{
49
+ success: boolean;
50
+ teamName?: string;
51
+ teamUuid?: string;
52
+ userName?: string;
53
+ projectName?: string;
54
+ projectExists?: boolean;
55
+ tasksVerified?: {
56
+ total: number;
57
+ found: number;
58
+ missing: string[];
59
+ };
60
+ error?: string;
61
+ }>;
42
62
  private mergeMetadata;
43
63
  sendLog(record: ExecutionRecord, metadata?: Metadata): Promise<'success' | 'error' | 'silent' | LogApiSuccess>;
64
+ sendLogByUuid(record: ExecutionRecord, taskUuid: string, metadata?: Metadata): Promise<'success' | 'error' | 'silent' | LogApiSuccess>;
44
65
  getListener(): (record: ExecutionRecord) => Promise<void>;
45
66
  getLog(taskName: string, uuid: string): Promise<LogApiResult | null>;
46
67
  setQuality(taskName: string, uuid: string, quality: Quality): Promise<boolean>;
68
+ private loadForgeConfig;
69
+ private getTaskUUID;
70
+ sendLogByName(taskName: string, record: ExecutionRecord, metadata?: Metadata): Promise<'success' | 'error' | 'silent' | LogApiSuccess>;
47
71
  }
48
72
  export declare const createHiveLogClient: (config: HiveLogClientConfig) => HiveLogClient;
49
73
  export interface HiveClientConfig {
@@ -66,6 +90,29 @@ export declare class HiveClient {
66
90
  private host;
67
91
  private projectUuid;
68
92
  constructor(config: HiveClientConfig);
69
- invoke(taskName: string, payload: unknown): Promise<InvokeResult | null>;
93
+ private maskSecret;
94
+ getConf(): Record<string, unknown>;
95
+ testConfig(): Promise<{
96
+ success: boolean;
97
+ teamName?: string;
98
+ teamUuid?: string;
99
+ userName?: string;
100
+ projectName?: string;
101
+ projectExists?: boolean;
102
+ tasksVerified?: {
103
+ total: number;
104
+ found: number;
105
+ missing: string[];
106
+ };
107
+ error?: string;
108
+ }>;
109
+ invoke(taskUuid: string, payload: unknown): Promise<InvokeResult | null>;
70
110
  }
71
111
  export declare const createHiveClient: (config: HiveClientConfig) => HiveClient;
112
+ /**
113
+ * Create a HiveLogClient from forge.json configuration
114
+ * @param forgeConfigPath Path to forge.json file (defaults to './forge.json')
115
+ * @param additionalConfig Additional config options to override forge.json values
116
+ * @returns HiveLogClient configured from forge.json
117
+ */
118
+ export declare const createClientFromForgeConf: (forgeConfigPath?: string, additionalConfig?: Partial<HiveLogClientConfig>) => HiveLogClient;