@ai-appforge/nodejs 1.0.0
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 +42 -0
- package/dist/client.d.ts +10 -0
- package/dist/client.js +39 -0
- package/dist/client.test.d.ts +1 -0
- package/dist/client.test.js +12 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/jest.config.cjs +23 -0
- package/package.json +26 -0
- package/src/client.test.ts +15 -0
- package/src/client.ts +55 -0
- package/src/index.ts +2 -0
- package/tsconfig.json +14 -0
- package/tsconfig.test.json +7 -0
package/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# @ai-appforge/nodejs
|
|
2
|
+
|
|
3
|
+
The official Node.js client for AI App Forge.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @ai-appforge/nodejs
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Configuration
|
|
12
|
+
|
|
13
|
+
You can configure the client using environment variables or by passing options to the constructor.
|
|
14
|
+
|
|
15
|
+
**Environment Variables:**
|
|
16
|
+
- `AI_APP_FORGE_BASE_URL`: The URL of your AI App Forge instance (default: `http://localhost:3001`).
|
|
17
|
+
- `AI_APP_FORGE_API_KEY`: Your API key.
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { AiAppForgeClient } from '@ai-appforge/nodejs';
|
|
23
|
+
|
|
24
|
+
// Initialize the client
|
|
25
|
+
// API key can be passed here or set via AI_APP_FORGE_API_KEY env var
|
|
26
|
+
const client = new AiAppForgeClient({
|
|
27
|
+
apiKey: 'your-api-key'
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
async function runWorkflow() {
|
|
31
|
+
try {
|
|
32
|
+
const result = await client.workflows.execute('workflow-id', {
|
|
33
|
+
input_param: 'value'
|
|
34
|
+
});
|
|
35
|
+
console.log('Workflow Result:', result);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.error('Error executing workflow:', error);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
runWorkflow();
|
|
42
|
+
```
|
package/dist/client.d.ts
ADDED
package/dist/client.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import fetch from 'node-fetch';
|
|
2
|
+
import { WorkflowsModule, APIError } from '@ai-appforge/core';
|
|
3
|
+
import * as dotenv from 'dotenv';
|
|
4
|
+
// Load environment variables
|
|
5
|
+
dotenv.config();
|
|
6
|
+
export class AiAppForgeClient {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.baseUrl = process.env.AI_APP_FORGE_BASE_URL || 'http://localhost:3001';
|
|
9
|
+
// Remove trailing slash from baseUrl if present
|
|
10
|
+
this.baseUrl = this.baseUrl.replace(/\/$/, '');
|
|
11
|
+
this.apiKey = options?.apiKey || process.env.AI_APP_FORGE_API_KEY || '';
|
|
12
|
+
// Initialize modules
|
|
13
|
+
this.workflows = new WorkflowsModule(this.request.bind(this));
|
|
14
|
+
}
|
|
15
|
+
async request(endpoint, options) {
|
|
16
|
+
const headers = {
|
|
17
|
+
'Content-Type': 'application/json',
|
|
18
|
+
...(options?.headers || {}),
|
|
19
|
+
};
|
|
20
|
+
if (this.apiKey) {
|
|
21
|
+
headers['x-api-key'] = this.apiKey;
|
|
22
|
+
}
|
|
23
|
+
const res = await fetch(`${this.baseUrl}${endpoint}`, {
|
|
24
|
+
...options,
|
|
25
|
+
headers,
|
|
26
|
+
});
|
|
27
|
+
let data;
|
|
28
|
+
try {
|
|
29
|
+
data = await res.json();
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
data = {};
|
|
33
|
+
}
|
|
34
|
+
if (!res.ok) {
|
|
35
|
+
throw new APIError(res.status, data, res.headers);
|
|
36
|
+
}
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AiAppForgeClient } from './client.js';
|
|
2
|
+
describe('WorkflowSDK Node.js', () => {
|
|
3
|
+
it('should be instantiable', () => {
|
|
4
|
+
const client = new AiAppForgeClient({ apiKey: 'test-key' });
|
|
5
|
+
expect(client).toBeDefined();
|
|
6
|
+
});
|
|
7
|
+
it('should accept optional apiKey', () => {
|
|
8
|
+
const client = new AiAppForgeClient();
|
|
9
|
+
expect(client).toBeDefined();
|
|
10
|
+
});
|
|
11
|
+
// Add more meaningful tests as needed
|
|
12
|
+
});
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/jest.config.cjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
2
|
+
const config = {
|
|
3
|
+
preset: 'ts-jest/presets/default-esm', // Use ESM preset
|
|
4
|
+
testEnvironment: 'node',
|
|
5
|
+
extensionsToTreatAsEsm: ['.ts'],
|
|
6
|
+
moduleNameMapper: {
|
|
7
|
+
'^(\\.{1,2}/.*)\\.js$': '$1',
|
|
8
|
+
},
|
|
9
|
+
transform: {
|
|
10
|
+
'^.+\\.tsx?$': [
|
|
11
|
+
'ts-jest',
|
|
12
|
+
{
|
|
13
|
+
useESM: true,
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
},
|
|
17
|
+
transformIgnorePatterns: [
|
|
18
|
+
// Transform node-fetch and other ESM-only deps
|
|
19
|
+
'node_modules/(?!(node-fetch|data-uri-to-buffer|fetch-blob|formdata-polyfill)/)',
|
|
20
|
+
],
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
module.exports = config;
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ai-appforge/nodejs",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Node.js SDK for AI App Forge",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "npx tsc",
|
|
9
|
+
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@ai-appforge/core": "file:../core",
|
|
13
|
+
"dotenv": "^16.3.1",
|
|
14
|
+
"node-fetch": "^3.3.2"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/jest": "^30.0.0",
|
|
18
|
+
"@types/node": "^20.19.30",
|
|
19
|
+
"@types/node-fetch": "^2.6.4",
|
|
20
|
+
"cross-env": "^10.1.0",
|
|
21
|
+
"jest": "^30.2.0",
|
|
22
|
+
"ts-jest": "^29.4.6",
|
|
23
|
+
"typescript": "^5.0.0"
|
|
24
|
+
},
|
|
25
|
+
"type": "module"
|
|
26
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AiAppForgeClient } from './client.js';
|
|
2
|
+
|
|
3
|
+
describe('WorkflowSDK Node.js', () => {
|
|
4
|
+
it('should be instantiable', () => {
|
|
5
|
+
const client = new AiAppForgeClient({ apiKey: 'test-key' });
|
|
6
|
+
expect(client).toBeDefined();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('should accept optional apiKey', () => {
|
|
10
|
+
const client = new AiAppForgeClient();
|
|
11
|
+
expect(client).toBeDefined();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// Add more meaningful tests as needed
|
|
15
|
+
});
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import fetch, { RequestInit } from 'node-fetch';
|
|
2
|
+
import { WorkflowsModule, APIError } from '@ai-appforge/core';
|
|
3
|
+
import * as dotenv from 'dotenv';
|
|
4
|
+
|
|
5
|
+
// Load environment variables
|
|
6
|
+
dotenv.config();
|
|
7
|
+
|
|
8
|
+
export class AiAppForgeClient {
|
|
9
|
+
private baseUrl: string;
|
|
10
|
+
private apiKey: string;
|
|
11
|
+
|
|
12
|
+
public workflows: WorkflowsModule;
|
|
13
|
+
|
|
14
|
+
constructor(options?: { apiKey?: string }) {
|
|
15
|
+
this.baseUrl = process.env.AI_APP_FORGE_BASE_URL || 'http://localhost:3001';
|
|
16
|
+
// Remove trailing slash from baseUrl if present
|
|
17
|
+
this.baseUrl = this.baseUrl.replace(/\/$/, '');
|
|
18
|
+
|
|
19
|
+
this.apiKey = options?.apiKey || process.env.AI_APP_FORGE_API_KEY || '';
|
|
20
|
+
|
|
21
|
+
// Initialize modules
|
|
22
|
+
this.workflows = new WorkflowsModule(this.request.bind(this));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
private async request<T>(endpoint: string, options?: RequestInit): Promise<T> {
|
|
27
|
+
const headers: Record<string, string> = {
|
|
28
|
+
'Content-Type': 'application/json',
|
|
29
|
+
...(options?.headers as Record<string, string> || {}),
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
if (this.apiKey) {
|
|
33
|
+
headers['x-api-key'] = this.apiKey;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const res = await fetch(`${this.baseUrl}${endpoint}`, {
|
|
37
|
+
...options,
|
|
38
|
+
headers,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
let data: any;
|
|
42
|
+
try {
|
|
43
|
+
data = await res.json();
|
|
44
|
+
} catch {
|
|
45
|
+
data = {};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!res.ok) {
|
|
49
|
+
throw new APIError(res.status, data, res.headers);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return data as T;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
}
|
package/src/index.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src"]
|
|
14
|
+
}
|