@forgehive/forge-cli 0.3.0 → 0.3.2

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.
@@ -16,7 +16,10 @@ export declare const run: import("@forgehive/task").TaskInstanceType<(argv: {
16
16
  }) => Promise<Promise<any>>;
17
17
  verifyLogFolder: (logsPath: string) => Promise<boolean>;
18
18
  ensureBuildsFolder: () => Promise<string>;
19
- sendLogToAPI: (profile: Profile, projectName: string, taskName: string, logItem: unknown) => Promise<boolean>;
19
+ sendLogToAPI: (profile: Profile, projectName: string, taskName: string, logItem: {
20
+ input: unknown;
21
+ metadata?: Record<string, string>;
22
+ }) => Promise<boolean>;
20
23
  }>) => Promise<any>, {
21
24
  loadConf: (args: {}) => Promise<Promise<ForgeConf>>;
22
25
  loadCurrentProfile: (args: {}) => Promise<Promise<Profile>>;
@@ -31,5 +34,8 @@ export declare const run: import("@forgehive/task").TaskInstanceType<(argv: {
31
34
  }) => Promise<Promise<any>>;
32
35
  verifyLogFolder: (logsPath: string) => Promise<boolean>;
33
36
  ensureBuildsFolder: () => Promise<string>;
34
- sendLogToAPI: (profile: Profile, projectName: string, taskName: string, logItem: unknown) => Promise<boolean>;
37
+ sendLogToAPI: (profile: Profile, projectName: string, taskName: string, logItem: {
38
+ input: unknown;
39
+ metadata?: Record<string, string>;
40
+ }) => Promise<boolean>;
35
41
  }>;
@@ -11,10 +11,10 @@ exports.run = void 0;
11
11
  const path_1 = __importDefault(require("path"));
12
12
  const promises_1 = __importDefault(require("fs/promises"));
13
13
  const os_1 = __importDefault(require("os"));
14
- const axios_1 = __importDefault(require("axios"));
15
14
  const task_1 = require("@forgehive/task");
16
15
  const schema_1 = require("@forgehive/schema");
17
16
  const record_tape_1 = require("@forgehive/record-tape");
17
+ const hive_sdk_1 = require("@forgehive/hive-sdk");
18
18
  const create_1 = require("../bundle/create");
19
19
  const load_1 = require("../bundle/load");
20
20
  const load_2 = require("../conf/load");
@@ -53,25 +53,31 @@ const boundaries = {
53
53
  },
54
54
  sendLogToAPI: async (profile, projectName, taskName, logItem) => {
55
55
  try {
56
- const logsUrl = `${profile.url}/api/tasks/log-ingest`;
57
- const authToken = `${profile.apiKey}:${profile.apiSecret}`;
58
- await axios_1.default.post(logsUrl, {
56
+ const config = {
59
57
  projectName,
60
- taskName,
61
- logItem: JSON.stringify(logItem)
62
- }, {
63
- headers: {
64
- Authorization: `Bearer ${authToken}`,
65
- 'Content-Type': 'application/json'
58
+ apiKey: profile.apiKey,
59
+ apiSecret: profile.apiSecret,
60
+ host: profile.url,
61
+ metadata: {
62
+ environment: 'cli'
66
63
  }
67
- });
68
- console.log('===============================================');
69
- console.log('Log sent to API... ', profile.name, profile.url);
70
- return true;
64
+ };
65
+ const client = new hive_sdk_1.HiveLogClient(config);
66
+ const result = await client.sendLog(taskName, logItem);
67
+ if (result === 'success') {
68
+ console.log('===============================================');
69
+ console.log('Log sent to API... ', profile.name, profile.url);
70
+ return true;
71
+ }
72
+ else {
73
+ console.error('Failed to send log to API:', profile.url);
74
+ return false;
75
+ }
71
76
  }
72
77
  catch (e) {
78
+ console.error('Failed to send log to API:', profile.url);
73
79
  const error = e;
74
- console.error('Failed to send log to API:', error.message);
80
+ console.error('Error:', error.message);
75
81
  return false;
76
82
  }
77
83
  }
@@ -122,23 +128,17 @@ exports.run = (0, task_1.createTask)({
122
128
  throw new Error(`Handler "${taskDescriptor.handler}" not found in bundle`);
123
129
  }
124
130
  // Setup record tape
125
- let tape = new record_tape_1.RecordTape({
131
+ const tape = new record_tape_1.RecordTape({
126
132
  path: logsPath
127
133
  });
128
134
  // load record tape
129
135
  try {
130
136
  await tape.load();
131
- // Need to figure out how to handle the log length
132
- // and other options for the RecordTape
133
- // For now, we'll just keep the implementation simple
134
- const maxLogLength = 9;
135
- const log = tape.getLog();
136
- if (log.length > maxLogLength) {
137
- const newTape = new record_tape_1.RecordTape({
138
- path: logsPath,
139
- log: log.slice(-maxLogLength)
140
- });
141
- tape = newTape;
137
+ // Maintain a maximum log length by removing old records
138
+ const maxLogLength = 10;
139
+ // Remove records from the beginning until we're within the limit
140
+ while (tape.getLength() >= maxLogLength) {
141
+ tape.shift();
142
142
  }
143
143
  }
144
144
  catch (_error) {
@@ -146,7 +146,7 @@ exports.run = (0, task_1.createTask)({
146
146
  }
147
147
  // Run the task with provided arguments
148
148
  const [result, error, record] = await task.safeRun(args);
149
- const logItem = tape.push(descriptorName, record, {
149
+ const logItem = tape.push(record, {
150
150
  environment: 'cli'
151
151
  });
152
152
  await tape.save();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forgehive/forge-cli",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "TypeScript CLI application",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -10,10 +10,11 @@
10
10
  "publishConfig": {
11
11
  "access": "public",
12
12
  "dependencies": {
13
- "@forgehive/record-tape": "^0.2.0",
14
- "@forgehive/runner": "^0.2.0",
13
+ "@forgehive/hive-sdk": "^0.0.2",
14
+ "@forgehive/record-tape": "^0.2.2",
15
+ "@forgehive/runner": "^0.2.2",
15
16
  "@forgehive/schema": "^0.1.4",
16
- "@forgehive/task": "^0.2.0",
17
+ "@forgehive/task": "^0.2.2",
17
18
  "esbuild": "^0.25.0",
18
19
  "handlebars": "^4.7.8",
19
20
  "minimist": "^1.2.8"
@@ -26,10 +27,11 @@
26
27
  "esbuild": "^0.25.0",
27
28
  "handlebars": "^4.7.8",
28
29
  "minimist": "^1.2.8",
29
- "@forgehive/record-tape": "0.2.0",
30
- "@forgehive/task": "0.2.0",
31
- "@forgehive/schema": "0.1.4",
32
- "@forgehive/runner": "0.2.0"
30
+ "@forgehive/hive-sdk": "0.0.2",
31
+ "@forgehive/record-tape": "0.2.2",
32
+ "@forgehive/task": "0.2.2",
33
+ "@forgehive/runner": "0.2.2",
34
+ "@forgehive/schema": "0.1.4"
33
35
  },
34
36
  "devDependencies": {
35
37
  "@types/archiver": "^6.0.3",
@@ -6,11 +6,11 @@
6
6
  import path from 'path'
7
7
  import fs from 'fs/promises'
8
8
  import os from 'os'
9
- import axios from 'axios'
10
9
 
11
10
  import { createTask } from '@forgehive/task'
12
11
  import { Schema } from '@forgehive/schema'
13
12
  import { RecordTape } from '@forgehive/record-tape'
13
+ import { HiveLogClient } from '@forgehive/hive-sdk'
14
14
 
15
15
  import { create as bundleCreate } from '../bundle/create'
16
16
  import { load as bundleLoad } from '../bundle/load'
@@ -51,29 +51,33 @@ const boundaries = {
51
51
 
52
52
  return buildsPath
53
53
  },
54
- sendLogToAPI: async (profile: Profile, projectName: string, taskName: string, logItem: unknown): Promise<boolean> => {
54
+ sendLogToAPI: async (profile: Profile, projectName: string, taskName: string, logItem: { input: unknown; metadata?: Record<string, string> }): Promise<boolean> => {
55
55
  try {
56
- const logsUrl = `${profile.url}/api/tasks/log-ingest`
57
- const authToken = `${profile.apiKey}:${profile.apiSecret}`
58
-
59
- await axios.post(logsUrl, {
56
+ const config = {
60
57
  projectName,
61
- taskName,
62
- logItem: JSON.stringify(logItem)
63
- }, {
64
- headers: {
65
- Authorization: `Bearer ${authToken}`,
66
- 'Content-Type': 'application/json'
58
+ apiKey: profile.apiKey,
59
+ apiSecret: profile.apiSecret,
60
+ host: profile.url,
61
+ metadata: {
62
+ environment: 'cli'
67
63
  }
68
- })
64
+ }
69
65
 
70
- console.log('===============================================')
71
- console.log('Log sent to API... ', profile.name, profile.url)
66
+ const client = new HiveLogClient(config)
67
+ const result = await client.sendLog(taskName, logItem)
72
68
 
73
- return true
69
+ if (result === 'success') {
70
+ console.log('===============================================')
71
+ console.log('Log sent to API... ', profile.name, profile.url)
72
+ return true
73
+ } else {
74
+ console.error('Failed to send log to API:', profile.url)
75
+ return false
76
+ }
74
77
  } catch (e) {
78
+ console.error('Failed to send log to API:', profile.url)
75
79
  const error = e as Error
76
- console.error('Failed to send log to API:', error.message)
80
+ console.error('Error:', error.message)
77
81
  return false
78
82
  }
79
83
  }
@@ -141,7 +145,7 @@ export const run = createTask({
141
145
  }
142
146
 
143
147
  // Setup record tape
144
- let tape = new RecordTape({
148
+ const tape = new RecordTape({
145
149
  path: logsPath
146
150
  })
147
151
 
@@ -149,19 +153,12 @@ export const run = createTask({
149
153
  try {
150
154
  await tape.load()
151
155
 
152
- // Need to figure out how to handle the log length
153
- // and other options for the RecordTape
154
- // For now, we'll just keep the implementation simple
155
- const maxLogLength = 9
156
- const log = tape.getLog()
157
-
158
- if (log.length > maxLogLength) {
159
- const newTape = new RecordTape({
160
- path: logsPath,
161
- log: log.slice(-maxLogLength)
162
- })
156
+ // Maintain a maximum log length by removing old records
157
+ const maxLogLength = 10
163
158
 
164
- tape = newTape
159
+ // Remove records from the beginning until we're within the limit
160
+ while (tape.getLength() >= maxLogLength) {
161
+ tape.shift()
165
162
  }
166
163
  } catch (_error) {
167
164
  // if the tape is not found, create a new one on saving
@@ -169,7 +166,7 @@ export const run = createTask({
169
166
 
170
167
  // Run the task with provided arguments
171
168
  const [result, error, record] = await task.safeRun(args)
172
- const logItem = tape.push(descriptorName, record, {
169
+ const logItem = tape.push(record, {
173
170
  environment: 'cli'
174
171
  })
175
172
  await tape.save()