@supernal/tts-widget 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/MIGRATION.md ADDED
@@ -0,0 +1,502 @@
1
+ # Migration Guide: v1.2.x → v1.3.0
2
+
3
+ ## What Changed?
4
+
5
+ Version 1.3.0 introduces a **Smart Loader** that gives you automatic updates via CDN while maintaining backward compatibility with bundled code.
6
+
7
+ ### Key Benefits
8
+
9
+ ✅ **Always up-to-date** - Get bug fixes and features automatically
10
+ ✅ **Zero-config** - Works out of the box with sensible defaults
11
+ ✅ **Graceful fallback** - CSP/firewall scenarios handled automatically
12
+ ✅ **Full control** - Opt into bundled mode or pin versions when needed
13
+
14
+ ---
15
+
16
+ ## Breaking Changes
17
+
18
+ **None!** 🎉
19
+
20
+ Existing code continues to work exactly as before. The smart loader is opt-in.
21
+
22
+ ---
23
+
24
+ ## Recommended Migration
25
+
26
+ ### Before (v1.2.x)
27
+
28
+ ```javascript
29
+ import { SupernalTTS } from '@supernal/tts-widget';
30
+ import '@supernal/tts-widget/widget.css';
31
+
32
+ SupernalTTS.init({
33
+ apiUrl: 'https://tts.supernal.ai',
34
+ provider: 'openai',
35
+ voice: 'alloy'
36
+ });
37
+ ```
38
+
39
+ **Behavior:** Loads bundled widget from `node_modules` (never updates)
40
+
41
+ ### After (v1.3.0) - Option 1: Smart Loader (Recommended)
42
+
43
+ ```javascript
44
+ import { WidgetLoader } from '@supernal/tts-widget/loader';
45
+ import '@supernal/tts-widget/widget.css';
46
+
47
+ const widget = await WidgetLoader.load(); // CDN @1 with fallback
48
+ widget.init({
49
+ apiUrl: 'https://tts.supernal.ai',
50
+ provider: 'openai',
51
+ voice: 'alloy'
52
+ });
53
+ ```
54
+
55
+ **Behavior:**
56
+ 1. Tries to load from `https://unpkg.com/@supernal/tts-widget@1/dist/widget.js`
57
+ 2. If CDN fails (CSP/firewall/timeout): Falls back to bundled version
58
+ 3. Always gets latest v1.x.x (patches and minors auto-apply)
59
+
60
+ ### After (v1.3.0) - Option 2: Keep Bundled (No Change Required!)
61
+
62
+ ```javascript
63
+ import { SupernalTTS } from '@supernal/tts-widget';
64
+ import '@supernal/tts-widget/widget.css';
65
+
66
+ SupernalTTS.init({
67
+ apiUrl: 'https://tts.supernal.ai',
68
+ provider: 'openai',
69
+ voice: 'alloy'
70
+ });
71
+ ```
72
+
73
+ **Behavior:** Identical to v1.2.x - always uses bundled widget
74
+ **Note:** Your existing code already uses this pattern - no changes needed!
75
+
76
+ ---
77
+
78
+ ## React Migration
79
+
80
+ ### Before (v1.2.x)
81
+
82
+ ```tsx
83
+ import { TTSInitializer } from '@supernal/tts-widget/react';
84
+
85
+ function App() {
86
+ return (
87
+ <>
88
+ <TTSInitializer apiUrl="https://tts.supernal.ai" />
89
+ <YourApp />
90
+ </>
91
+ );
92
+ }
93
+ ```
94
+
95
+ ### After (v1.3.0) - Default (Smart Loader)
96
+
97
+ ```tsx
98
+ import { TTSInitializer } from '@supernal/tts-widget/react';
99
+
100
+ function App() {
101
+ return (
102
+ <>
103
+ <TTSInitializer
104
+ apiUrl="https://tts.supernal.ai"
105
+ mode="auto" // NEW: Try CDN, fallback to bundled (default)
106
+ version="major" // NEW: Load latest v1.x.x (default)
107
+ />
108
+ <YourApp />
109
+ </>
110
+ );
111
+ }
112
+ ```
113
+
114
+ ### After (v1.3.0) - CSP-Safe Mode
115
+
116
+ ```tsx
117
+ import { TTSInitializer } from '@supernal/tts-widget/react';
118
+
119
+ function App() {
120
+ return (
121
+ <>
122
+ <TTSInitializer
123
+ apiUrl="https://tts.supernal.ai"
124
+ mode="bundled" // Force local version (no CDN)
125
+ />
126
+ <YourApp />
127
+ </>
128
+ );
129
+ }
130
+ ```
131
+
132
+ ---
133
+
134
+ ## Upgrade Strategies
135
+
136
+ ### Strategy 1: Gradual Adoption (Recommended)
137
+
138
+ **Timeline:** Upgrade npm package now, migrate code later
139
+
140
+ ```bash
141
+ npm install @supernal/tts-widget@1.3.0
142
+ ```
143
+
144
+ **Keep existing code:**
145
+ ```javascript
146
+ import { SupernalTTS } from '@supernal/tts-widget';
147
+ // Old behavior, no changes needed
148
+ ```
149
+
150
+ **Migrate when ready:**
151
+ ```javascript
152
+ import { WidgetLoader } from '@supernal/tts-widget/loader';
153
+ const widget = await WidgetLoader.load();
154
+ // New behavior, always up-to-date
155
+ ```
156
+
157
+ ---
158
+
159
+ ### Strategy 2: Immediate Auto-Update
160
+
161
+ **For:** Users who want latest features automatically
162
+
163
+ ```bash
164
+ npm install @supernal/tts-widget@1.3.0
165
+ ```
166
+
167
+ **Update all imports:**
168
+ ```diff
169
+ - import { SupernalTTS } from '@supernal/tts-widget';
170
+ + import { WidgetLoader } from '@supernal/tts-widget/loader';
171
+
172
+ + const widget = await WidgetLoader.load();
173
+ - SupernalTTS.init({ ... });
174
+ + widget.init({ ... });
175
+ ```
176
+
177
+ **Benefits:**
178
+ - Get bug fixes without npm updates
179
+ - New features arrive automatically
180
+ - Fallback ensures it works everywhere
181
+
182
+ ---
183
+
184
+ ### Strategy 3: Version Pinning
185
+
186
+ **For:** Production apps that need stability
187
+
188
+ ```bash
189
+ npm install @supernal/tts-widget@1.3.0
190
+ ```
191
+
192
+ **Pin to current version:**
193
+ ```javascript
194
+ import { WidgetLoader } from '@supernal/tts-widget/loader';
195
+
196
+ const widget = await WidgetLoader.load({
197
+ version: '1.3.0' // Lock to exact version
198
+ });
199
+
200
+ widget.init({ ... });
201
+ ```
202
+
203
+ **When to upgrade:**
204
+ - Test new versions in staging
205
+ - Pin to tested version in production
206
+ - Update pin after verification
207
+
208
+ ---
209
+
210
+ ## Configuration Options
211
+
212
+ ### Version Strategies
213
+
214
+ ```javascript
215
+ // Major version pinning (default, recommended)
216
+ WidgetLoader.load({ version: 'major' })
217
+ // → Loads latest v1.x.x from unpkg.com/@supernal/tts-widget@1/
218
+
219
+ // Always latest (risky, not recommended)
220
+ WidgetLoader.load({ version: 'latest' })
221
+ // → Loads absolute latest, even v2.0.0 breaking changes
222
+
223
+ // Specific version (stability)
224
+ WidgetLoader.load({ version: '1.3.0' })
225
+ // → Locks to exactly v1.3.0, never updates
226
+ ```
227
+
228
+ ### Loading Modes
229
+
230
+ ```javascript
231
+ // Auto mode (default) - Try CDN, fallback to bundled
232
+ WidgetLoader.load({ mode: 'auto' })
233
+
234
+ // CDN only - Error if CDN unavailable
235
+ WidgetLoader.load({ mode: 'cdn' })
236
+
237
+ // Bundled only - Never use CDN (CSP-safe)
238
+ WidgetLoader.load({ mode: 'bundled' })
239
+ ```
240
+
241
+ ### Advanced Options
242
+
243
+ ```javascript
244
+ WidgetLoader.load({
245
+ mode: 'auto',
246
+ version: 'major',
247
+ timeout: 5000, // CDN timeout in ms (default: 3000)
248
+ cdnUrl: 'https://cdn.example.com/widget', // Custom CDN
249
+
250
+ onCdnSuccess: () => {
251
+ console.log('Loaded from CDN');
252
+ },
253
+
254
+ onCdnFail: (error) => {
255
+ console.warn('CDN failed, using bundled:', error);
256
+ }
257
+ })
258
+ ```
259
+
260
+ ---
261
+
262
+ ## Common Use Cases
263
+
264
+ ### Use Case 1: Public Blog (Auto-Update)
265
+
266
+ ```javascript
267
+ import { WidgetLoader } from '@supernal/tts-widget/loader';
268
+ import '@supernal/tts-widget/widget.css';
269
+
270
+ const widget = await WidgetLoader.load();
271
+ widget.init({
272
+ apiUrl: 'https://tts.supernal.ai',
273
+ voice: 'alloy'
274
+ });
275
+ ```
276
+
277
+ **Why:** Get latest features and bug fixes automatically
278
+
279
+ ---
280
+
281
+ ### Use Case 2: Corporate Intranet (Bundled Only)
282
+
283
+ ```javascript
284
+ import { WidgetLoader } from '@supernal/tts-widget/loader';
285
+ import '@supernal/tts-widget/widget.css';
286
+
287
+ const widget = await WidgetLoader.load({ mode: 'bundled' });
288
+ widget.init({
289
+ apiUrl: 'https://tts.internal.company.com',
290
+ voice: 'alloy'
291
+ });
292
+ ```
293
+
294
+ **Why:** Firewall blocks external CDN, need bundled version
295
+
296
+ ---
297
+
298
+ ### Use Case 3: E-Commerce Site (Pinned Version)
299
+
300
+ ```javascript
301
+ import { WidgetLoader } from '@supernal/tts-widget/loader';
302
+ import '@supernal/tts-widget/widget.css';
303
+
304
+ const widget = await WidgetLoader.load({ version: '1.3.0' });
305
+ widget.init({
306
+ apiUrl: 'https://tts.supernal.ai',
307
+ voice: 'nova'
308
+ });
309
+ ```
310
+
311
+ **Why:** Production stability critical, test updates before deploying
312
+
313
+ ---
314
+
315
+ ### Use Case 4: Next.js App with React
316
+
317
+ ```tsx
318
+ // app/layout.tsx
319
+ import { TTSInitializer } from '@supernal/tts-widget/react';
320
+ import '@supernal/tts-widget/widget.css';
321
+
322
+ export default function RootLayout({ children }) {
323
+ return (
324
+ <html>
325
+ <body>
326
+ <TTSInitializer
327
+ apiUrl="https://tts.supernal.ai"
328
+ mode="auto"
329
+ version="major"
330
+ />
331
+ {children}
332
+ </body>
333
+ </html>
334
+ );
335
+ }
336
+ ```
337
+
338
+ **Why:** React integration with automatic updates and SSR support
339
+
340
+ ---
341
+
342
+ ## Troubleshooting
343
+
344
+ ### Issue 1: "Module not found: WidgetLoader"
345
+
346
+ **Cause:** Old version installed
347
+
348
+ **Fix:**
349
+ ```bash
350
+ npm install @supernal/tts-widget@1.3.0
351
+ ```
352
+
353
+ ---
354
+
355
+ ### Issue 2: Widget loads slowly (3s delay)
356
+
357
+ **Cause:** CDN timeout before fallback
358
+
359
+ **Fix:** Either force bundled mode or increase timeout
360
+ ```javascript
361
+ // Option A: Force bundled (no CDN delay)
362
+ WidgetLoader.load({ mode: 'bundled' })
363
+
364
+ // Option B: Increase timeout
365
+ WidgetLoader.load({ timeout: 10000 })
366
+ ```
367
+
368
+ ---
369
+
370
+ ### Issue 3: CSP violation error
371
+
372
+ **Cause:** Content Security Policy blocks unpkg.com
373
+
374
+ **Fix:** Use bundled mode
375
+ ```javascript
376
+ WidgetLoader.load({ mode: 'bundled' })
377
+ ```
378
+
379
+ Or update CSP to allow unpkg:
380
+ ```html
381
+ <meta http-equiv="Content-Security-Policy"
382
+ content="script-src 'self' https://unpkg.com">
383
+ ```
384
+
385
+ ---
386
+
387
+ ### Issue 4: TypeScript errors with new imports
388
+
389
+ **Cause:** TypeScript cache not updated
390
+
391
+ **Fix:**
392
+ ```bash
393
+ # Clear TypeScript cache
394
+ rm -rf node_modules/.cache
395
+ npm install
396
+
397
+ # Restart TypeScript server in VS Code
398
+ Cmd+Shift+P → "TypeScript: Restart TS Server"
399
+ ```
400
+
401
+ ---
402
+
403
+ ## Rollback Plan
404
+
405
+ If you encounter issues with v1.3.0, you can rollback:
406
+
407
+ ### Option 1: Downgrade to v1.2.1
408
+
409
+ ```bash
410
+ npm install @supernal/tts-widget@1.2.1
411
+ ```
412
+
413
+ ### Option 2: Keep v1.3.0 but use bundled mode
414
+
415
+ ```javascript
416
+ import { SupernalTTS } from '@supernal/tts-widget';
417
+ // Identical to v1.2.1 behavior
418
+ ```
419
+
420
+ ---
421
+
422
+ ## FAQs
423
+
424
+ ### Q: Do I need to update my code?
425
+
426
+ **A:** No, existing code works as-is. The smart loader is opt-in.
427
+
428
+ ---
429
+
430
+ ### Q: Will this increase my bundle size?
431
+
432
+ **A:** Slightly. The loader adds ~2KB, but CDN caching saves bandwidth long-term.
433
+
434
+ **Bundle sizes:**
435
+ - v1.2.1: 13.3KB (widget) + 4KB (CSS) = **17.3KB**
436
+ - v1.3.0: 2KB (loader) + 13.3KB (bundled fallback) + 4KB (CSS) = **19.3KB**
437
+ - v1.3.0 (CDN hit): 2KB (loader) + 4KB (CSS) = **6KB** (widget cached by browser)
438
+
439
+ ---
440
+
441
+ ### Q: What if unpkg.com goes down?
442
+
443
+ **A:** Automatic fallback to bundled version ensures your site keeps working.
444
+
445
+ ---
446
+
447
+ ### Q: How do I know if CDN or bundled is loading?
448
+
449
+ **A:** Check browser console for loader messages:
450
+ ```
451
+ [TTS Widget] Attempting CDN load...
452
+ [TTS Widget] CDN load successful
453
+ ```
454
+ or
455
+ ```
456
+ [TTS Widget] CDN load failed: timeout
457
+ [TTS Widget] Falling back to bundled version
458
+ ```
459
+
460
+ ---
461
+
462
+ ### Q: Can I self-host the CDN version?
463
+
464
+ **A:** Yes, but not recommended. Use bundled mode instead:
465
+ ```javascript
466
+ WidgetLoader.load({ mode: 'bundled' })
467
+ ```
468
+
469
+ If you must self-host:
470
+ ```javascript
471
+ WidgetLoader.load({
472
+ cdnUrl: 'https://cdn.yoursite.com/tts-widget',
473
+ version: '1.3.0'
474
+ })
475
+ ```
476
+
477
+ ---
478
+
479
+ ### Q: What happens on major version updates (v2.0.0)?
480
+
481
+ **A:** Your code continues loading v1.x.x until you explicitly upgrade:
482
+ ```javascript
483
+ // Still loads v1.x.x
484
+ WidgetLoader.load({ version: 'major' })
485
+
486
+ // Opt into v2.0.0
487
+ WidgetLoader.load({ version: '2' })
488
+ ```
489
+
490
+ ---
491
+
492
+ ## Need Help?
493
+
494
+ - **Documentation:** https://tts.supernal.ai/docs
495
+ - **GitHub Issues:** https://github.com/supernalintelligence/supernal-tts/issues
496
+ - **Email:** support@supernal.ai
497
+
498
+ ---
499
+
500
+ **Last Updated:** 2026-01-21
501
+ **Current Version:** 1.3.0
502
+ **Status:** Stable