kugelaudio 0.1.3 → 0.1.5

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/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ All notable changes to the KugelAudio JavaScript/TypeScript SDK will be document
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.1.3] - 2024-12-25
9
+
10
+ ### Fixed
11
+ - Fixed WebSocket authentication: now correctly uses `master_key` query param when `isMasterKey: true` is set, instead of always using `api_key`
12
+ - Added both `X-API-Key` header and `Authorization: Bearer` header for HTTP requests
13
+
8
14
  ## [0.1.0] - 2024-12-17
9
15
 
10
16
  ### Added
package/dist/index.d.mts CHANGED
@@ -151,10 +151,12 @@ interface StreamCallbacks {
151
151
  * KugelAudio client options.
152
152
  */
153
153
  interface KugelAudioOptions {
154
- /** Your KugelAudio API key */
154
+ /** Your KugelAudio API key or JWT token */
155
155
  apiKey: string;
156
156
  /** Whether apiKey is a master key (for internal/server-side use). Master keys bypass billing. */
157
157
  isMasterKey?: boolean;
158
+ /** Whether apiKey is a JWT token (for user authentication). Takes precedence over isMasterKey. */
159
+ isToken?: boolean;
158
160
  /** API base URL (default: https://api.kugelaudio.com) */
159
161
  apiUrl?: string;
160
162
  /** TTS server URL (default: https://eu.kugelaudio.com) */
@@ -277,6 +279,7 @@ declare class TTSResource {
277
279
  declare class KugelAudio {
278
280
  private _apiKey;
279
281
  private _isMasterKey;
282
+ private _isToken;
280
283
  private _apiUrl;
281
284
  private _ttsUrl;
282
285
  private _timeout;
@@ -291,6 +294,8 @@ declare class KugelAudio {
291
294
  get apiKey(): string;
292
295
  /** Check if using master key authentication */
293
296
  get isMasterKey(): boolean;
297
+ /** Check if using JWT token authentication */
298
+ get isToken(): boolean;
294
299
  /** Get TTS URL */
295
300
  get ttsUrl(): string;
296
301
  /**
package/dist/index.d.ts CHANGED
@@ -151,10 +151,12 @@ interface StreamCallbacks {
151
151
  * KugelAudio client options.
152
152
  */
153
153
  interface KugelAudioOptions {
154
- /** Your KugelAudio API key */
154
+ /** Your KugelAudio API key or JWT token */
155
155
  apiKey: string;
156
156
  /** Whether apiKey is a master key (for internal/server-side use). Master keys bypass billing. */
157
157
  isMasterKey?: boolean;
158
+ /** Whether apiKey is a JWT token (for user authentication). Takes precedence over isMasterKey. */
159
+ isToken?: boolean;
158
160
  /** API base URL (default: https://api.kugelaudio.com) */
159
161
  apiUrl?: string;
160
162
  /** TTS server URL (default: https://eu.kugelaudio.com) */
@@ -277,6 +279,7 @@ declare class TTSResource {
277
279
  declare class KugelAudio {
278
280
  private _apiKey;
279
281
  private _isMasterKey;
282
+ private _isToken;
280
283
  private _apiUrl;
281
284
  private _ttsUrl;
282
285
  private _timeout;
@@ -291,6 +294,8 @@ declare class KugelAudio {
291
294
  get apiKey(): string;
292
295
  /** Check if using master key authentication */
293
296
  get isMasterKey(): boolean;
297
+ /** Check if using JWT token authentication */
298
+ get isToken(): boolean;
294
299
  /** Get TTS URL */
295
300
  get ttsUrl(): string;
296
301
  /**
package/dist/index.js CHANGED
@@ -253,7 +253,14 @@ var TTSResource = class {
253
253
  */
254
254
  buildWsUrl() {
255
255
  const wsUrl = this.client.ttsUrl.replace("https://", "wss://").replace("http://", "ws://");
256
- const authParam = this.client.isMasterKey ? "master_key" : "api_key";
256
+ let authParam;
257
+ if (this.client.isToken) {
258
+ authParam = "token";
259
+ } else if (this.client.isMasterKey) {
260
+ authParam = "master_key";
261
+ } else {
262
+ authParam = "api_key";
263
+ }
257
264
  return `${wsUrl}/ws/tts?${authParam}=${this.client.apiKey}`;
258
265
  }
259
266
  /**
@@ -492,6 +499,7 @@ var KugelAudio = class {
492
499
  }
493
500
  this._apiKey = options.apiKey;
494
501
  this._isMasterKey = options.isMasterKey || false;
502
+ this._isToken = options.isToken || false;
495
503
  this._apiUrl = (options.apiUrl || DEFAULT_API_URL).replace(/\/$/, "");
496
504
  this._ttsUrl = (options.ttsUrl || this._apiUrl).replace(/\/$/, "");
497
505
  this._timeout = options.timeout || 6e4;
@@ -507,6 +515,10 @@ var KugelAudio = class {
507
515
  get isMasterKey() {
508
516
  return this._isMasterKey;
509
517
  }
518
+ /** Check if using JWT token authentication */
519
+ get isToken() {
520
+ return this._isToken;
521
+ }
510
522
  /** Get TTS URL */
511
523
  get ttsUrl() {
512
524
  return this._ttsUrl;
package/dist/index.mjs CHANGED
@@ -217,7 +217,14 @@ var TTSResource = class {
217
217
  */
218
218
  buildWsUrl() {
219
219
  const wsUrl = this.client.ttsUrl.replace("https://", "wss://").replace("http://", "ws://");
220
- const authParam = this.client.isMasterKey ? "master_key" : "api_key";
220
+ let authParam;
221
+ if (this.client.isToken) {
222
+ authParam = "token";
223
+ } else if (this.client.isMasterKey) {
224
+ authParam = "master_key";
225
+ } else {
226
+ authParam = "api_key";
227
+ }
221
228
  return `${wsUrl}/ws/tts?${authParam}=${this.client.apiKey}`;
222
229
  }
223
230
  /**
@@ -456,6 +463,7 @@ var KugelAudio = class {
456
463
  }
457
464
  this._apiKey = options.apiKey;
458
465
  this._isMasterKey = options.isMasterKey || false;
466
+ this._isToken = options.isToken || false;
459
467
  this._apiUrl = (options.apiUrl || DEFAULT_API_URL).replace(/\/$/, "");
460
468
  this._ttsUrl = (options.ttsUrl || this._apiUrl).replace(/\/$/, "");
461
469
  this._timeout = options.timeout || 6e4;
@@ -471,6 +479,10 @@ var KugelAudio = class {
471
479
  get isMasterKey() {
472
480
  return this._isMasterKey;
473
481
  }
482
+ /** Check if using JWT token authentication */
483
+ get isToken() {
484
+ return this._isToken;
485
+ }
474
486
  /** Get TTS URL */
475
487
  get ttsUrl() {
476
488
  return this._ttsUrl;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kugelaudio",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Official JavaScript/TypeScript SDK for KugelAudio TTS API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/src/client.ts CHANGED
@@ -165,8 +165,15 @@ class TTSResource {
165
165
  const wsUrl = this.client.ttsUrl
166
166
  .replace('https://', 'wss://')
167
167
  .replace('http://', 'ws://');
168
- // Use master_key param for master keys (bypasses billing), api_key for regular keys
169
- const authParam = this.client.isMasterKey ? 'master_key' : 'api_key';
168
+ // Use token param for JWT tokens, master_key for master keys (bypasses billing), api_key for regular keys
169
+ let authParam: string;
170
+ if (this.client.isToken) {
171
+ authParam = 'token';
172
+ } else if (this.client.isMasterKey) {
173
+ authParam = 'master_key';
174
+ } else {
175
+ authParam = 'api_key';
176
+ }
170
177
  return `${wsUrl}/ws/tts?${authParam}=${this.client.apiKey}`;
171
178
  }
172
179
 
@@ -481,6 +488,7 @@ class TTSResource {
481
488
  export class KugelAudio {
482
489
  private _apiKey: string;
483
490
  private _isMasterKey: boolean;
491
+ private _isToken: boolean;
484
492
  private _apiUrl: string;
485
493
  private _ttsUrl: string;
486
494
  private _timeout: number;
@@ -499,6 +507,7 @@ export class KugelAudio {
499
507
 
500
508
  this._apiKey = options.apiKey;
501
509
  this._isMasterKey = options.isMasterKey || false;
510
+ this._isToken = options.isToken || false;
502
511
  this._apiUrl = (options.apiUrl || DEFAULT_API_URL).replace(/\/$/, '');
503
512
  // If ttsUrl not specified, use apiUrl (backend proxies to TTS server)
504
513
  this._ttsUrl = (options.ttsUrl || this._apiUrl).replace(/\/$/, '');
@@ -519,6 +528,11 @@ export class KugelAudio {
519
528
  return this._isMasterKey;
520
529
  }
521
530
 
531
+ /** Check if using JWT token authentication */
532
+ get isToken(): boolean {
533
+ return this._isToken;
534
+ }
535
+
522
536
  /** Get TTS URL */
523
537
  get ttsUrl(): string {
524
538
  return this._ttsUrl;
package/src/types.ts CHANGED
@@ -163,10 +163,12 @@ export interface StreamCallbacks {
163
163
  * KugelAudio client options.
164
164
  */
165
165
  export interface KugelAudioOptions {
166
- /** Your KugelAudio API key */
166
+ /** Your KugelAudio API key or JWT token */
167
167
  apiKey: string;
168
168
  /** Whether apiKey is a master key (for internal/server-side use). Master keys bypass billing. */
169
169
  isMasterKey?: boolean;
170
+ /** Whether apiKey is a JWT token (for user authentication). Takes precedence over isMasterKey. */
171
+ isToken?: boolean;
170
172
  /** API base URL (default: https://api.kugelaudio.com) */
171
173
  apiUrl?: string;
172
174
  /** TTS server URL (default: https://eu.kugelaudio.com) */