@soham20/smart-offline-sdk 0.2.0 → 0.2.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.
- package/package.json +1 -1
- package/src/index.cjs.js +19 -2
- package/src/index.d.ts +1 -0
- package/src/index.js +21 -2
package/package.json
CHANGED
package/src/index.cjs.js
CHANGED
|
@@ -116,21 +116,38 @@ async function clearCacheLogs() {
|
|
|
116
116
|
store.clear();
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
async function clearCache() {
|
|
120
|
+
const cacheNames = await caches.keys();
|
|
121
|
+
const smartOfflineCaches = cacheNames.filter(name => name.includes('smart-offline'));
|
|
122
|
+
await Promise.all(smartOfflineCaches.map(name => caches.delete(name)));
|
|
123
|
+
|
|
124
|
+
// Also clear usage tracking database
|
|
125
|
+
const db = await openDB('smart-offline', 1);
|
|
126
|
+
const tx = db.transaction('usage', 'readwrite');
|
|
127
|
+
const store = tx.objectStore('usage');
|
|
128
|
+
store.clear();
|
|
129
|
+
|
|
130
|
+
console.log('🗑️ All SmartOffline caches and usage data cleared');
|
|
131
|
+
}
|
|
132
|
+
|
|
119
133
|
function openDB(name, version) {
|
|
120
134
|
return new Promise((resolve, reject) => {
|
|
121
135
|
const request = indexedDB.open(name, version);
|
|
122
136
|
request.onupgradeneeded = () => {
|
|
123
137
|
const db = request.result;
|
|
124
|
-
if (!db.objectStoreNames.contains('logs')) {
|
|
138
|
+
if (name === 'smart-offline-logs' && !db.objectStoreNames.contains('logs')) {
|
|
125
139
|
db.createObjectStore('logs', { autoIncrement: true });
|
|
126
140
|
}
|
|
141
|
+
if (name === 'smart-offline' && !db.objectStoreNames.contains('usage')) {
|
|
142
|
+
db.createObjectStore('usage', { keyPath: 'url' });
|
|
143
|
+
}
|
|
127
144
|
};
|
|
128
145
|
request.onsuccess = () => resolve(request.result);
|
|
129
146
|
request.onerror = () => reject(request.error);
|
|
130
147
|
});
|
|
131
148
|
}
|
|
132
149
|
|
|
133
|
-
const SmartOffline = { init, on, off, getCacheLogs, clearCacheLogs };
|
|
150
|
+
const SmartOffline = { init, on, off, getCacheLogs, clearCacheLogs, clearCache };
|
|
134
151
|
|
|
135
152
|
module.exports = { SmartOffline };
|
|
136
153
|
module.exports.default = SmartOffline;
|
package/src/index.d.ts
CHANGED
|
@@ -69,6 +69,7 @@ export interface SmartOfflineSDK {
|
|
|
69
69
|
off(eventType: 'cache' | 'skip' | 'serve' | 'clear' | 'error', callback: (event: CacheEvent) => void): void;
|
|
70
70
|
getCacheLogs(): Promise<CacheLog[]>;
|
|
71
71
|
clearCacheLogs(): Promise<void>;
|
|
72
|
+
clearCache(): Promise<void>;
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
export declare const SmartOffline: SmartOfflineSDK;
|
package/src/index.js
CHANGED
|
@@ -135,14 +135,32 @@ async function clearCacheLogs() {
|
|
|
135
135
|
store.clear();
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
// API to clear all caches
|
|
139
|
+
async function clearCache() {
|
|
140
|
+
const cacheNames = await caches.keys();
|
|
141
|
+
const smartOfflineCaches = cacheNames.filter(name => name.includes('smart-offline'));
|
|
142
|
+
await Promise.all(smartOfflineCaches.map(name => caches.delete(name)));
|
|
143
|
+
|
|
144
|
+
// Also clear usage tracking database
|
|
145
|
+
const db = await openDB('smart-offline', 1);
|
|
146
|
+
const tx = db.transaction('usage', 'readwrite');
|
|
147
|
+
const store = tx.objectStore('usage');
|
|
148
|
+
store.clear();
|
|
149
|
+
|
|
150
|
+
console.log('🗑️ All SmartOffline caches and usage data cleared');
|
|
151
|
+
}
|
|
152
|
+
|
|
138
153
|
function openDB(name, version) {
|
|
139
154
|
return new Promise((resolve, reject) => {
|
|
140
155
|
const request = indexedDB.open(name, version);
|
|
141
156
|
request.onupgradeneeded = () => {
|
|
142
157
|
const db = request.result;
|
|
143
|
-
if (!db.objectStoreNames.contains('logs')) {
|
|
158
|
+
if (name === 'smart-offline-logs' && !db.objectStoreNames.contains('logs')) {
|
|
144
159
|
db.createObjectStore('logs', { autoIncrement: true });
|
|
145
160
|
}
|
|
161
|
+
if (name === 'smart-offline' && !db.objectStoreNames.contains('usage')) {
|
|
162
|
+
db.createObjectStore('usage', { keyPath: 'url' });
|
|
163
|
+
}
|
|
146
164
|
};
|
|
147
165
|
request.onsuccess = () => resolve(request.result);
|
|
148
166
|
request.onerror = () => reject(request.error);
|
|
@@ -154,7 +172,8 @@ const SmartOffline = {
|
|
|
154
172
|
on,
|
|
155
173
|
off,
|
|
156
174
|
getCacheLogs,
|
|
157
|
-
clearCacheLogs
|
|
175
|
+
clearCacheLogs,
|
|
176
|
+
clearCache
|
|
158
177
|
};
|
|
159
178
|
|
|
160
179
|
export { SmartOffline }; // ✅ named export
|