flowscale 1.0.14 → 1.0.15

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 CHANGED
@@ -1,6 +1,25 @@
1
1
  # Flowscale Node.js SDK
2
2
 
3
- A comprehensive Node.js SDK designed to simplify interaction with the FlowScale ComfyUI API. This library abstracts away the complexities of API calls, enabling you to effortlessly invoke workflows, retrieve outputs, manage workflow runs, and monitor system health.
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` parameter:
15
+
16
+ ```javascript
17
+ const flowscale = new FlowscaleAPI(
18
+ apiKey,
19
+ apiUrl,
20
+ true // allowDangerouslyExposeApiKey - Only set to true if you understand the security risks
21
+ );
22
+ ```
4
23
 
5
24
  ---
6
25
 
@@ -29,18 +48,31 @@ To get started, import the Flowscale SDK into your project:
29
48
  ```javascript
30
49
  import { FlowscaleAPI } from 'flowscale';
31
50
 
32
- // Initialize the SDK
51
+ // Node.js Environment (Recommended)
33
52
  const apiKey = process.env.FLOWSCALE_API_KEY;
34
53
  const apiUrl = process.env.FLOWSCALE_API_URL;
35
-
36
- if (!apiKey || !apiUrl) {
37
- console.error('FLOWSCALE_API_KEY or FLOWSCALE_API_URL not set in .env');
38
- process.exit(1);
39
- }
40
-
41
54
  const flowscale = new FlowscaleAPI(apiKey, apiUrl);
55
+
56
+ // Browser Environment (Not Recommended)
57
+ const flowscale = new FlowscaleAPI(
58
+ 'your-api-key', // ⚠️ WARNING: This will be exposed to users
59
+ 'https://your-api-url.pod.flowscale.ai',
60
+ true // Explicitly acknowledge the security risk
61
+ );
42
62
  ```
43
63
 
64
+ ### Environment-Specific Considerations
65
+
66
+ #### Node.js (Recommended)
67
+ - Store API keys in environment variables
68
+ - Use `.env` files for configuration
69
+ - Full access to all SDK features
70
+
71
+ #### Browser
72
+ - API key will be visible in network requests
73
+ - Supports File/Blob uploads directly from browser
74
+ - Consider implementing a backend proxy instead
75
+
44
76
  **Environment Variables:** Add the following to your `.env` file:
45
77
 
46
78
  ```plaintext
package/dist/index.d.ts CHANGED
@@ -3,7 +3,8 @@ export declare class FlowscaleAPI {
3
3
  private apiKey;
4
4
  private baseUrl;
5
5
  private client;
6
- constructor(apiKey: string, baseUrl: string);
6
+ private isNode;
7
+ constructor(apiKey: string, baseUrl: string, allowDangerouslyExposeApiKey?: boolean);
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,12 +41,21 @@ 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(apiKey, baseUrl) {
45
+ function FlowscaleAPI(apiKey, baseUrl, allowDangerouslyExposeApiKey) {
46
+ if (allowDangerouslyExposeApiKey === void 0) { allowDangerouslyExposeApiKey = false; }
60
47
  var _this = this;
48
+ // Check if we're in a Node.js environment
49
+ this.isNode = typeof process !== 'undefined' &&
50
+ process.versions != null &&
51
+ process.versions.node != null;
52
+ // Warn about API key exposure in browser environment
53
+ if (!this.isNode && !allowDangerouslyExposeApiKey) {
54
+ throw new Error('WARNING: Using FlowscaleAPI in a browser environment will expose your API key to end users. ' +
55
+ 'This is a security risk. If you understand the risks and still want to proceed, ' +
56
+ 'set allowDangerouslyExposeApiKey to true. ' +
57
+ 'We strongly recommend using a backend proxy instead.');
58
+ }
61
59
  this.apiKey = apiKey;
62
60
  this.baseUrl = baseUrl;
63
61
  this.client = axios_1.default.create({
@@ -132,7 +130,7 @@ var FlowscaleAPI = /** @class */ (function () {
132
130
  switch (_a.label) {
133
131
  case 0:
134
132
  _a.trys.push([0, 2, , 3]);
135
- formData_1 = new form_data_1.default();
133
+ formData_1 = new FormData();
136
134
  _loop_1 = function (key) {
137
135
  if (data.hasOwnProperty(key)) {
138
136
  var value = data[key];
@@ -152,7 +150,10 @@ var FlowscaleAPI = /** @class */ (function () {
152
150
  for (key in data) {
153
151
  _loop_1(key);
154
152
  }
155
- headers = __assign(__assign({}, formData_1.getHeaders()), { 'X-API-KEY': this.apiKey });
153
+ headers = {
154
+ 'Content-Type': 'multipart/form-data',
155
+ 'X-API-KEY': this.apiKey,
156
+ };
156
157
  url = "/api/v1/runs?workflow_id=".concat(encodeURIComponent(workflowId)).concat(groupId ? "&group_id=".concat(encodeURIComponent(groupId)) : '');
157
158
  return [4 /*yield*/, this.client.post(url, formData_1, { headers: headers })];
158
159
  case 1:
@@ -333,21 +334,16 @@ var FlowscaleAPI = /** @class */ (function () {
333
334
  * Helper method to append data to FormData.
334
335
  */
335
336
  FlowscaleAPI.prototype.appendFormData = function (formData, key, value) {
336
- if (value instanceof fs_1.default.ReadStream) {
337
- // It's a file stream
337
+ if (value instanceof Blob || value instanceof File) {
338
+ // Handle File and Blob objects directly
338
339
  formData.append(key, value);
339
340
  }
340
- else if (Buffer.isBuffer(value)) {
341
- // It's a Buffer
342
- formData.append(key, value, { filename: "".concat(key, ".dat") });
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);
341
+ else if (typeof value === 'object' && value !== null) {
342
+ // Handle plain objects by stringifying
343
+ formData.append(key, JSON.stringify(value));
348
344
  }
349
345
  else {
350
- // Assume it's a string or other value
346
+ // Handle primitive values
351
347
  formData.append(key, value);
352
348
  }
353
349
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flowscale",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "An NPM library for communicating with the Flowscale APIs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",