wavespeed 0.0.2 → 0.0.3

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.
Files changed (2) hide show
  1. package/dist/index.js +22 -6
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ /**
3
+ * Input parameters for image generation
4
+ */
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.WaveSpeed = exports.Prediction = void 0;
4
- const url_1 = require("url");
5
7
  /**
6
8
  * Prediction model representing an image generation job
7
9
  */
@@ -73,15 +75,23 @@ class WaveSpeed {
73
75
  */
74
76
  constructor(apiKey, options = {}) {
75
77
  this.baseUrl = 'https://api.wavespeed.ai/api/v2/';
76
- this.apiKey = apiKey || process.env.WAVESPEED_API_KEY || '';
78
+ // Browser-friendly environment variable handling
79
+ const getEnvVar = (name) => {
80
+ // Try to get from process.env for Node.js environments
81
+ if (typeof process !== 'undefined' && process.env && process.env[name]) {
82
+ return process.env[name];
83
+ }
84
+ return undefined;
85
+ };
86
+ this.apiKey = apiKey || getEnvVar('WAVESPEED_API_KEY') || '';
77
87
  if (!this.apiKey) {
78
88
  throw new Error('API key is required. Provide it as a parameter or set the WAVESPEED_API_KEY environment variable.');
79
89
  }
80
90
  if (options.baseUrl) {
81
91
  this.baseUrl = options.baseUrl;
82
92
  }
83
- this.pollInterval = options.pollInterval || Number(process.env.WAVESPEED_POLL_INTERVAL) || 1;
84
- this.timeout = options.timeout || Number(process.env.WAVESPEED_TIMEOUT) || 60;
93
+ this.pollInterval = options.pollInterval || Number(getEnvVar('WAVESPEED_POLL_INTERVAL')) || 1;
94
+ this.timeout = options.timeout || Number(getEnvVar('WAVESPEED_TIMEOUT')) || 60;
85
95
  }
86
96
  /**
87
97
  * Fetch with timeout support
@@ -97,11 +107,13 @@ class WaveSpeed {
97
107
  'Authorization': `Bearer ${this.apiKey}`,
98
108
  'Content-Type': 'application/json'
99
109
  };
110
+ // Use AbortController for timeout (supported in modern browsers)
100
111
  const controller = new AbortController();
101
112
  const id = setTimeout(() => controller.abort(), timeout);
102
113
  try {
103
- // Construct the full URL by joining baseUrl and path
104
- const url = new url_1.URL(path, this.baseUrl).toString();
114
+ // Use browser's built-in URL API
115
+ const url = new URL(path, this.baseUrl).toString();
116
+ // Use the global fetch API available in browsers
105
117
  const response = await fetch(url, {
106
118
  ...fetchOptions,
107
119
  signal: controller.signal
@@ -147,3 +159,7 @@ class WaveSpeed {
147
159
  exports.WaveSpeed = WaveSpeed;
148
160
  // Export default and named exports for different import styles
149
161
  exports.default = WaveSpeed;
162
+ // Add browser global for UMD-style usage
163
+ if (typeof window !== 'undefined') {
164
+ window.WaveSpeed = WaveSpeed;
165
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wavespeed",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "WaveSpeed Client SDK for Wavespeed API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -34,4 +34,4 @@
34
34
  "files": [
35
35
  "dist"
36
36
  ]
37
- }
37
+ }