@forgehive/hive-sdk 0.0.2 → 0.0.4

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/dist/index.d.ts CHANGED
@@ -64,3 +64,26 @@ export declare class HiveLogClient {
64
64
  setQuality(taskName: string, uuid: string, quality: Quality): Promise<boolean>;
65
65
  }
66
66
  export declare const createHiveLogClient: (config: HiveLogClientConfig) => HiveLogClient;
67
+ export interface HiveClientConfig {
68
+ projectUuid: string;
69
+ apiKey?: string;
70
+ apiSecret?: string;
71
+ host?: string;
72
+ }
73
+ export interface InvokeResponse {
74
+ responsePayload: unknown;
75
+ }
76
+ export interface InvokeError {
77
+ error: string;
78
+ }
79
+ export type InvokeResult = InvokeResponse | InvokeError;
80
+ export declare function isInvokeError(response: unknown): response is InvokeError;
81
+ export declare class HiveClient {
82
+ private apiKey;
83
+ private apiSecret;
84
+ private host;
85
+ private projectUuid;
86
+ constructor(config: HiveClientConfig);
87
+ invoke(taskName: string, payload: unknown): Promise<InvokeResult | null>;
88
+ }
89
+ export declare const createHiveClient: (config: HiveClientConfig) => HiveClient;
package/dist/index.js CHANGED
@@ -3,8 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createHiveLogClient = exports.HiveLogClient = void 0;
6
+ exports.createHiveClient = exports.HiveClient = exports.createHiveLogClient = exports.HiveLogClient = void 0;
7
7
  exports.isApiError = isApiError;
8
+ exports.isInvokeError = isInvokeError;
8
9
  const axios_1 = __importDefault(require("axios"));
9
10
  const debug_1 = __importDefault(require("debug"));
10
11
  const log = (0, debug_1.default)('hive-sdk');
@@ -142,3 +143,54 @@ const createHiveLogClient = (config) => {
142
143
  return new HiveLogClient(config);
143
144
  };
144
145
  exports.createHiveLogClient = createHiveLogClient;
146
+ // Type guard to check if invoke response is an error
147
+ function isInvokeError(response) {
148
+ return response !== null && typeof response === 'object' && 'error' in response;
149
+ }
150
+ class HiveClient {
151
+ constructor(config) {
152
+ const apiKey = config.apiKey || process.env.HIVE_API_KEY;
153
+ const apiSecret = config.apiSecret || process.env.HIVE_API_SECRET;
154
+ const host = config.host || process.env.HIVE_HOST || 'https://forgehive.dev';
155
+ if (!apiKey || !apiSecret) {
156
+ throw new Error('Missing Hive API credentials. Please provide apiKey and apiSecret, or set HIVE_API_KEY and HIVE_API_SECRET environment variables. Get them at https://forgehive.dev');
157
+ }
158
+ this.projectUuid = config.projectUuid;
159
+ this.host = host;
160
+ this.apiKey = apiKey;
161
+ this.apiSecret = apiSecret;
162
+ log('HiveClient initialized for project "%s" with host "%s"', config.projectUuid, host);
163
+ }
164
+ async invoke(taskName, payload) {
165
+ try {
166
+ const invokeUrl = `${this.host}/api/project/${this.projectUuid}/task/${taskName}/invoke`;
167
+ log('Invoking task "%s" at %s', taskName, invokeUrl);
168
+ const authToken = `${this.apiKey}:${this.apiSecret}`;
169
+ const response = await axios_1.default.post(invokeUrl, {
170
+ payload
171
+ }, {
172
+ headers: {
173
+ Authorization: `Bearer ${authToken}`,
174
+ 'Content-Type': 'application/json'
175
+ }
176
+ });
177
+ log('Success: Invoked task "%s"', taskName);
178
+ return response.data;
179
+ }
180
+ catch (e) {
181
+ const error = e;
182
+ log('Error: Failed to invoke task "%s": %s', taskName, error.message);
183
+ // Check if it's an axios error with response data
184
+ if (axios_1.default.isAxiosError(error) && error.response?.data) {
185
+ return error.response.data;
186
+ }
187
+ return { error: error.message };
188
+ }
189
+ }
190
+ }
191
+ exports.HiveClient = HiveClient;
192
+ const createHiveClient = (config) => {
193
+ log('Creating HiveClient for project "%s"', config.projectUuid);
194
+ return new HiveClient(config);
195
+ };
196
+ exports.createHiveClient = createHiveClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forgehive/hive-sdk",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -221,3 +221,87 @@ export const createHiveLogClient = (config: HiveLogClientConfig): HiveLogClient
221
221
  log('Creating HiveLogClient for project "%s"', config.projectName)
222
222
  return new HiveLogClient(config)
223
223
  }
224
+
225
+ // Configuration interface for HiveClient
226
+ export interface HiveClientConfig {
227
+ projectUuid: string
228
+ apiKey?: string
229
+ apiSecret?: string
230
+ host?: string
231
+ }
232
+
233
+ // Response types for invoke method
234
+ export interface InvokeResponse {
235
+ responsePayload: unknown
236
+ }
237
+
238
+ export interface InvokeError {
239
+ error: string
240
+ }
241
+
242
+ export type InvokeResult = InvokeResponse | InvokeError
243
+
244
+ // Type guard to check if invoke response is an error
245
+ export function isInvokeError(response: unknown): response is InvokeError {
246
+ return response !== null && typeof response === 'object' && 'error' in response
247
+ }
248
+
249
+ export class HiveClient {
250
+ private apiKey: string
251
+ private apiSecret: string
252
+ private host: string
253
+ private projectUuid: string
254
+
255
+ constructor(config: HiveClientConfig) {
256
+ const apiKey = config.apiKey || process.env.HIVE_API_KEY
257
+ const apiSecret = config.apiSecret || process.env.HIVE_API_SECRET
258
+ const host = config.host || process.env.HIVE_HOST || 'https://forgehive.dev'
259
+
260
+ if (!apiKey || !apiSecret) {
261
+ throw new Error('Missing Hive API credentials. Please provide apiKey and apiSecret, or set HIVE_API_KEY and HIVE_API_SECRET environment variables. Get them at https://forgehive.dev')
262
+ }
263
+
264
+ this.projectUuid = config.projectUuid
265
+ this.host = host
266
+ this.apiKey = apiKey
267
+ this.apiSecret = apiSecret
268
+
269
+ log('HiveClient initialized for project "%s" with host "%s"', config.projectUuid, host)
270
+ }
271
+
272
+ async invoke(taskName: string, payload: unknown): Promise<InvokeResult | null> {
273
+ try {
274
+ const invokeUrl = `${this.host}/api/project/${this.projectUuid}/task/${taskName}/invoke`
275
+ log('Invoking task "%s" at %s', taskName, invokeUrl)
276
+
277
+ const authToken = `${this.apiKey}:${this.apiSecret}`
278
+
279
+ const response = await axios.post(invokeUrl, {
280
+ payload
281
+ }, {
282
+ headers: {
283
+ Authorization: `Bearer ${authToken}`,
284
+ 'Content-Type': 'application/json'
285
+ }
286
+ })
287
+
288
+ log('Success: Invoked task "%s"', taskName)
289
+ return response.data as InvokeResult
290
+ } catch (e) {
291
+ const error = e as Error
292
+ log('Error: Failed to invoke task "%s": %s', taskName, error.message)
293
+
294
+ // Check if it's an axios error with response data
295
+ if (axios.isAxiosError(error) && error.response?.data) {
296
+ return error.response.data as InvokeError
297
+ }
298
+
299
+ return { error: error.message }
300
+ }
301
+ }
302
+ }
303
+
304
+ export const createHiveClient = (config: HiveClientConfig): HiveClient => {
305
+ log('Creating HiveClient for project "%s"', config.projectUuid)
306
+ return new HiveClient(config)
307
+ }