@ai-appforge/react-native 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 +37 -0
- package/dist/client.d.ts +10 -0
- package/dist/client.js +40 -0
- package/dist/client.test.d.ts +1 -0
- package/dist/client.test.js +10 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -0
- package/jest.config.js +6 -0
- package/package.json +25 -0
- package/src/client.test.ts +9 -0
- package/src/client.ts +50 -0
- package/src/index.ts +2 -0
- package/tsconfig.json +15 -0
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# @ai-appforge/react-native
|
|
2
|
+
|
|
3
|
+
The official React Native client for AI App Forge.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @ai-appforge/react-native
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
> **Note**: This package relies on the global `fetch` API, which is available by default in React Native.
|
|
12
|
+
|
|
13
|
+
## Configuration
|
|
14
|
+
|
|
15
|
+
You can configure the client using environment variables (using a library like `react-native-dotenv`) or by passing options to the constructor.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { AiAppForgeClient } from '@ai-appforge/react-native';
|
|
21
|
+
|
|
22
|
+
const client = new AiAppForgeClient({
|
|
23
|
+
apiKey: 'your-api-key'
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Example: Triggering a workflow from a button press
|
|
27
|
+
const handlePress = async () => {
|
|
28
|
+
try {
|
|
29
|
+
const result = await client.workflows.execute('workflow-id', {
|
|
30
|
+
userInput: 'Hello AI'
|
|
31
|
+
});
|
|
32
|
+
console.log('Result:', result);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error(error);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
```
|
package/dist/client.d.ts
ADDED
package/dist/client.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AiAppForgeClient = void 0;
|
|
4
|
+
const core_1 = require("@ai-appforge/core");
|
|
5
|
+
class AiAppForgeClient {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.baseUrl = process.env.AI_APP_FORGE_BASE_URL || 'http://localhost:3001';
|
|
8
|
+
// Remove trailing slash from baseUrl if present
|
|
9
|
+
this.baseUrl = this.baseUrl.replace(/\/$/, '');
|
|
10
|
+
this.apiKey = options?.apiKey || process.env.AI_APP_FORGE_API_KEY || '';
|
|
11
|
+
// Initialize modules
|
|
12
|
+
this.workflows = new core_1.WorkflowsModule(this.request.bind(this));
|
|
13
|
+
}
|
|
14
|
+
async request(endpoint, options) {
|
|
15
|
+
const headers = {
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
|
+
...(options?.headers || {}),
|
|
18
|
+
};
|
|
19
|
+
if (this.apiKey) {
|
|
20
|
+
headers['x-api-key'] = this.apiKey;
|
|
21
|
+
}
|
|
22
|
+
const res = await fetch(`${this.baseUrl}${endpoint}`, {
|
|
23
|
+
...options,
|
|
24
|
+
headers,
|
|
25
|
+
});
|
|
26
|
+
let data;
|
|
27
|
+
try {
|
|
28
|
+
data = await res.json();
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
data = {};
|
|
32
|
+
}
|
|
33
|
+
if (!res.ok) {
|
|
34
|
+
// Note: React Native's fetch Headers object might behave slightly differently but usually compatible
|
|
35
|
+
throw new core_1.APIError(res.status, data, res.headers);
|
|
36
|
+
}
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.AiAppForgeClient = AiAppForgeClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const client_1 = require("./client");
|
|
4
|
+
describe('WorkflowSDK React Native', () => {
|
|
5
|
+
it('should be instantiable', () => {
|
|
6
|
+
// Just a smoke test
|
|
7
|
+
const client = new client_1.AiAppForgeClient({ apiKey: 'test-key' });
|
|
8
|
+
expect(client).toBeDefined();
|
|
9
|
+
});
|
|
10
|
+
});
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./client"), exports);
|
|
18
|
+
__exportStar(require("@ai-appforge/core"), exports);
|
package/jest.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ai-appforge/react-native",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "React Native SDK for AI App Forge",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "npx tsc",
|
|
9
|
+
"test": "jest"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@ai-appforge/core": "file:../core"
|
|
13
|
+
},
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"react-native": "*"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/jest": "^30.0.0",
|
|
19
|
+
"@types/node": "^25.0.10",
|
|
20
|
+
"@types/react-native": "^0.72.0",
|
|
21
|
+
"jest": "^30.2.0",
|
|
22
|
+
"ts-jest": "^29.4.6",
|
|
23
|
+
"typescript": "^5.0.0"
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { WorkflowsModule, APIError } from '@ai-appforge/core';
|
|
2
|
+
|
|
3
|
+
export class AiAppForgeClient {
|
|
4
|
+
private baseUrl: string;
|
|
5
|
+
private apiKey: string;
|
|
6
|
+
|
|
7
|
+
public workflows: WorkflowsModule;
|
|
8
|
+
|
|
9
|
+
constructor(options: { apiKey: string }) {
|
|
10
|
+
this.baseUrl = process.env.AI_APP_FORGE_BASE_URL || 'http://localhost:3001';
|
|
11
|
+
// Remove trailing slash from baseUrl if present
|
|
12
|
+
this.baseUrl = this.baseUrl.replace(/\/$/, '');
|
|
13
|
+
|
|
14
|
+
this.apiKey = options?.apiKey || process.env.AI_APP_FORGE_API_KEY || '';
|
|
15
|
+
|
|
16
|
+
// Initialize modules
|
|
17
|
+
this.workflows = new WorkflowsModule(this.request.bind(this));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
private async request<T>(endpoint: string, options?: RequestInit): Promise<T> {
|
|
22
|
+
const headers: Record<string, string> = {
|
|
23
|
+
'Content-Type': 'application/json',
|
|
24
|
+
...(options?.headers as Record<string, string> || {}),
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
if (this.apiKey) {
|
|
28
|
+
headers['x-api-key'] = this.apiKey;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const res = await fetch(`${this.baseUrl}${endpoint}`, {
|
|
32
|
+
...options,
|
|
33
|
+
headers,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
let data: any;
|
|
37
|
+
try {
|
|
38
|
+
data = await res.json();
|
|
39
|
+
} catch {
|
|
40
|
+
data = {};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!res.ok) {
|
|
44
|
+
// Note: React Native's fetch Headers object might behave slightly differently but usually compatible
|
|
45
|
+
throw new APIError(res.status, data, res.headers as any);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return data as T;
|
|
49
|
+
}
|
|
50
|
+
}
|
package/src/index.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "CommonJS",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"jsx": "react-native"
|
|
13
|
+
},
|
|
14
|
+
"include": ["src"]
|
|
15
|
+
}
|