@2112-lab/central-plant 0.2.12 → 0.3.1

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.
@@ -0,0 +1,1473 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _rollupPluginBabelHelpers = require('../../../_virtual/_rollupPluginBabelHelpers.js');
6
+ var CacheManager = require('./CacheManager.js');
7
+
8
+ /**
9
+ * Retrieve the injected Auth instance. Throws if not configured.
10
+ */
11
+ function getAuth() {
12
+ var auth = CacheManager.cacheManager.config.auth;
13
+ if (!auth) throw new Error('cacheManager.configure({ auth }) must be called before using S3 cache functions');
14
+ return auth;
15
+ }
16
+
17
+ /**
18
+ * Retrieve the injected Storage instance. Throws if not configured.
19
+ */
20
+ function getStorage() {
21
+ var storage = CacheManager.cacheManager.config.storage;
22
+ if (!storage) throw new Error('cacheManager.configure({ storage }) must be called before using S3 cache functions');
23
+ return storage;
24
+ }
25
+
26
+ /**
27
+ * Guard used inside S3 fetchers. Throws a noRetry error (suppressed by onError)
28
+ * instead of letting Storage.get() fail with an Amplify credential warning.
29
+ */
30
+ function requireAuthentication() {
31
+ return _requireAuthentication.apply(this, arguments);
32
+ }
33
+ /**
34
+ * Reset the cache manager identity.
35
+ * Call this when auth state changes to ensure the correct cache partition is used.
36
+ */
37
+ function _requireAuthentication() {
38
+ _requireAuthentication = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee() {
39
+ var err;
40
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context) {
41
+ while (1) switch (_context.n) {
42
+ case 0:
43
+ _context.p = 0;
44
+ _context.n = 1;
45
+ return getAuth().currentAuthenticatedUser();
46
+ case 1:
47
+ _context.n = 3;
48
+ break;
49
+ case 2:
50
+ _context.p = 2;
51
+ _context.v;
52
+ err = new Error('S3 access requires authentication');
53
+ err.code = 'S3CacheNotAuthenticated';
54
+ err.noRetry = true;
55
+ throw err;
56
+ case 3:
57
+ return _context.a(2);
58
+ }
59
+ }, _callee, null, [[0, 2]]);
60
+ }));
61
+ return _requireAuthentication.apply(this, arguments);
62
+ }
63
+ function resetCacheIdentity() {
64
+ CacheManager.cacheManager.resetIdentity();
65
+ console.log('🔄 Cache identity reset - will re-evaluate on next cache access');
66
+ }
67
+
68
+ // --- Global Cache for Bundled/Static Access ---
69
+ var GLOBAL_CACHE_NAME = 'asset-manager-global-v1';
70
+ function getGlobalCache() {
71
+ return _getGlobalCache.apply(this, arguments);
72
+ }
73
+ function _getGlobalCache() {
74
+ _getGlobalCache = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee2() {
75
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context2) {
76
+ while (1) switch (_context2.n) {
77
+ case 0:
78
+ if ('caches' in window) {
79
+ _context2.n = 1;
80
+ break;
81
+ }
82
+ return _context2.a(2, null);
83
+ case 1:
84
+ return _context2.a(2, caches.open(GLOBAL_CACHE_NAME));
85
+ }
86
+ }, _callee2);
87
+ }));
88
+ return _getGlobalCache.apply(this, arguments);
89
+ }
90
+ function executeGlobal(_x) {
91
+ return _executeGlobal.apply(this, arguments);
92
+ }
93
+ /**
94
+ * Clear the entire global cache (bundled models, thumbnails, etc.).
95
+ */
96
+ function _executeGlobal() {
97
+ _executeGlobal = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee3(_ref) {
98
+ var cacheKey, fetcher, processor, metadata, cache, cachedResponse, response, responseClone, headers, responseToCache, _response, _t2, _t3, _t4, _t5, _t6, _t7;
99
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context3) {
100
+ while (1) switch (_context3.n) {
101
+ case 0:
102
+ cacheKey = _ref.cacheKey, fetcher = _ref.fetcher, processor = _ref.processor, metadata = _ref.metadata;
103
+ _context3.p = 1;
104
+ _context3.n = 2;
105
+ return getGlobalCache();
106
+ case 2:
107
+ cache = _context3.v;
108
+ if (cache) {
109
+ _context3.n = 5;
110
+ break;
111
+ }
112
+ _t2 = processor;
113
+ _context3.n = 3;
114
+ return fetcher();
115
+ case 3:
116
+ _t3 = _context3.v;
117
+ _context3.n = 4;
118
+ return _t2(_t3);
119
+ case 4:
120
+ return _context3.a(2, _context3.v);
121
+ case 5:
122
+ _context3.n = 6;
123
+ return cache.match(cacheKey);
124
+ case 6:
125
+ cachedResponse = _context3.v;
126
+ if (!cachedResponse) {
127
+ _context3.n = 8;
128
+ break;
129
+ }
130
+ _context3.n = 7;
131
+ return processor(cachedResponse);
132
+ case 7:
133
+ return _context3.a(2, _context3.v);
134
+ case 8:
135
+ _context3.n = 9;
136
+ return fetcher();
137
+ case 9:
138
+ response = _context3.v;
139
+ // Clone for cache
140
+ responseClone = response.clone(); // Store with metadata headers if possible
141
+ headers = new Headers(responseClone.headers);
142
+ headers.append('X-Cached-Time', Date.now().toString());
143
+ if (metadata) {
144
+ headers.append('X-Cache-Metadata', JSON.stringify(metadata));
145
+ }
146
+
147
+ // We need to create a new Response with updated headers to store it
148
+ _t4 = Response;
149
+ _context3.n = 10;
150
+ return responseClone.blob();
151
+ case 10:
152
+ _t5 = _context3.v;
153
+ _t6 = {
154
+ status: responseClone.status,
155
+ statusText: responseClone.statusText,
156
+ headers: headers
157
+ };
158
+ responseToCache = new _t4(_t5, _t6);
159
+ _context3.n = 11;
160
+ return cache.put(cacheKey, responseToCache);
161
+ case 11:
162
+ _context3.n = 12;
163
+ return processor(response);
164
+ case 12:
165
+ return _context3.a(2, _context3.v);
166
+ case 13:
167
+ _context3.p = 13;
168
+ _t7 = _context3.v;
169
+ console.warn('Global Cache execution failed, falling back to network', _t7);
170
+ _context3.n = 14;
171
+ return fetcher();
172
+ case 14:
173
+ _response = _context3.v;
174
+ _context3.n = 15;
175
+ return processor(_response);
176
+ case 15:
177
+ return _context3.a(2, _context3.v);
178
+ }
179
+ }, _callee3, null, [[1, 13]]);
180
+ }));
181
+ return _executeGlobal.apply(this, arguments);
182
+ }
183
+ function clearGlobalCache() {
184
+ return _clearGlobalCache.apply(this, arguments);
185
+ }
186
+ /**
187
+ * Remove expired entries from the global cache.
188
+ * Returns the number of entries removed.
189
+ */
190
+ function _clearGlobalCache() {
191
+ _clearGlobalCache = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee4() {
192
+ var deleted, _t8;
193
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context4) {
194
+ while (1) switch (_context4.n) {
195
+ case 0:
196
+ _context4.p = 0;
197
+ if ('caches' in window) {
198
+ _context4.n = 1;
199
+ break;
200
+ }
201
+ return _context4.a(2, false);
202
+ case 1:
203
+ _context4.n = 2;
204
+ return caches.delete(GLOBAL_CACHE_NAME);
205
+ case 2:
206
+ deleted = _context4.v;
207
+ if (deleted) console.log('🗑️ Global cache cleared');
208
+ return _context4.a(2, deleted);
209
+ case 3:
210
+ _context4.p = 3;
211
+ _t8 = _context4.v;
212
+ console.warn('Failed to clear global cache:', _t8);
213
+ return _context4.a(2, false);
214
+ }
215
+ }, _callee4, null, [[0, 3]]);
216
+ }));
217
+ return _clearGlobalCache.apply(this, arguments);
218
+ }
219
+ function cleanExpiredGlobalCache() {
220
+ return _cleanExpiredGlobalCache.apply(this, arguments);
221
+ }
222
+ function _cleanExpiredGlobalCache() {
223
+ _cleanExpiredGlobalCache = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee6() {
224
+ var cache, keys, cleaned;
225
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context6) {
226
+ while (1) switch (_context6.n) {
227
+ case 0:
228
+ _context6.n = 1;
229
+ return getGlobalCache();
230
+ case 1:
231
+ cache = _context6.v;
232
+ if (cache) {
233
+ _context6.n = 2;
234
+ break;
235
+ }
236
+ return _context6.a(2, 0);
237
+ case 2:
238
+ _context6.n = 3;
239
+ return cache.keys();
240
+ case 3:
241
+ keys = _context6.v;
242
+ cleaned = 0;
243
+ _context6.n = 4;
244
+ return Promise.all(keys.map(/*#__PURE__*/function () {
245
+ var _ref2 = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee5(request) {
246
+ var response, cachedTime, age, s3Key, expiryMs, _t9;
247
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context5) {
248
+ while (1) switch (_context5.n) {
249
+ case 0:
250
+ _context5.p = 0;
251
+ _context5.n = 1;
252
+ return cache.match(request);
253
+ case 1:
254
+ response = _context5.v;
255
+ if (response) {
256
+ _context5.n = 2;
257
+ break;
258
+ }
259
+ return _context5.a(2);
260
+ case 2:
261
+ cachedTime = parseInt(response.headers.get('X-Cached-Time') || '0');
262
+ age = Date.now() - cachedTime;
263
+ s3Key = request.url.replace('https://local.cache', '');
264
+ expiryMs = CacheManager.cacheManager.getExpiryForPath(s3Key);
265
+ if (!(age > expiryMs)) {
266
+ _context5.n = 4;
267
+ break;
268
+ }
269
+ _context5.n = 3;
270
+ return cache.delete(request);
271
+ case 3:
272
+ cleaned++;
273
+ case 4:
274
+ _context5.n = 6;
275
+ break;
276
+ case 5:
277
+ _context5.p = 5;
278
+ _t9 = _context5.v;
279
+ console.warn('Failed to check global cache entry:', _t9);
280
+ case 6:
281
+ return _context5.a(2);
282
+ }
283
+ }, _callee5, null, [[0, 5]]);
284
+ }));
285
+ return function (_x16) {
286
+ return _ref2.apply(this, arguments);
287
+ };
288
+ }()));
289
+ case 4:
290
+ if (cleaned > 0) console.log("\uD83E\uDDF9 Cleaned ".concat(cleaned, " expired global cache entries"));
291
+ return _context6.a(2, cleaned);
292
+ }
293
+ }, _callee6);
294
+ }));
295
+ return _cleanExpiredGlobalCache.apply(this, arguments);
296
+ }
297
+ function getGlobalCacheStatsDetail() {
298
+ return _getGlobalCacheStatsDetail.apply(this, arguments);
299
+ } // --- Exports delegating to CacheManager ---
300
+ function _getGlobalCacheStatsDetail() {
301
+ _getGlobalCacheStatsDetail = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee8() {
302
+ var cache, keys, items, totalSize;
303
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context8) {
304
+ while (1) switch (_context8.n) {
305
+ case 0:
306
+ _context8.n = 1;
307
+ return getGlobalCache();
308
+ case 1:
309
+ cache = _context8.v;
310
+ if (cache) {
311
+ _context8.n = 2;
312
+ break;
313
+ }
314
+ return _context8.a(2, {
315
+ count: 0,
316
+ totalSize: 0,
317
+ totalSizeMB: '0.00',
318
+ items: []
319
+ });
320
+ case 2:
321
+ _context8.n = 3;
322
+ return cache.keys();
323
+ case 3:
324
+ keys = _context8.v;
325
+ items = [];
326
+ totalSize = 0;
327
+ _context8.n = 4;
328
+ return Promise.all(keys.map(/*#__PURE__*/function () {
329
+ var _ref3 = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee7(request) {
330
+ var response, cachedTime, metadataHeader, metadata, size, cl;
331
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context7) {
332
+ while (1) switch (_context7.n) {
333
+ case 0:
334
+ _context7.n = 1;
335
+ return cache.match(request);
336
+ case 1:
337
+ response = _context7.v;
338
+ if (response) {
339
+ _context7.n = 2;
340
+ break;
341
+ }
342
+ return _context7.a(2);
343
+ case 2:
344
+ cachedTime = parseInt(response.headers.get('X-Cached-Time') || '0');
345
+ metadataHeader = response.headers.get('X-Cache-Metadata');
346
+ metadata = metadataHeader ? JSON.parse(metadataHeader) : {};
347
+ size = 0;
348
+ cl = response.headers.get('Content-Length');
349
+ if (cl) size = parseInt(cl);
350
+ totalSize += size;
351
+ items.push(_rollupPluginBabelHelpers.objectSpread2({
352
+ url: request.url,
353
+ s3Key: request.url.replace('https://local.cache', ''),
354
+ size: size,
355
+ sizeMB: (size / (1024 * 1024)).toFixed(2),
356
+ cachedTime: cachedTime,
357
+ age: Date.now() - cachedTime,
358
+ isLocal: true,
359
+ type: response.headers.get('Content-Type') || 'application/octet-stream'
360
+ }, metadata));
361
+ case 3:
362
+ return _context7.a(2);
363
+ }
364
+ }, _callee7);
365
+ }));
366
+ return function (_x17) {
367
+ return _ref3.apply(this, arguments);
368
+ };
369
+ }()));
370
+ case 4:
371
+ return _context8.a(2, {
372
+ count: items.length,
373
+ totalSize: totalSize,
374
+ totalSizeMB: (totalSize / (1024 * 1024)).toFixed(2),
375
+ items: items
376
+ });
377
+ }
378
+ }, _callee8);
379
+ }));
380
+ return _getGlobalCacheStatsDetail.apply(this, arguments);
381
+ }
382
+ function getGlobalCacheStats() {
383
+ return CacheManager.cacheManager.getGlobalStats();
384
+ }
385
+ function resetGlobalCacheStats() {
386
+ CacheManager.cacheManager.resetStats();
387
+ }
388
+ function getCurrentCacheName() {
389
+ return _getCurrentCacheName.apply(this, arguments);
390
+ }
391
+ function _getCurrentCacheName() {
392
+ _getCurrentCacheName = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee9() {
393
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context9) {
394
+ while (1) switch (_context9.n) {
395
+ case 0:
396
+ return _context9.a(2, CacheManager.cacheManager.getCacheName());
397
+ }
398
+ }, _callee9);
399
+ }));
400
+ return _getCurrentCacheName.apply(this, arguments);
401
+ }
402
+ function cleanExpiredCache() {
403
+ return _cleanExpiredCache.apply(this, arguments);
404
+ }
405
+ function _cleanExpiredCache() {
406
+ _cleanExpiredCache = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee0() {
407
+ var userCount, globalCount, count;
408
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context0) {
409
+ while (1) switch (_context0.n) {
410
+ case 0:
411
+ _context0.n = 1;
412
+ return CacheManager.cacheManager.cleanExpired();
413
+ case 1:
414
+ userCount = _context0.v;
415
+ _context0.n = 2;
416
+ return cleanExpiredGlobalCache();
417
+ case 2:
418
+ globalCount = _context0.v;
419
+ count = userCount + globalCount;
420
+ if (count > 0) console.log("\uD83E\uDDF9 Cleaned ".concat(count, " expired cache entries (user: ").concat(userCount, ", global: ").concat(globalCount, ")"));
421
+ return _context0.a(2, count);
422
+ }
423
+ }, _callee0);
424
+ }));
425
+ return _cleanExpiredCache.apply(this, arguments);
426
+ }
427
+ function cleanInvalidCacheEntries() {
428
+ return _cleanInvalidCacheEntries.apply(this, arguments);
429
+ }
430
+ function _cleanInvalidCacheEntries() {
431
+ _cleanInvalidCacheEntries = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee1() {
432
+ var count;
433
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context1) {
434
+ while (1) switch (_context1.n) {
435
+ case 0:
436
+ _context1.n = 1;
437
+ return CacheManager.cacheManager.cleanInvalid();
438
+ case 1:
439
+ count = _context1.v;
440
+ if (count > 0) console.log("\uD83E\uDDF9 Cleaned ".concat(count, " invalid cache entries"));
441
+ return _context1.a(2, count);
442
+ }
443
+ }, _callee1);
444
+ }));
445
+ return _cleanInvalidCacheEntries.apply(this, arguments);
446
+ }
447
+ function getCacheStats() {
448
+ return _getCacheStats.apply(this, arguments);
449
+ }
450
+ function _getCacheStats() {
451
+ _getCacheStats = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee10() {
452
+ var allUsers,
453
+ userStats,
454
+ globalStats,
455
+ userItems,
456
+ _args10 = arguments;
457
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context10) {
458
+ while (1) switch (_context10.n) {
459
+ case 0:
460
+ allUsers = _args10.length > 0 && _args10[0] !== undefined ? _args10[0] : false;
461
+ _context10.n = 1;
462
+ return CacheManager.cacheManager.getDetailedStats(allUsers);
463
+ case 1:
464
+ userStats = _context10.v;
465
+ _context10.n = 2;
466
+ return getGlobalCacheStatsDetail();
467
+ case 2:
468
+ globalStats = _context10.v;
469
+ // Ensure user stats items have isLocal: false
470
+ userItems = userStats.items.map(function (item) {
471
+ return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, item), {}, {
472
+ isLocal: false
473
+ });
474
+ }); // Merge stats
475
+ return _context10.a(2, {
476
+ count: userStats.count + globalStats.count,
477
+ totalSize: userStats.totalSize + globalStats.totalSize,
478
+ totalSizeMB: (parseFloat(userStats.totalSizeMB) + parseFloat(globalStats.totalSizeMB)).toFixed(2),
479
+ items: [].concat(_rollupPluginBabelHelpers.toConsumableArray(userItems), _rollupPluginBabelHelpers.toConsumableArray(globalStats.items))
480
+ });
481
+ }
482
+ }, _callee10);
483
+ }));
484
+ return _getCacheStats.apply(this, arguments);
485
+ }
486
+ function getUserOnlyCacheStats() {
487
+ return _getUserOnlyCacheStats.apply(this, arguments);
488
+ }
489
+ function _getUserOnlyCacheStats() {
490
+ _getUserOnlyCacheStats = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee11() {
491
+ var allUsers,
492
+ stats,
493
+ _args11 = arguments;
494
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context11) {
495
+ while (1) switch (_context11.n) {
496
+ case 0:
497
+ allUsers = _args11.length > 0 && _args11[0] !== undefined ? _args11[0] : false;
498
+ _context11.n = 1;
499
+ return CacheManager.cacheManager.getDetailedStats(allUsers);
500
+ case 1:
501
+ stats = _context11.v;
502
+ // Ensure items have isLocal: false
503
+ stats.items = stats.items.map(function (item) {
504
+ return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, item), {}, {
505
+ isLocal: false
506
+ });
507
+ });
508
+ return _context11.a(2, stats);
509
+ }
510
+ }, _callee11);
511
+ }));
512
+ return _getUserOnlyCacheStats.apply(this, arguments);
513
+ }
514
+ function getGlobalOnlyCacheStats() {
515
+ return _getGlobalOnlyCacheStats.apply(this, arguments);
516
+ }
517
+ function _getGlobalOnlyCacheStats() {
518
+ _getGlobalOnlyCacheStats = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee12() {
519
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context12) {
520
+ while (1) switch (_context12.n) {
521
+ case 0:
522
+ _context12.n = 1;
523
+ return getGlobalCacheStatsDetail();
524
+ case 1:
525
+ return _context12.a(2, _context12.v);
526
+ }
527
+ }, _callee12);
528
+ }));
529
+ return _getGlobalOnlyCacheStats.apply(this, arguments);
530
+ }
531
+ function clearS3Cache() {
532
+ return _clearS3Cache.apply(this, arguments);
533
+ }
534
+ function _clearS3Cache() {
535
+ _clearS3Cache = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee13() {
536
+ var specificKey,
537
+ clearAllUsers,
538
+ result,
539
+ _args13 = arguments;
540
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context13) {
541
+ while (1) switch (_context13.n) {
542
+ case 0:
543
+ specificKey = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : null;
544
+ clearAllUsers = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : false;
545
+ _context13.n = 1;
546
+ return CacheManager.cacheManager.clearCache(specificKey, clearAllUsers);
547
+ case 1:
548
+ result = _context13.v;
549
+ if (specificKey) {
550
+ _context13.n = 2;
551
+ break;
552
+ }
553
+ _context13.n = 2;
554
+ return clearGlobalCache();
555
+ case 2:
556
+ if (result) console.log(specificKey ? "\uD83D\uDDD1\uFE0F Cleared cache for ".concat(specificKey) : "\uD83D\uDDD1\uFE0F Cache cleared (user + global)");
557
+ return _context13.a(2, result);
558
+ }
559
+ }, _callee13);
560
+ }));
561
+ return _clearS3Cache.apply(this, arguments);
562
+ }
563
+ function getAllCacheKeys() {
564
+ return _getAllCacheKeys.apply(this, arguments);
565
+ }
566
+ function _getAllCacheKeys() {
567
+ _getAllCacheKeys = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee14() {
568
+ var allKeys, addKey, globalCache, keys, allCacheNames, appCaches, _iterator, _step, cacheName, cache, _keys, _t0;
569
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context14) {
570
+ while (1) switch (_context14.n) {
571
+ case 0:
572
+ allKeys = new Set(); // Helper to add both raw and decoded versions for robust matching
573
+ addKey = function addKey(url) {
574
+ allKeys.add(url);
575
+ try {
576
+ var decoded = decodeURI(url);
577
+ if (decoded !== url) allKeys.add(decoded);
578
+ } catch (e) {
579
+ // Ignore encoding errors
580
+ }
581
+ }; // 1. Get Global Cache Keys (Custom Global Cache)
582
+ _context14.n = 1;
583
+ return getGlobalCache();
584
+ case 1:
585
+ globalCache = _context14.v;
586
+ if (!globalCache) {
587
+ _context14.n = 3;
588
+ break;
589
+ }
590
+ _context14.n = 2;
591
+ return globalCache.keys();
592
+ case 2:
593
+ keys = _context14.v;
594
+ keys.forEach(function (request) {
595
+ return addKey(request.url);
596
+ });
597
+ case 3:
598
+ if (!('caches' in window)) {
599
+ _context14.n = 13;
600
+ break;
601
+ }
602
+ _context14.n = 4;
603
+ return caches.keys();
604
+ case 4:
605
+ allCacheNames = _context14.v;
606
+ appCaches = allCacheNames.filter(function (name) {
607
+ return name.startsWith(CacheManager.CACHE_NAME_PREFIX);
608
+ });
609
+ _iterator = _rollupPluginBabelHelpers.createForOfIteratorHelper(appCaches);
610
+ _context14.p = 5;
611
+ _iterator.s();
612
+ case 6:
613
+ if ((_step = _iterator.n()).done) {
614
+ _context14.n = 10;
615
+ break;
616
+ }
617
+ cacheName = _step.value;
618
+ _context14.n = 7;
619
+ return caches.open(cacheName);
620
+ case 7:
621
+ cache = _context14.v;
622
+ if (!cache) {
623
+ _context14.n = 9;
624
+ break;
625
+ }
626
+ _context14.n = 8;
627
+ return cache.keys();
628
+ case 8:
629
+ _keys = _context14.v;
630
+ _keys.forEach(function (request) {
631
+ return addKey(request.url);
632
+ });
633
+ case 9:
634
+ _context14.n = 6;
635
+ break;
636
+ case 10:
637
+ _context14.n = 12;
638
+ break;
639
+ case 11:
640
+ _context14.p = 11;
641
+ _t0 = _context14.v;
642
+ _iterator.e(_t0);
643
+ case 12:
644
+ _context14.p = 12;
645
+ _iterator.f();
646
+ return _context14.f(12);
647
+ case 13:
648
+ return _context14.a(2, allKeys);
649
+ }
650
+ }, _callee14, null, [[5, 11, 12, 13]]);
651
+ }));
652
+ return _getAllCacheKeys.apply(this, arguments);
653
+ }
654
+ function switchCachePartition(_x2) {
655
+ return _switchCachePartition.apply(this, arguments);
656
+ }
657
+
658
+ // --- Data Fetchers ---
659
+
660
+ /**
661
+ * Check all app cache partitions for a cached response.
662
+ * This handles the race condition where auth may not be hydrated yet on page refresh.
663
+ * @param {string} cacheKey - The cache key to look for
664
+ * @returns {Promise<Response|null>} - Cached response or null if not found
665
+ */
666
+ function _switchCachePartition() {
667
+ _switchCachePartition = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee15(isAuthenticated) {
668
+ var oldCacheName, partitionToDelete, deleted, newCacheName, _t1, _t10;
669
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context15) {
670
+ while (1) switch (_context15.n) {
671
+ case 0:
672
+ _context15.p = 0;
673
+ console.log("\uD83D\uDD04 Switching cache partition (authenticated: ".concat(isAuthenticated, ")..."));
674
+ _context15.n = 1;
675
+ return CacheManager.cacheManager.getCacheName();
676
+ case 1:
677
+ oldCacheName = _context15.v;
678
+ // Reset identity to force re-evaluation of cache name
679
+ CacheManager.cacheManager.resetIdentity();
680
+ partitionToDelete = null;
681
+ if (isAuthenticated) {
682
+ // User logged in - delete anonymous cache
683
+ partitionToDelete = "".concat(CacheManager.CACHE_NAME_PREFIX, "-anonymous");
684
+ } else {
685
+ // User logged out - delete their user-specific cache
686
+ partitionToDelete = oldCacheName;
687
+ }
688
+ if (!partitionToDelete) {
689
+ _context15.n = 3;
690
+ break;
691
+ }
692
+ _context15.n = 2;
693
+ return CacheManager.cacheManager.deleteCache(partitionToDelete);
694
+ case 2:
695
+ _t1 = _context15.v;
696
+ _context15.n = 4;
697
+ break;
698
+ case 3:
699
+ _t1 = false;
700
+ case 4:
701
+ deleted = _t1;
702
+ _context15.n = 5;
703
+ return CacheManager.cacheManager.getCacheName();
704
+ case 5:
705
+ newCacheName = _context15.v;
706
+ console.log("\u2705 Cache partition switched:", {
707
+ from: oldCacheName,
708
+ to: newCacheName,
709
+ deleted: partitionToDelete
710
+ });
711
+ return _context15.a(2, {
712
+ oldCacheName: oldCacheName,
713
+ newCacheName: newCacheName,
714
+ deletedPartition: partitionToDelete,
715
+ deleted: deleted
716
+ });
717
+ case 6:
718
+ _context15.p = 6;
719
+ _t10 = _context15.v;
720
+ console.error('Failed to switch cache partition:', _t10);
721
+ return _context15.a(2, {
722
+ error: _t10.message
723
+ });
724
+ }
725
+ }, _callee15, null, [[0, 6]]);
726
+ }));
727
+ return _switchCachePartition.apply(this, arguments);
728
+ }
729
+ function findInAllCachePartitions(_x3) {
730
+ return _findInAllCachePartitions.apply(this, arguments);
731
+ }
732
+ function _findInAllCachePartitions() {
733
+ _findInAllCachePartitions = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee16(cacheKey) {
734
+ var allCacheNames, appCaches, encodedCacheKey, _iterator2, _step2, cacheName, cache, response, _t11;
735
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context16) {
736
+ while (1) switch (_context16.n) {
737
+ case 0:
738
+ if ('caches' in window) {
739
+ _context16.n = 1;
740
+ break;
741
+ }
742
+ return _context16.a(2, null);
743
+ case 1:
744
+ _context16.n = 2;
745
+ return caches.keys();
746
+ case 2:
747
+ allCacheNames = _context16.v;
748
+ appCaches = allCacheNames.filter(function (name) {
749
+ return name.startsWith(CacheManager.CACHE_NAME_PREFIX);
750
+ }); // Also try URL-encoded version of the key in case spaces/special chars were encoded
751
+ encodedCacheKey = encodeURI(cacheKey);
752
+ _iterator2 = _rollupPluginBabelHelpers.createForOfIteratorHelper(appCaches);
753
+ _context16.p = 3;
754
+ _iterator2.s();
755
+ case 4:
756
+ if ((_step2 = _iterator2.n()).done) {
757
+ _context16.n = 10;
758
+ break;
759
+ }
760
+ cacheName = _step2.value;
761
+ _context16.n = 5;
762
+ return caches.open(cacheName);
763
+ case 5:
764
+ cache = _context16.v;
765
+ _context16.n = 6;
766
+ return cache.match(cacheKey);
767
+ case 6:
768
+ response = _context16.v;
769
+ if (!response) {
770
+ _context16.n = 7;
771
+ break;
772
+ }
773
+ console.log("\u2705 [findInAllCachePartitions] Found in ".concat(cacheName, " (exact match): ").concat(cacheKey.substring(0, 80), "..."));
774
+ return _context16.a(2, response);
775
+ case 7:
776
+ if (!(encodedCacheKey !== cacheKey)) {
777
+ _context16.n = 9;
778
+ break;
779
+ }
780
+ _context16.n = 8;
781
+ return cache.match(encodedCacheKey);
782
+ case 8:
783
+ response = _context16.v;
784
+ if (!response) {
785
+ _context16.n = 9;
786
+ break;
787
+ }
788
+ console.log("\u2705 [findInAllCachePartitions] Found in ".concat(cacheName, " (encoded match): ").concat(encodedCacheKey.substring(0, 80), "..."));
789
+ return _context16.a(2, response);
790
+ case 9:
791
+ _context16.n = 4;
792
+ break;
793
+ case 10:
794
+ _context16.n = 12;
795
+ break;
796
+ case 11:
797
+ _context16.p = 11;
798
+ _t11 = _context16.v;
799
+ _iterator2.e(_t11);
800
+ case 12:
801
+ _context16.p = 12;
802
+ _iterator2.f();
803
+ return _context16.f(12);
804
+ case 13:
805
+ return _context16.a(2, null);
806
+ }
807
+ }, _callee16, null, [[3, 11, 12, 13]]);
808
+ }));
809
+ return _findInAllCachePartitions.apply(this, arguments);
810
+ }
811
+ function getCachedS3Object(_x4) {
812
+ return _getCachedS3Object.apply(this, arguments);
813
+ }
814
+ function _getCachedS3Object() {
815
+ _getCachedS3Object = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee19(s3Key) {
816
+ var storageOptions,
817
+ expiryMs,
818
+ cacheKey,
819
+ expiry,
820
+ cachedResponse,
821
+ cachedTime,
822
+ age,
823
+ _allKeys,
824
+ matchingKeys,
825
+ _args19 = arguments;
826
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context19) {
827
+ while (1) switch (_context19.n) {
828
+ case 0:
829
+ storageOptions = _args19.length > 1 && _args19[1] !== undefined ? _args19[1] : {};
830
+ expiryMs = _args19.length > 2 && _args19[2] !== undefined ? _args19[2] : null;
831
+ cacheKey = "https://s3.cache/".concat(s3Key);
832
+ expiry = expiryMs || CacheManager.cacheManager.getExpiryForPath(s3Key);
833
+ console.log("\uD83D\uDD0D [S3Cache] Checking for cached S3 object:", {
834
+ s3Key: s3Key,
835
+ cacheKey: cacheKey
836
+ });
837
+
838
+ // First, check ALL app cache partitions for a hit (handles auth race condition)
839
+ _context19.n = 1;
840
+ return findInAllCachePartitions(cacheKey);
841
+ case 1:
842
+ cachedResponse = _context19.v;
843
+ if (!cachedResponse) {
844
+ _context19.n = 4;
845
+ break;
846
+ }
847
+ cachedTime = cachedResponse.headers.get('x-cached-time');
848
+ age = Date.now() - parseInt(cachedTime || '0');
849
+ console.log("\u2705 [S3Cache] Found in cache partition, age: ".concat(Math.round(age / 1000), "s, expiry: ").concat(Math.round(expiry / 1000), "s"));
850
+ if (!(age < expiry)) {
851
+ _context19.n = 3;
852
+ break;
853
+ }
854
+ console.log("\u2705 [S3Cache] Returning cached blob for: ".concat(s3Key));
855
+ _context19.n = 2;
856
+ return cachedResponse.blob();
857
+ case 2:
858
+ return _context19.a(2, _context19.v);
859
+ case 3:
860
+ console.log("\u23F0 [S3Cache] Cache entry expired, will re-fetch");
861
+ _context19.n = 6;
862
+ break;
863
+ case 4:
864
+ console.log("\u274C [S3Cache] Not found in any cache partition");
865
+ _context19.n = 5;
866
+ return getAllCacheKeys();
867
+ case 5:
868
+ _allKeys = _context19.v;
869
+ matchingKeys = _rollupPluginBabelHelpers.toConsumableArray(_allKeys).filter(function (k) {
870
+ return k.includes('24dd6a7a') || k.includes('.glb');
871
+ });
872
+ if (matchingKeys.length > 0) {
873
+ console.log("\uD83D\uDD0D [S3Cache] Available GLB cache keys:", matchingKeys.slice(0, 5));
874
+ }
875
+ case 6:
876
+ return _context19.a(2, CacheManager.cacheManager.execute({
877
+ cacheKey: cacheKey,
878
+ sourceKey: s3Key,
879
+ expiryMs: expiry,
880
+ fetcher: function () {
881
+ var _fetcher = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee17() {
882
+ var Storage, Auth, result, _result, _t12;
883
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context17) {
884
+ while (1) switch (_context17.n) {
885
+ case 0:
886
+ _context17.n = 1;
887
+ return requireAuthentication();
888
+ case 1:
889
+ Storage = getStorage();
890
+ Auth = getAuth();
891
+ _context17.p = 2;
892
+ _context17.n = 3;
893
+ return Storage.get(s3Key, _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, storageOptions), {}, {
894
+ download: true
895
+ }));
896
+ case 3:
897
+ result = _context17.v;
898
+ return _context17.a(2, result.Body);
899
+ case 4:
900
+ _context17.p = 4;
901
+ _t12 = _context17.v;
902
+ if (!(_t12.code === 'ExpiredToken' || _t12.message && _t12.message.includes('ExpiredToken'))) {
903
+ _context17.n = 7;
904
+ break;
905
+ }
906
+ console.warn("\u26A0\uFE0F Token expired fetching S3 object. Refreshing credentials and retrying...");
907
+ _context17.n = 5;
908
+ return Auth.currentCredentials({
909
+ bypassCache: true
910
+ });
911
+ case 5:
912
+ _context17.n = 6;
913
+ return Storage.get(s3Key, _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, storageOptions), {}, {
914
+ download: true
915
+ }));
916
+ case 6:
917
+ _result = _context17.v;
918
+ return _context17.a(2, _result.Body);
919
+ case 7:
920
+ throw _t12;
921
+ case 8:
922
+ return _context17.a(2);
923
+ }
924
+ }, _callee17, null, [[2, 4]]);
925
+ }));
926
+ function fetcher() {
927
+ return _fetcher.apply(this, arguments);
928
+ }
929
+ return fetcher;
930
+ }(),
931
+ processor: function () {
932
+ var _processor = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee18(res) {
933
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context18) {
934
+ while (1) switch (_context18.n) {
935
+ case 0:
936
+ if (!(res instanceof Response)) {
937
+ _context18.n = 2;
938
+ break;
939
+ }
940
+ _context18.n = 1;
941
+ return res.blob();
942
+ case 1:
943
+ return _context18.a(2, _context18.v);
944
+ case 2:
945
+ return _context18.a(2, res);
946
+ }
947
+ }, _callee18);
948
+ }));
949
+ function processor(_x18) {
950
+ return _processor.apply(this, arguments);
951
+ }
952
+ return processor;
953
+ }(),
954
+ logType: 'S3 Object'
955
+ }));
956
+ }
957
+ }, _callee19);
958
+ }));
959
+ return _getCachedS3Object.apply(this, arguments);
960
+ }
961
+ function getCachedS3ObjectURL(_x5) {
962
+ return _getCachedS3ObjectURL.apply(this, arguments);
963
+ }
964
+ function _getCachedS3ObjectURL() {
965
+ _getCachedS3ObjectURL = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee20(s3Key) {
966
+ var storageOptions,
967
+ expiryMs,
968
+ blob,
969
+ _args20 = arguments;
970
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context20) {
971
+ while (1) switch (_context20.n) {
972
+ case 0:
973
+ storageOptions = _args20.length > 1 && _args20[1] !== undefined ? _args20[1] : {};
974
+ expiryMs = _args20.length > 2 && _args20[2] !== undefined ? _args20[2] : null;
975
+ _context20.n = 1;
976
+ return getCachedS3Object(s3Key, storageOptions, expiryMs);
977
+ case 1:
978
+ blob = _context20.v;
979
+ return _context20.a(2, URL.createObjectURL(blob));
980
+ }
981
+ }, _callee20);
982
+ }));
983
+ return _getCachedS3ObjectURL.apply(this, arguments);
984
+ }
985
+ function preloadS3Objects(_x6) {
986
+ return _preloadS3Objects.apply(this, arguments);
987
+ }
988
+ function _preloadS3Objects() {
989
+ _preloadS3Objects = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee22(s3Keys) {
990
+ var storageOptions,
991
+ results,
992
+ _args22 = arguments;
993
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context22) {
994
+ while (1) switch (_context22.n) {
995
+ case 0:
996
+ storageOptions = _args22.length > 1 && _args22[1] !== undefined ? _args22[1] : {};
997
+ results = {
998
+ success: 0,
999
+ failed: 0,
1000
+ errors: []
1001
+ };
1002
+ _context22.n = 1;
1003
+ return Promise.all(s3Keys.map(/*#__PURE__*/function () {
1004
+ var _ref4 = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee21(key) {
1005
+ var _t13;
1006
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context21) {
1007
+ while (1) switch (_context21.n) {
1008
+ case 0:
1009
+ _context21.p = 0;
1010
+ _context21.n = 1;
1011
+ return getCachedS3Object(key, storageOptions);
1012
+ case 1:
1013
+ results.success++;
1014
+ _context21.n = 3;
1015
+ break;
1016
+ case 2:
1017
+ _context21.p = 2;
1018
+ _t13 = _context21.v;
1019
+ results.failed++;
1020
+ results.errors.push({
1021
+ key: key,
1022
+ error: _t13.message
1023
+ });
1024
+ case 3:
1025
+ return _context21.a(2);
1026
+ }
1027
+ }, _callee21, null, [[0, 2]]);
1028
+ }));
1029
+ return function (_x19) {
1030
+ return _ref4.apply(this, arguments);
1031
+ };
1032
+ }()));
1033
+ case 1:
1034
+ console.log("\u2705 Preload complete: ".concat(results.success, " success, ").concat(results.failed, " failed"));
1035
+ return _context22.a(2, results);
1036
+ }
1037
+ }, _callee22);
1038
+ }));
1039
+ return _preloadS3Objects.apply(this, arguments);
1040
+ }
1041
+ function getCachedS3Json(_x7) {
1042
+ return _getCachedS3Json.apply(this, arguments);
1043
+ }
1044
+ function _getCachedS3Json() {
1045
+ _getCachedS3Json = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee24(s3Key) {
1046
+ var storageOptions,
1047
+ expiryMs,
1048
+ _args24 = arguments;
1049
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context24) {
1050
+ while (1) switch (_context24.n) {
1051
+ case 0:
1052
+ storageOptions = _args24.length > 1 && _args24[1] !== undefined ? _args24[1] : {};
1053
+ expiryMs = _args24.length > 2 && _args24[2] !== undefined ? _args24[2] : null;
1054
+ return _context24.a(2, CacheManager.cacheManager.execute({
1055
+ cacheKey: "https://s3.cache/".concat(s3Key),
1056
+ sourceKey: s3Key,
1057
+ expiryMs: expiryMs || CacheManager.cacheManager.getExpiryForPath(s3Key),
1058
+ fetcher: function () {
1059
+ var _fetcher2 = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee23() {
1060
+ var Storage, Auth, signedUrl, _signedUrl, _t14;
1061
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context23) {
1062
+ while (1) switch (_context23.n) {
1063
+ case 0:
1064
+ _context23.n = 1;
1065
+ return requireAuthentication();
1066
+ case 1:
1067
+ Storage = getStorage();
1068
+ Auth = getAuth();
1069
+ _context23.p = 2;
1070
+ _context23.n = 3;
1071
+ return Storage.get(s3Key, _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, storageOptions), {}, {
1072
+ customPrefix: {
1073
+ public: ''
1074
+ }
1075
+ }));
1076
+ case 3:
1077
+ signedUrl = _context23.v;
1078
+ return _context23.a(2, fetch(signedUrl));
1079
+ case 4:
1080
+ _context23.p = 4;
1081
+ _t14 = _context23.v;
1082
+ if (!(_t14.code === 'ExpiredToken' || _t14.message && _t14.message.includes('ExpiredToken'))) {
1083
+ _context23.n = 7;
1084
+ break;
1085
+ }
1086
+ console.warn("\u26A0\uFE0F Token expired fetching S3 JSON. Refreshing credentials and retrying...");
1087
+ _context23.n = 5;
1088
+ return Auth.currentCredentials({
1089
+ bypassCache: true
1090
+ });
1091
+ case 5:
1092
+ _context23.n = 6;
1093
+ return Storage.get(s3Key, _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, storageOptions), {}, {
1094
+ customPrefix: {
1095
+ public: ''
1096
+ }
1097
+ }));
1098
+ case 6:
1099
+ _signedUrl = _context23.v;
1100
+ return _context23.a(2, fetch(_signedUrl));
1101
+ case 7:
1102
+ throw _t14;
1103
+ case 8:
1104
+ return _context23.a(2);
1105
+ }
1106
+ }, _callee23, null, [[2, 4]]);
1107
+ }));
1108
+ function fetcher() {
1109
+ return _fetcher2.apply(this, arguments);
1110
+ }
1111
+ return fetcher;
1112
+ }(),
1113
+ processor: function processor(res) {
1114
+ return res.json();
1115
+ },
1116
+ logType: 'S3 JSON'
1117
+ }));
1118
+ }
1119
+ }, _callee24);
1120
+ }));
1121
+ return _getCachedS3Json.apply(this, arguments);
1122
+ }
1123
+ function getCachedLocalJson(_x8) {
1124
+ return _getCachedLocalJson.apply(this, arguments);
1125
+ }
1126
+ function _getCachedLocalJson() {
1127
+ _getCachedLocalJson = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee25(localPath) {
1128
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context25) {
1129
+ while (1) switch (_context25.n) {
1130
+ case 0:
1131
+ return _context25.a(2, executeGlobal({
1132
+ cacheKey: "https://local.cache".concat(localPath),
1133
+ fetcher: function fetcher() {
1134
+ return fetch(localPath);
1135
+ },
1136
+ processor: function processor(res) {
1137
+ return res.json();
1138
+ },
1139
+ metadata: {
1140
+ 'x-local-path': localPath
1141
+ }
1142
+ }));
1143
+ }
1144
+ }, _callee25);
1145
+ }));
1146
+ return _getCachedLocalJson.apply(this, arguments);
1147
+ }
1148
+ function getCachedLocalFile(_x9) {
1149
+ return _getCachedLocalFile.apply(this, arguments);
1150
+ }
1151
+ function _getCachedLocalFile() {
1152
+ _getCachedLocalFile = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee26(url) {
1153
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context26) {
1154
+ while (1) switch (_context26.n) {
1155
+ case 0:
1156
+ if (!(!url || url.includes('undefined') || url.includes('null'))) {
1157
+ _context26.n = 1;
1158
+ break;
1159
+ }
1160
+ throw new Error("Invalid URL: ".concat(url));
1161
+ case 1:
1162
+ return _context26.a(2, executeGlobal({
1163
+ cacheKey: "https://local.cache".concat(url),
1164
+ fetcher: function fetcher() {
1165
+ return fetch(url);
1166
+ },
1167
+ processor: function processor(res) {
1168
+ return res.blob();
1169
+ },
1170
+ metadata: {
1171
+ 'x-local-path': url
1172
+ }
1173
+ }));
1174
+ }
1175
+ }, _callee26);
1176
+ }));
1177
+ return _getCachedLocalFile.apply(this, arguments);
1178
+ }
1179
+ function getCachedLocalFileURL(_x0) {
1180
+ return _getCachedLocalFileURL.apply(this, arguments);
1181
+ }
1182
+ function _getCachedLocalFileURL() {
1183
+ _getCachedLocalFileURL = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee27(url) {
1184
+ var expiryMs,
1185
+ blob,
1186
+ _args27 = arguments;
1187
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context27) {
1188
+ while (1) switch (_context27.n) {
1189
+ case 0:
1190
+ expiryMs = _args27.length > 1 && _args27[1] !== undefined ? _args27[1] : null;
1191
+ _context27.n = 1;
1192
+ return getCachedLocalFile(url, expiryMs);
1193
+ case 1:
1194
+ blob = _context27.v;
1195
+ return _context27.a(2, URL.createObjectURL(blob));
1196
+ }
1197
+ }, _callee27);
1198
+ }));
1199
+ return _getCachedLocalFileURL.apply(this, arguments);
1200
+ }
1201
+ function preloadLocalFiles(_x1) {
1202
+ return _preloadLocalFiles.apply(this, arguments);
1203
+ }
1204
+
1205
+ // --- Arbitrary JSON Helpers ---
1206
+ function _preloadLocalFiles() {
1207
+ _preloadLocalFiles = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee29(urls) {
1208
+ var results;
1209
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context29) {
1210
+ while (1) switch (_context29.n) {
1211
+ case 0:
1212
+ console.log("preloadLocalFiles started");
1213
+ results = {
1214
+ success: 0,
1215
+ failed: 0,
1216
+ errors: []
1217
+ };
1218
+ _context29.n = 1;
1219
+ return Promise.all(urls.map(/*#__PURE__*/function () {
1220
+ var _ref5 = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee28(url) {
1221
+ var _t15;
1222
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context28) {
1223
+ while (1) switch (_context28.n) {
1224
+ case 0:
1225
+ _context28.p = 0;
1226
+ _context28.n = 1;
1227
+ return getCachedLocalFile(url);
1228
+ case 1:
1229
+ results.success++;
1230
+ _context28.n = 3;
1231
+ break;
1232
+ case 2:
1233
+ _context28.p = 2;
1234
+ _t15 = _context28.v;
1235
+ console.error("\u274C preloadLocalFiles Preload failed for ".concat(url, ":"), _t15);
1236
+ results.failed++;
1237
+ results.errors.push({
1238
+ url: url,
1239
+ error: _t15.message
1240
+ });
1241
+ case 3:
1242
+ return _context28.a(2);
1243
+ }
1244
+ }, _callee28, null, [[0, 2]]);
1245
+ }));
1246
+ return function (_x20) {
1247
+ return _ref5.apply(this, arguments);
1248
+ };
1249
+ }()));
1250
+ case 1:
1251
+ console.log("preloadLocalFiles finished");
1252
+ if (results.failed > 0) {
1253
+ console.warn("\u26A0\uFE0F preloadLocalFiles Cache priming finished with errors: ".concat(results.failed, " failed"), results.errors);
1254
+ }
1255
+ return _context29.a(2, results);
1256
+ }
1257
+ }, _callee29);
1258
+ }));
1259
+ return _preloadLocalFiles.apply(this, arguments);
1260
+ }
1261
+ function cacheJsonData(_x10, _x11) {
1262
+ return _cacheJsonData.apply(this, arguments);
1263
+ }
1264
+ function _cacheJsonData() {
1265
+ _cacheJsonData = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee32(key, data) {
1266
+ var expiryMs,
1267
+ cacheKey,
1268
+ _args32 = arguments;
1269
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context32) {
1270
+ while (1) switch (_context32.n) {
1271
+ case 0:
1272
+ expiryMs = _args32.length > 2 && _args32[2] !== undefined ? _args32[2] : CacheManager.CACHE_EXPIRY.JSON;
1273
+ cacheKey = "https://json.cache/".concat(key); // Delete existing entry first to ensure we overwrite with new data
1274
+ _context32.n = 1;
1275
+ return CacheManager.cacheManager.delete(cacheKey);
1276
+ case 1:
1277
+ return _context32.a(2, CacheManager.cacheManager.execute({
1278
+ cacheKey: cacheKey,
1279
+ sourceKey: key,
1280
+ expiryMs: expiryMs,
1281
+ fetcher: function () {
1282
+ var _fetcher3 = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee30() {
1283
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context30) {
1284
+ while (1) switch (_context30.n) {
1285
+ case 0:
1286
+ return _context30.a(2, new Response(JSON.stringify(data), {
1287
+ headers: {
1288
+ 'Content-Type': 'application/json'
1289
+ }
1290
+ }));
1291
+ }
1292
+ }, _callee30);
1293
+ }));
1294
+ function fetcher() {
1295
+ return _fetcher3.apply(this, arguments);
1296
+ }
1297
+ return fetcher;
1298
+ }(),
1299
+ processor: function () {
1300
+ var _processor2 = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee31(res) {
1301
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context31) {
1302
+ while (1) switch (_context31.n) {
1303
+ case 0:
1304
+ return _context31.a(2, data);
1305
+ }
1306
+ }, _callee31);
1307
+ }));
1308
+ function processor(_x21) {
1309
+ return _processor2.apply(this, arguments);
1310
+ }
1311
+ return processor;
1312
+ }(),
1313
+ // Return the original data to the caller
1314
+ logType: 'Arbitrary JSON'
1315
+ }).then(function () {
1316
+ return true;
1317
+ }).catch(function (e) {
1318
+ console.error("Failed to cache JSON data ".concat(key, ":"), e);
1319
+ return false;
1320
+ }));
1321
+ }
1322
+ }, _callee32);
1323
+ }));
1324
+ return _cacheJsonData.apply(this, arguments);
1325
+ }
1326
+ function getCachedJsonData(_x12) {
1327
+ return _getCachedJsonData.apply(this, arguments);
1328
+ }
1329
+ function _getCachedJsonData() {
1330
+ _getCachedJsonData = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee34(key) {
1331
+ var expiryMs,
1332
+ _args34 = arguments;
1333
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context34) {
1334
+ while (1) switch (_context34.n) {
1335
+ case 0:
1336
+ expiryMs = _args34.length > 1 && _args34[1] !== undefined ? _args34[1] : CacheManager.CACHE_EXPIRY.JSON;
1337
+ return _context34.a(2, CacheManager.cacheManager.get("https://json.cache/".concat(key), expiryMs, /*#__PURE__*/function () {
1338
+ var _ref6 = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee33(r) {
1339
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context33) {
1340
+ while (1) switch (_context33.n) {
1341
+ case 0:
1342
+ return _context33.a(2, r.json());
1343
+ }
1344
+ }, _callee33);
1345
+ }));
1346
+ return function (_x22) {
1347
+ return _ref6.apply(this, arguments);
1348
+ };
1349
+ }()));
1350
+ }
1351
+ }, _callee34);
1352
+ }));
1353
+ return _getCachedJsonData.apply(this, arguments);
1354
+ }
1355
+ function removeCachedJsonData(_x13) {
1356
+ return _removeCachedJsonData.apply(this, arguments);
1357
+ }
1358
+
1359
+ // --- Thumbnails ---
1360
+ function _removeCachedJsonData() {
1361
+ _removeCachedJsonData = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee35(key) {
1362
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context35) {
1363
+ while (1) switch (_context35.n) {
1364
+ case 0:
1365
+ return _context35.a(2, CacheManager.cacheManager.delete("https://json.cache/".concat(key)));
1366
+ }
1367
+ }, _callee35);
1368
+ }));
1369
+ return _removeCachedJsonData.apply(this, arguments);
1370
+ }
1371
+ function getThumbnailKey(asset) {
1372
+ var thumbnailKey = asset.thumbnailS3Path;
1373
+ if (!thumbnailKey && asset.s3Path) {
1374
+ var uuid = asset.uuid || asset.id;
1375
+ var thumbnailFilename = "".concat(uuid, ".png");
1376
+ thumbnailKey = "".concat(asset.s3Path, "/").concat(thumbnailFilename);
1377
+ }
1378
+ return thumbnailKey || null;
1379
+ }
1380
+ function isThumbnailCached(_x14) {
1381
+ return _isThumbnailCached.apply(this, arguments);
1382
+ }
1383
+ function _isThumbnailCached() {
1384
+ _isThumbnailCached = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee36(asset) {
1385
+ var isS3Asset, key;
1386
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context36) {
1387
+ while (1) switch (_context36.n) {
1388
+ case 0:
1389
+ // Match the isS3Component logic: isS3Component || source === 's3' || scope === 'user'
1390
+ isS3Asset = asset.isS3Component || asset.source === 's3' || asset.scope === 'user';
1391
+ if (isS3Asset) {
1392
+ _context36.n = 1;
1393
+ break;
1394
+ }
1395
+ return _context36.a(2, true);
1396
+ case 1:
1397
+ key = getThumbnailKey(asset);
1398
+ if (key) {
1399
+ _context36.n = 2;
1400
+ break;
1401
+ }
1402
+ return _context36.a(2, false);
1403
+ case 2:
1404
+ return _context36.a(2, isCached(key));
1405
+ }
1406
+ }, _callee36);
1407
+ }));
1408
+ return _isThumbnailCached.apply(this, arguments);
1409
+ }
1410
+ function isCached(_x15) {
1411
+ return _isCached.apply(this, arguments);
1412
+ }
1413
+
1414
+ // --- Path/Expiry Helpers ---
1415
+ function _isCached() {
1416
+ _isCached = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee37(s3Key) {
1417
+ var expiryMs,
1418
+ _args37 = arguments;
1419
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context37) {
1420
+ while (1) switch (_context37.n) {
1421
+ case 0:
1422
+ expiryMs = _args37.length > 1 && _args37[1] !== undefined ? _args37[1] : null;
1423
+ return _context37.a(2, CacheManager.cacheManager.has("https://s3.cache/".concat(s3Key), expiryMs));
1424
+ }
1425
+ }, _callee37);
1426
+ }));
1427
+ return _isCached.apply(this, arguments);
1428
+ }
1429
+ function getCacheExpiryForPath(path) {
1430
+ var assetType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1431
+ return CacheManager.cacheManager.getExpiryForPath(path, assetType);
1432
+ }
1433
+ function formatCacheExpiry(ms) {
1434
+ var SECOND = 1000;
1435
+ var MINUTE = 60 * SECOND;
1436
+ var HOUR = 60 * MINUTE;
1437
+ var DAY = 24 * HOUR;
1438
+ var WEEK = 7 * DAY;
1439
+ if (ms >= WEEK) return "".concat((ms / WEEK).toFixed(1), " week(s)");
1440
+ if (ms >= DAY) return "".concat((ms / DAY).toFixed(1), " day(s)");
1441
+ if (ms >= HOUR) return "".concat((ms / HOUR).toFixed(1), " hour(s)");
1442
+ return "".concat((ms / 1000 / 60).toFixed(1), " minute(s)");
1443
+ }
1444
+
1445
+ exports.GLOBAL_CACHE_NAME = GLOBAL_CACHE_NAME;
1446
+ exports.cacheJsonData = cacheJsonData;
1447
+ exports.cleanExpiredCache = cleanExpiredCache;
1448
+ exports.cleanInvalidCacheEntries = cleanInvalidCacheEntries;
1449
+ exports.clearS3Cache = clearS3Cache;
1450
+ exports.formatCacheExpiry = formatCacheExpiry;
1451
+ exports.getAllCacheKeys = getAllCacheKeys;
1452
+ exports.getCacheExpiryForPath = getCacheExpiryForPath;
1453
+ exports.getCacheStats = getCacheStats;
1454
+ exports.getCachedJsonData = getCachedJsonData;
1455
+ exports.getCachedLocalFile = getCachedLocalFile;
1456
+ exports.getCachedLocalFileURL = getCachedLocalFileURL;
1457
+ exports.getCachedLocalJson = getCachedLocalJson;
1458
+ exports.getCachedS3Json = getCachedS3Json;
1459
+ exports.getCachedS3Object = getCachedS3Object;
1460
+ exports.getCachedS3ObjectURL = getCachedS3ObjectURL;
1461
+ exports.getCurrentCacheName = getCurrentCacheName;
1462
+ exports.getGlobalCacheStats = getGlobalCacheStats;
1463
+ exports.getGlobalOnlyCacheStats = getGlobalOnlyCacheStats;
1464
+ exports.getThumbnailKey = getThumbnailKey;
1465
+ exports.getUserOnlyCacheStats = getUserOnlyCacheStats;
1466
+ exports.isCached = isCached;
1467
+ exports.isThumbnailCached = isThumbnailCached;
1468
+ exports.preloadLocalFiles = preloadLocalFiles;
1469
+ exports.preloadS3Objects = preloadS3Objects;
1470
+ exports.removeCachedJsonData = removeCachedJsonData;
1471
+ exports.resetCacheIdentity = resetCacheIdentity;
1472
+ exports.resetGlobalCacheStats = resetGlobalCacheStats;
1473
+ exports.switchCachePartition = switchCachePartition;