@ai-appforge/nodejs 1.0.0 → 1.0.1
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/client.d.ts +5 -1
- package/dist/client.js +7 -2
- package/package.json +2 -2
- package/src/client.ts +12 -4
package/dist/client.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { WorkflowsModule } from '@ai-appforge/core';
|
|
1
|
+
import { WorkflowsModule, ActivityModule } from '@ai-appforge/core';
|
|
2
2
|
export declare class AiAppForgeClient {
|
|
3
3
|
private baseUrl;
|
|
4
4
|
private apiKey;
|
|
5
|
+
private authToken?;
|
|
5
6
|
workflows: WorkflowsModule;
|
|
7
|
+
activity: ActivityModule;
|
|
6
8
|
constructor(options?: {
|
|
7
9
|
apiKey?: string;
|
|
10
|
+
baseUrl?: string;
|
|
11
|
+
authToken?: string;
|
|
8
12
|
});
|
|
9
13
|
private request;
|
|
10
14
|
}
|
package/dist/client.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import fetch from 'node-fetch';
|
|
2
|
-
import { WorkflowsModule, APIError } from '@ai-appforge/core';
|
|
2
|
+
import { WorkflowsModule, APIError, ActivityModule } from '@ai-appforge/core';
|
|
3
3
|
import * as dotenv from 'dotenv';
|
|
4
4
|
// Load environment variables
|
|
5
5
|
dotenv.config();
|
|
6
6
|
export class AiAppForgeClient {
|
|
7
7
|
constructor(options) {
|
|
8
|
-
this.baseUrl = process.env.AI_APP_FORGE_BASE_URL || 'http://localhost:3001';
|
|
8
|
+
this.baseUrl = options?.baseUrl || process.env.AI_APP_FORGE_BASE_URL || 'http://localhost:3001';
|
|
9
9
|
// Remove trailing slash from baseUrl if present
|
|
10
10
|
this.baseUrl = this.baseUrl.replace(/\/$/, '');
|
|
11
11
|
this.apiKey = options?.apiKey || process.env.AI_APP_FORGE_API_KEY || '';
|
|
12
|
+
this.authToken = options?.authToken;
|
|
12
13
|
// Initialize modules
|
|
13
14
|
this.workflows = new WorkflowsModule(this.request.bind(this));
|
|
15
|
+
this.activity = new ActivityModule(this.request.bind(this));
|
|
14
16
|
}
|
|
15
17
|
async request(endpoint, options) {
|
|
16
18
|
const headers = {
|
|
@@ -20,6 +22,9 @@ export class AiAppForgeClient {
|
|
|
20
22
|
if (this.apiKey) {
|
|
21
23
|
headers['x-api-key'] = this.apiKey;
|
|
22
24
|
}
|
|
25
|
+
if (this.authToken) {
|
|
26
|
+
headers['Authorization'] = `Bearer ${this.authToken}`;
|
|
27
|
+
}
|
|
23
28
|
const res = await fetch(`${this.baseUrl}${endpoint}`, {
|
|
24
29
|
...options,
|
|
25
30
|
headers,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-appforge/nodejs",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Node.js SDK for AI App Forge",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,4 +23,4 @@
|
|
|
23
23
|
"typescript": "^5.0.0"
|
|
24
24
|
},
|
|
25
25
|
"type": "module"
|
|
26
|
-
}
|
|
26
|
+
}
|
package/src/client.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fetch, { RequestInit } from 'node-fetch';
|
|
2
|
-
import { WorkflowsModule, APIError } from '@ai-appforge/core';
|
|
2
|
+
import { WorkflowsModule, APIError, ActivityModule } from '@ai-appforge/core';
|
|
3
3
|
import * as dotenv from 'dotenv';
|
|
4
4
|
|
|
5
5
|
// Load environment variables
|
|
@@ -8,18 +8,22 @@ dotenv.config();
|
|
|
8
8
|
export class AiAppForgeClient {
|
|
9
9
|
private baseUrl: string;
|
|
10
10
|
private apiKey: string;
|
|
11
|
+
private authToken?: string;
|
|
11
12
|
|
|
12
13
|
public workflows: WorkflowsModule;
|
|
14
|
+
public activity: ActivityModule;
|
|
13
15
|
|
|
14
|
-
constructor(options?: { apiKey?: string }) {
|
|
15
|
-
this.baseUrl = process.env.AI_APP_FORGE_BASE_URL || 'http://localhost:3001';
|
|
16
|
+
constructor(options?: { apiKey?: string; baseUrl?: string; authToken?: string }) {
|
|
17
|
+
this.baseUrl = options?.baseUrl || process.env.AI_APP_FORGE_BASE_URL || 'http://localhost:3001';
|
|
16
18
|
// Remove trailing slash from baseUrl if present
|
|
17
19
|
this.baseUrl = this.baseUrl.replace(/\/$/, '');
|
|
18
20
|
|
|
19
21
|
this.apiKey = options?.apiKey || process.env.AI_APP_FORGE_API_KEY || '';
|
|
22
|
+
this.authToken = options?.authToken;
|
|
20
23
|
|
|
21
24
|
// Initialize modules
|
|
22
25
|
this.workflows = new WorkflowsModule(this.request.bind(this));
|
|
26
|
+
this.activity = new ActivityModule(this.request.bind(this));
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
|
|
@@ -33,6 +37,10 @@ export class AiAppForgeClient {
|
|
|
33
37
|
headers['x-api-key'] = this.apiKey;
|
|
34
38
|
}
|
|
35
39
|
|
|
40
|
+
if (this.authToken) {
|
|
41
|
+
headers['Authorization'] = `Bearer ${this.authToken}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
36
44
|
const res = await fetch(`${this.baseUrl}${endpoint}`, {
|
|
37
45
|
...options,
|
|
38
46
|
headers,
|
|
@@ -46,7 +54,7 @@ export class AiAppForgeClient {
|
|
|
46
54
|
}
|
|
47
55
|
|
|
48
56
|
if (!res.ok) {
|
|
49
|
-
throw new APIError(res.status, data, res.headers);
|
|
57
|
+
throw new APIError(res.status, data, res.headers as any);
|
|
50
58
|
}
|
|
51
59
|
|
|
52
60
|
return data as T;
|