@forgehive/forge-cli 0.3.2 → 0.3.3

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.
@@ -0,0 +1,16 @@
1
+ import { type InvokeResult } from '@forgehive/hive-sdk';
2
+ import { type ForgeConf, type Profile } from '../types';
3
+ export declare const invoke: import("@forgehive/task").TaskInstanceType<(argv: {
4
+ descriptorName: string;
5
+ json: string;
6
+ }, boundaries: import("@forgehive/task").WrappedBoundaries<{
7
+ loadConf: (args: {}) => Promise<Promise<ForgeConf>>;
8
+ loadCurrentProfile: (args: {}) => Promise<Promise<Profile>>;
9
+ parseJSON: (jsonString: string) => Promise<unknown>;
10
+ invokeTask: (projectUuid: string, profile: Profile, taskName: string, payload: unknown) => Promise<InvokeResult | null>;
11
+ }>) => Promise<unknown>, {
12
+ loadConf: (args: {}) => Promise<Promise<ForgeConf>>;
13
+ loadCurrentProfile: (args: {}) => Promise<Promise<Profile>>;
14
+ parseJSON: (jsonString: string) => Promise<unknown>;
15
+ invokeTask: (projectUuid: string, profile: Profile, taskName: string, payload: unknown) => Promise<InvokeResult | null>;
16
+ }>;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ // TASK: invoke
3
+ // Run this task with:
4
+ // forge task:run task:invoke
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.invoke = void 0;
7
+ const task_1 = require("@forgehive/task");
8
+ const schema_1 = require("@forgehive/schema");
9
+ const hive_sdk_1 = require("@forgehive/hive-sdk");
10
+ const load_1 = require("../conf/load");
11
+ const loadCurrent_1 = require("../auth/loadCurrent");
12
+ const name = 'task:invoke';
13
+ const description = 'Invoke a deployed task remotely using the Hive API';
14
+ const schema = new schema_1.Schema({
15
+ descriptorName: schema_1.Schema.string(),
16
+ json: schema_1.Schema.string()
17
+ });
18
+ const boundaries = {
19
+ loadConf: load_1.load.asBoundary(),
20
+ loadCurrentProfile: loadCurrent_1.loadCurrent.asBoundary(),
21
+ parseJSON: async (jsonString) => {
22
+ try {
23
+ return JSON.parse(jsonString);
24
+ }
25
+ catch (error) {
26
+ throw new Error(`Invalid JSON: ${error instanceof Error ? error.message : 'Unknown error'}`);
27
+ }
28
+ },
29
+ invokeTask: async (projectUuid, profile, taskName, payload) => {
30
+ const client = (0, hive_sdk_1.createHiveClient)({
31
+ projectUuid,
32
+ apiKey: profile.apiKey,
33
+ apiSecret: profile.apiSecret,
34
+ host: profile.url
35
+ });
36
+ console.log(`Invoking task: ${taskName}`);
37
+ console.log('Payload:', payload);
38
+ console.log(`Using profile: ${profile.name} (${profile.url})`);
39
+ return await client.invoke(taskName, payload);
40
+ }
41
+ };
42
+ exports.invoke = (0, task_1.createTask)({
43
+ name,
44
+ description,
45
+ schema,
46
+ boundaries,
47
+ fn: async function ({ descriptorName, json }, { loadConf, loadCurrentProfile, parseJSON, invokeTask }) {
48
+ // Load forge configuration
49
+ const forge = await loadConf({});
50
+ const taskDescriptor = forge.tasks[descriptorName];
51
+ if (taskDescriptor === undefined) {
52
+ throw new Error(`Task "${descriptorName}" is not defined in forge.json`);
53
+ }
54
+ // Check for project UUID
55
+ if (!forge.project.uuid) {
56
+ throw new Error('Project UUID is not defined in forge.json. Please ensure your project has a UUID.');
57
+ }
58
+ // Load profile (required for invoke)
59
+ let profile;
60
+ try {
61
+ profile = await loadCurrentProfile({});
62
+ }
63
+ catch (error) {
64
+ throw new Error('No profile found. Please authenticate first using: forge auth:add');
65
+ }
66
+ // Parse the JSON payload
67
+ const payload = await parseJSON(json);
68
+ // Invoke the task using the boundary
69
+ const result = await invokeTask(forge.project.uuid, profile, descriptorName, payload);
70
+ if ((0, hive_sdk_1.isInvokeError)(result)) {
71
+ throw new Error(`Task invocation failed: ${result.error}`);
72
+ }
73
+ console.log('Success! Task invoked successfully.');
74
+ return result?.responsePayload;
75
+ }
76
+ });
package/forge.json CHANGED
@@ -109,6 +109,10 @@
109
109
  "bundle:fingerprint": {
110
110
  "path": "src/tasks/bundle/fingerprint.ts",
111
111
  "handler": "fingerprint"
112
+ },
113
+ "task:invoke": {
114
+ "path": "src/tasks/task/invoke.ts",
115
+ "handler": "invoke"
112
116
  }
113
117
  },
114
118
  "runners": {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forgehive/forge-cli",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "TypeScript CLI application",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -10,7 +10,7 @@
10
10
  "publishConfig": {
11
11
  "access": "public",
12
12
  "dependencies": {
13
- "@forgehive/hive-sdk": "^0.0.2",
13
+ "@forgehive/hive-sdk": "^0.0.3",
14
14
  "@forgehive/record-tape": "^0.2.2",
15
15
  "@forgehive/runner": "^0.2.2",
16
16
  "@forgehive/schema": "^0.1.4",
@@ -27,11 +27,11 @@
27
27
  "esbuild": "^0.25.0",
28
28
  "handlebars": "^4.7.8",
29
29
  "minimist": "^1.2.8",
30
- "@forgehive/hive-sdk": "0.0.2",
31
- "@forgehive/record-tape": "0.2.2",
32
- "@forgehive/task": "0.2.2",
30
+ "@forgehive/hive-sdk": "0.0.3",
33
31
  "@forgehive/runner": "0.2.2",
34
- "@forgehive/schema": "0.1.4"
32
+ "@forgehive/record-tape": "0.2.2",
33
+ "@forgehive/schema": "0.1.4",
34
+ "@forgehive/task": "0.2.2"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/archiver": "^6.0.3",
package/src/runner.ts CHANGED
@@ -18,6 +18,8 @@ import { replay as replayTask } from './tasks/task/replay'
18
18
  import { list as listTasks } from './tasks/task/list'
19
19
  import { describe as describeTask } from './tasks/task/describe'
20
20
  import { fingerprint as fingerprintTask } from './tasks/task/fingerprint'
21
+ import { invoke as invokeTask } from './tasks/task/invoke'
22
+
21
23
 
22
24
  import { create as createRunner } from './tasks/runner/create'
23
25
  import { remove as removeRunner } from './tasks/runner/remove'
@@ -58,6 +60,7 @@ runner.load('task:replay', replayTask)
58
60
  runner.load('task:list', listTasks)
59
61
  runner.load('task:describe', describeTask)
60
62
  runner.load('task:fingerprint', fingerprintTask)
63
+ runner.load('task:invoke', invokeTask)
61
64
 
62
65
  // Runner commands
63
66
  runner.load('runner:create', createRunner)
@@ -114,6 +117,13 @@ runner.setHandler(async (data: ParsedArgs): Promise<unknown> => {
114
117
  descriptorName: action,
115
118
  uuid
116
119
  })
120
+ } else if (taskName === 'task:invoke') {
121
+ const { json } = args as { json: string }
122
+
123
+ result = await task.run({
124
+ descriptorName: action,
125
+ json
126
+ })
117
127
  } else if (taskName === 'task:replay') {
118
128
  const { path, cache } = args as { path: string, cache: string }
119
129
 
@@ -0,0 +1,93 @@
1
+ // TASK: invoke
2
+ // Run this task with:
3
+ // forge task:run task:invoke
4
+
5
+ import { createTask } from '@forgehive/task'
6
+ import { Schema } from '@forgehive/schema'
7
+ import { createHiveClient, isInvokeError, type InvokeResult } from '@forgehive/hive-sdk'
8
+
9
+ import { load as loadConf } from '../conf/load'
10
+ import { loadCurrent as loadCurrentProfile } from '../auth/loadCurrent'
11
+ import { type ForgeConf, type Profile } from '../types'
12
+
13
+ const name = 'task:invoke'
14
+ const description = 'Invoke a deployed task remotely using the Hive API'
15
+
16
+ const schema = new Schema({
17
+ descriptorName: Schema.string(),
18
+ json: Schema.string()
19
+ })
20
+
21
+ const boundaries = {
22
+ loadConf: loadConf.asBoundary(),
23
+ loadCurrentProfile: loadCurrentProfile.asBoundary(),
24
+ parseJSON: async (jsonString: string): Promise<unknown> => {
25
+ try {
26
+ return JSON.parse(jsonString)
27
+ } catch (error) {
28
+ throw new Error(`Invalid JSON: ${error instanceof Error ? error.message : 'Unknown error'}`)
29
+ }
30
+ },
31
+ invokeTask: async (
32
+ projectUuid: string,
33
+ profile: Profile,
34
+ taskName: string,
35
+ payload: unknown
36
+ ): Promise<InvokeResult | null> => {
37
+ const client = createHiveClient({
38
+ projectUuid,
39
+ apiKey: profile.apiKey,
40
+ apiSecret: profile.apiSecret,
41
+ host: profile.url
42
+ })
43
+
44
+ console.log(`Invoking task: ${taskName}`)
45
+ console.log('Payload:', payload)
46
+ console.log(`Using profile: ${profile.name} (${profile.url})`)
47
+
48
+ return await client.invoke(taskName, payload)
49
+ }
50
+ }
51
+
52
+ export const invoke = createTask({
53
+ name,
54
+ description,
55
+ schema,
56
+ boundaries,
57
+ fn: async function ({ descriptorName, json }, { loadConf, loadCurrentProfile, parseJSON, invokeTask }) {
58
+ // Load forge configuration
59
+ const forge: ForgeConf = await loadConf({})
60
+ const taskDescriptor = forge.tasks[descriptorName as keyof typeof forge.tasks]
61
+
62
+ if (taskDescriptor === undefined) {
63
+ throw new Error(`Task "${descriptorName}" is not defined in forge.json`)
64
+ }
65
+
66
+ // Check for project UUID
67
+ if (!forge.project.uuid) {
68
+ throw new Error('Project UUID is not defined in forge.json. Please ensure your project has a UUID.')
69
+ }
70
+
71
+ // Load profile (required for invoke)
72
+ let profile: Profile
73
+ try {
74
+ profile = await loadCurrentProfile({})
75
+ } catch (error) {
76
+ throw new Error('No profile found. Please authenticate first using: forge auth:add')
77
+ }
78
+
79
+ // Parse the JSON payload
80
+ const payload = await parseJSON(json)
81
+
82
+ // Invoke the task using the boundary
83
+ const result = await invokeTask(forge.project.uuid, profile, descriptorName, payload)
84
+
85
+ if (isInvokeError(result)) {
86
+ throw new Error(`Task invocation failed: ${result.error}`)
87
+ }
88
+
89
+ console.log('Success! Task invoked successfully.')
90
+ return result?.responsePayload
91
+ }
92
+ })
93
+
@@ -20,6 +20,7 @@ export interface Infra {
20
20
  export interface ForgeConf {
21
21
  project: {
22
22
  name: string
23
+ uuid?: string
23
24
  }
24
25
  paths: {
25
26
  logs: string