flowscale 1.0.14 → 1.0.16
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 +44 -8
- package/dist/index.d.ts +3 -2
- package/dist/index.js +25 -30
- package/dist/types.d.ts +5 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
# Flowscale Node.js SDK
|
|
2
2
|
|
|
3
|
-
A comprehensive
|
|
3
|
+
A comprehensive SDK designed to simplify interaction with the FlowScale ComfyUI API. This library works in both Node.js and browser environments.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ⚠️ Important Security Notice for Browser Usage
|
|
8
|
+
|
|
9
|
+
When using this SDK in a browser environment, your API key will be exposed to end users. This is a significant security risk. We strongly recommend:
|
|
10
|
+
|
|
11
|
+
1. Using this SDK in a Node.js backend environment
|
|
12
|
+
2. Creating a proxy API that securely handles the API key server-side
|
|
13
|
+
|
|
14
|
+
If you understand the risks and still need to use the SDK directly in the browser, you must explicitly acknowledge this by setting the `allowDangerouslyExposeApiKey` option:
|
|
15
|
+
|
|
16
|
+
```javascript
|
|
17
|
+
const flowscale = new FlowscaleAPI({
|
|
18
|
+
apiKey: 'your-api-key',
|
|
19
|
+
baseUrl: 'your-api-url',
|
|
20
|
+
allowDangerouslyExposeApiKey: false // Only set to true if you understand the security risks
|
|
21
|
+
});
|
|
22
|
+
```
|
|
4
23
|
|
|
5
24
|
---
|
|
6
25
|
|
|
@@ -29,18 +48,35 @@ To get started, import the Flowscale SDK into your project:
|
|
|
29
48
|
```javascript
|
|
30
49
|
import { FlowscaleAPI } from 'flowscale';
|
|
31
50
|
|
|
32
|
-
//
|
|
51
|
+
// Node.js Environment (Recommended)
|
|
33
52
|
const apiKey = process.env.FLOWSCALE_API_KEY;
|
|
34
53
|
const apiUrl = process.env.FLOWSCALE_API_URL;
|
|
35
54
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
55
|
+
const flowscale = new FlowscaleAPI({
|
|
56
|
+
apiKey,
|
|
57
|
+
baseUrl: apiUrl
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Browser Environment (Not Recommended)
|
|
61
|
+
const flowscale = new FlowscaleAPI({
|
|
62
|
+
apiKey: 'your-api-key', // ⚠️ WARNING: This will be exposed to users
|
|
63
|
+
baseUrl: 'https://your-api-url.pod.flowscale.ai',
|
|
64
|
+
allowDangerouslyExposeApiKey: true // Explicitly acknowledge the security risk
|
|
65
|
+
});
|
|
42
66
|
```
|
|
43
67
|
|
|
68
|
+
### Environment-Specific Considerations
|
|
69
|
+
|
|
70
|
+
#### Node.js (Recommended)
|
|
71
|
+
- Store API keys in environment variables
|
|
72
|
+
- Use `.env` files for configuration
|
|
73
|
+
- Full access to all SDK features
|
|
74
|
+
|
|
75
|
+
#### Browser
|
|
76
|
+
- API key will be visible in network requests
|
|
77
|
+
- Supports File/Blob uploads directly from browser
|
|
78
|
+
- Consider implementing a backend proxy instead
|
|
79
|
+
|
|
44
80
|
**Environment Variables:** Add the following to your `.env` file:
|
|
45
81
|
|
|
46
82
|
```plaintext
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { HealthCheckResponse, QueueResponse, ExecuteWorkflowResponse, GetOutputResponse, RunDetailResponse, RunListResponse, CancelRunResponse } from './types';
|
|
1
|
+
import { HealthCheckResponse, QueueResponse, ExecuteWorkflowResponse, GetOutputResponse, RunDetailResponse, RunListResponse, CancelRunResponse, FlowscaleConfig } from './types';
|
|
2
2
|
export declare class FlowscaleAPI {
|
|
3
3
|
private apiKey;
|
|
4
4
|
private baseUrl;
|
|
5
5
|
private client;
|
|
6
|
-
|
|
6
|
+
private isNode;
|
|
7
|
+
constructor(config: FlowscaleConfig);
|
|
7
8
|
/**
|
|
8
9
|
* Checks the health status of all ComfyUI instances within the specified cluster.
|
|
9
10
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -52,14 +41,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
52
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
42
|
exports.FlowscaleAPI = void 0;
|
|
54
43
|
var axios_1 = __importDefault(require("axios"));
|
|
55
|
-
var form_data_1 = __importDefault(require("form-data"));
|
|
56
|
-
var fs_1 = __importDefault(require("fs"));
|
|
57
|
-
var path_1 = __importDefault(require("path"));
|
|
58
44
|
var FlowscaleAPI = /** @class */ (function () {
|
|
59
|
-
function FlowscaleAPI(
|
|
45
|
+
function FlowscaleAPI(config) {
|
|
60
46
|
var _this = this;
|
|
61
|
-
|
|
62
|
-
this.
|
|
47
|
+
// Check if we're in a Node.js environment
|
|
48
|
+
this.isNode = typeof process !== 'undefined' &&
|
|
49
|
+
process.versions != null &&
|
|
50
|
+
process.versions.node != null;
|
|
51
|
+
// Warn about API key exposure in browser environment
|
|
52
|
+
if (!this.isNode && !config.allowDangerouslyExposeApiKey) {
|
|
53
|
+
throw new Error('WARNING: Using FlowscaleAPI in a browser environment will expose your API key to end users. ' +
|
|
54
|
+
'This is a security risk. If you understand the risks and still want to proceed, ' +
|
|
55
|
+
'set allowDangerouslyExposeApiKey to true. ' +
|
|
56
|
+
'We strongly recommend using a backend proxy instead.');
|
|
57
|
+
}
|
|
58
|
+
this.apiKey = config.apiKey;
|
|
59
|
+
this.baseUrl = config.baseUrl;
|
|
63
60
|
this.client = axios_1.default.create({
|
|
64
61
|
baseURL: this.baseUrl,
|
|
65
62
|
});
|
|
@@ -132,7 +129,7 @@ var FlowscaleAPI = /** @class */ (function () {
|
|
|
132
129
|
switch (_a.label) {
|
|
133
130
|
case 0:
|
|
134
131
|
_a.trys.push([0, 2, , 3]);
|
|
135
|
-
formData_1 = new
|
|
132
|
+
formData_1 = new FormData();
|
|
136
133
|
_loop_1 = function (key) {
|
|
137
134
|
if (data.hasOwnProperty(key)) {
|
|
138
135
|
var value = data[key];
|
|
@@ -152,7 +149,10 @@ var FlowscaleAPI = /** @class */ (function () {
|
|
|
152
149
|
for (key in data) {
|
|
153
150
|
_loop_1(key);
|
|
154
151
|
}
|
|
155
|
-
headers =
|
|
152
|
+
headers = {
|
|
153
|
+
'Content-Type': 'multipart/form-data',
|
|
154
|
+
'X-API-KEY': this.apiKey,
|
|
155
|
+
};
|
|
156
156
|
url = "/api/v1/runs?workflow_id=".concat(encodeURIComponent(workflowId)).concat(groupId ? "&group_id=".concat(encodeURIComponent(groupId)) : '');
|
|
157
157
|
return [4 /*yield*/, this.client.post(url, formData_1, { headers: headers })];
|
|
158
158
|
case 1:
|
|
@@ -333,21 +333,16 @@ var FlowscaleAPI = /** @class */ (function () {
|
|
|
333
333
|
* Helper method to append data to FormData.
|
|
334
334
|
*/
|
|
335
335
|
FlowscaleAPI.prototype.appendFormData = function (formData, key, value) {
|
|
336
|
-
if (value instanceof
|
|
337
|
-
//
|
|
336
|
+
if (value instanceof Blob || value instanceof File) {
|
|
337
|
+
// Handle File and Blob objects directly
|
|
338
338
|
formData.append(key, value);
|
|
339
339
|
}
|
|
340
|
-
else if (
|
|
341
|
-
//
|
|
342
|
-
formData.append(key,
|
|
343
|
-
}
|
|
344
|
-
else if (typeof value === 'string' && fs_1.default.existsSync(value)) {
|
|
345
|
-
// If the value is a file path
|
|
346
|
-
var fileName = path_1.default.basename(value);
|
|
347
|
-
formData.append(key, fs_1.default.createReadStream(value), fileName);
|
|
340
|
+
else if (typeof value === 'object' && value !== null) {
|
|
341
|
+
// Handle plain objects by stringifying
|
|
342
|
+
formData.append(key, JSON.stringify(value));
|
|
348
343
|
}
|
|
349
344
|
else {
|
|
350
|
-
//
|
|
345
|
+
// Handle primitive values
|
|
351
346
|
formData.append(key, value);
|
|
352
347
|
}
|
|
353
348
|
};
|
package/dist/types.d.ts
CHANGED