@swoff/cli 0.4.1 → 0.4.4
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/dist/lib/commands/generate-guide.js +15 -15
- package/dist/lib/commands/generate-guide.js.map +1 -1
- package/dist/lib/commands/init.js +52 -6
- package/dist/lib/commands/init.js.map +1 -1
- package/dist/lib/config/validator.js +1 -1
- package/dist/lib/config/validator.js.map +1 -1
- package/dist/lib/generators/file-generators/client-injector-bundle.js +2 -1
- package/dist/lib/generators/file-generators/client-injector-bundle.js.map +1 -1
- package/dist/lib/generators/file-generators/client-injector.js +2 -1
- package/dist/lib/generators/file-generators/client-injector.js.map +1 -1
- package/dist/lib/generators/file-generators/context.js +4 -1
- package/dist/lib/generators/file-generators/context.js.map +1 -1
- package/dist/lib/generators/file-generators/generate-framework-adapters.js +28 -22
- package/dist/lib/generators/file-generators/generate-framework-adapters.js.map +1 -1
- package/dist/lib/generators/sw-sections/activate-handler.js +1 -5
- package/dist/lib/generators/sw-sections/activate-handler.js.map +1 -1
- package/dist/lib/generators/sw-sections/background-precache.js +8 -8
- package/dist/lib/generators/sw-sections/batch-refresh-queue.js +2 -5
- package/dist/lib/generators/sw-sections/batch-refresh-queue.js.map +1 -1
- package/dist/lib/generators/sw-sections/fetch-handler.js +14 -3
- package/dist/lib/generators/sw-sections/fetch-handler.js.map +1 -1
- package/dist/lib/shared/config-types.js +1 -0
- package/dist/lib/shared/config-types.js.map +1 -1
- package/dist/lib/utils/detect-framework.js +16 -0
- package/dist/lib/utils/detect-framework.js.map +1 -1
- package/dist/runtime/client-injector-bundle.js +2 -2
- package/dist/runtime/client-injector-bundle.js.map +1 -1
- package/dist/runtime/client-injector.js +3 -2
- package/dist/runtime/client-injector.js.map +1 -1
- package/dist/runtime/gql-wrapper.js +3 -1
- package/dist/runtime/gql-wrapper.js.map +1 -1
- package/dist/runtime/swoff-api-bundle.js +2 -1
- package/dist/runtime/swoff-api-bundle.js.map +1 -1
- package/package.json +1 -1
- package/templates/react/{useOfflineAnalytics.jsx → useSwoffAnalytics.jsx} +3 -3
- package/templates/react/{useOfflineAnalytics.tsx → useSwoffAnalytics.tsx} +3 -3
- package/templates/react/{useAuth.jsx → useSwoffAuth.jsx} +2 -2
- package/templates/react/{useAuth.tsx → useSwoffAuth.tsx} +2 -2
- package/templates/react/{useCachedFetch.jsx → useSwoffFetch.jsx} +6 -6
- package/templates/react/{useCachedFetch.tsx → useSwoffFetch.tsx} +7 -7
- package/templates/react/{useMutation.jsx → useSwoffMutation.jsx} +3 -3
- package/templates/react/{useMutation.tsx → useSwoffMutation.tsx} +3 -3
- package/templates/react/{useMutationState.jsx → useSwoffMutationState.jsx} +1 -1
- package/templates/react/{useMutationState.tsx → useSwoffMutationState.tsx} +2 -2
- package/templates/react/{useNetworkStatus.jsx → useSwoffNetwork.jsx} +2 -2
- package/templates/react/{useNetworkStatus.tsx → useSwoffNetwork.tsx} +2 -2
- package/templates/react/{usePrecacheProgress.jsx → useSwoffPrecache.jsx} +4 -7
- package/templates/react/{usePrecacheProgress.tsx → useSwoffPrecache.tsx} +4 -7
- package/templates/react/{usePrefetch.jsx → useSwoffPrefetch.jsx} +2 -2
- package/templates/react/{usePrefetch.tsx → useSwoffPrefetch.tsx} +2 -2
- package/templates/react/{usePushSubscription.jsx → useSwoffPush.jsx} +1 -1
- package/templates/react/{usePushSubscription.tsx → useSwoffPush.tsx} +1 -1
- package/templates/react/{usePwaInstall.jsx → useSwoffPwa.jsx} +1 -1
- package/templates/react/{usePwaInstall.tsx → useSwoffPwa.tsx} +1 -1
- package/templates/react/{useMutationQueue.jsx → useSwoffQueue.jsx} +2 -2
- package/templates/react/{useMutationQueue.tsx → useSwoffQueue.tsx} +2 -2
- package/templates/react/{useStorageEstimate.jsx → useSwoffStorage.jsx} +2 -2
- package/templates/react/{useStorageEstimate.tsx → useSwoffStorage.tsx} +2 -2
- package/templates/react/{useBackgroundSync.jsx → useSwoffSync.jsx} +1 -1
- package/templates/react/{useBackgroundSync.tsx → useSwoffSync.tsx} +1 -1
- package/templates/svelte/useSwoffAnalytics.js +31 -0
- package/templates/svelte/useSwoffAnalytics.ts +37 -0
- package/templates/svelte/useSwoffAuth.js +95 -0
- package/templates/svelte/useSwoffAuth.ts +96 -0
- package/templates/svelte/useSwoffFetch.js +97 -0
- package/templates/svelte/useSwoffFetch.ts +112 -0
- package/templates/svelte/useSwoffMutation.js +110 -0
- package/templates/svelte/useSwoffMutation.ts +141 -0
- package/templates/svelte/useSwoffMutationState.js +27 -0
- package/templates/svelte/useSwoffMutationState.ts +28 -0
- package/templates/svelte/useSwoffNetwork.js +75 -0
- package/templates/svelte/useSwoffNetwork.ts +75 -0
- package/templates/svelte/useSwoffPrecache.js +19 -0
- package/templates/svelte/useSwoffPrecache.ts +19 -0
- package/templates/svelte/useSwoffPrefetch.js +19 -0
- package/templates/svelte/useSwoffPrefetch.ts +20 -0
- package/templates/svelte/useSwoffPush.js +82 -0
- package/templates/svelte/useSwoffPush.ts +82 -0
- package/templates/svelte/useSwoffPwa.js +27 -0
- package/templates/svelte/useSwoffPwa.ts +27 -0
- package/templates/svelte/useSwoffQueue.js +57 -0
- package/templates/svelte/useSwoffQueue.ts +67 -0
- package/templates/svelte/useSwoffReset.js +21 -0
- package/templates/svelte/useSwoffReset.ts +32 -0
- package/templates/svelte/useSwoffStorage.js +47 -0
- package/templates/svelte/useSwoffStorage.ts +47 -0
- package/templates/svelte/useSwoffSync.js +31 -0
- package/templates/svelte/useSwoffSync.ts +31 -0
- package/templates/vue/useSwoffAnalytics.js +46 -0
- package/templates/vue/useSwoffAnalytics.ts +54 -0
- package/templates/vue/useSwoffAuth.js +106 -0
- package/templates/vue/useSwoffAuth.ts +118 -0
- package/templates/vue/useSwoffFetch.js +127 -0
- package/templates/vue/useSwoffFetch.ts +143 -0
- package/templates/vue/useSwoffMutation.js +124 -0
- package/templates/vue/useSwoffMutation.ts +155 -0
- package/templates/vue/useSwoffMutationState.js +35 -0
- package/templates/vue/useSwoffMutationState.ts +36 -0
- package/templates/vue/useSwoffNetwork.js +86 -0
- package/templates/vue/useSwoffNetwork.ts +89 -0
- package/templates/vue/useSwoffPrecache.js +19 -0
- package/templates/vue/useSwoffPrecache.ts +19 -0
- package/templates/vue/useSwoffPrefetch.js +33 -0
- package/templates/vue/useSwoffPrefetch.ts +41 -0
- package/templates/vue/useSwoffPush.js +81 -0
- package/templates/vue/useSwoffPush.ts +81 -0
- package/templates/vue/useSwoffPwa.js +27 -0
- package/templates/vue/useSwoffPwa.ts +27 -0
- package/templates/vue/useSwoffQueue.js +70 -0
- package/templates/vue/useSwoffQueue.ts +82 -0
- package/templates/vue/useSwoffReset.js +32 -0
- package/templates/vue/useSwoffReset.ts +39 -0
- package/templates/vue/useSwoffStorage.js +56 -0
- package/templates/vue/useSwoffStorage.ts +57 -0
- package/templates/vue/useSwoffSync.js +30 -0
- package/templates/vue/useSwoffSync.ts +30 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ref } from "vue";
|
|
2
|
+
import { resetSwoff } from "../reset.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Composable exposing swoff's nuclear reset with reactive state.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* const { reset, isResetting, error } = useSwoffReset();
|
|
9
|
+
*
|
|
10
|
+
* <button @click="reset()" :disabled="isResetting">
|
|
11
|
+
* {{ isResetting ? "Resetting..." : "Reset Swoff" }}
|
|
12
|
+
* </button>
|
|
13
|
+
* <p v-if="error" style="color: red">{{ error.message }}</p>
|
|
14
|
+
*/
|
|
15
|
+
export function useSwoffReset() {
|
|
16
|
+
const isResetting = ref(false);
|
|
17
|
+
const error = ref(null);
|
|
18
|
+
|
|
19
|
+
async function reset(options) {
|
|
20
|
+
isResetting.value = true;
|
|
21
|
+
error.value = null;
|
|
22
|
+
try {
|
|
23
|
+
await resetSwoff(options);
|
|
24
|
+
} catch (e) {
|
|
25
|
+
error.value = e instanceof Error ? e : new Error(String(e));
|
|
26
|
+
} finally {
|
|
27
|
+
isResetting.value = false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return { reset, isResetting: isResetting.value, error: error.value };
|
|
32
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ref } from "vue";
|
|
2
|
+
import { resetSwoff } from "../reset";
|
|
3
|
+
import type { ResetSwoffOptions } from "../reset";
|
|
4
|
+
|
|
5
|
+
interface UseSwoffResetResult {
|
|
6
|
+
reset: (options?: ResetSwoffOptions) => Promise<void>;
|
|
7
|
+
isResetting: boolean;
|
|
8
|
+
error: Error | null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Composable exposing swoff's nuclear reset with reactive state.
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* const { reset, isResetting, error } = useSwoffReset();
|
|
16
|
+
*
|
|
17
|
+
* <button @click="reset()" :disabled="isResetting">
|
|
18
|
+
* {{ isResetting ? "Resetting..." : "Reset Swoff" }}
|
|
19
|
+
* </button>
|
|
20
|
+
* <p v-if="error" style="color: red">{{ error.message }}</p>
|
|
21
|
+
*/
|
|
22
|
+
export function useSwoffReset(): UseSwoffResetResult {
|
|
23
|
+
const isResetting = ref(false);
|
|
24
|
+
const error = ref<Error | null>(null);
|
|
25
|
+
|
|
26
|
+
async function reset(options?: ResetSwoffOptions) {
|
|
27
|
+
isResetting.value = true;
|
|
28
|
+
error.value = null;
|
|
29
|
+
try {
|
|
30
|
+
await resetSwoff(options);
|
|
31
|
+
} catch (e) {
|
|
32
|
+
error.value = e instanceof Error ? e : new Error(String(e));
|
|
33
|
+
} finally {
|
|
34
|
+
isResetting.value = false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return { reset, isResetting: isResetting.value, error: error.value };
|
|
39
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ref, onMounted, onUnmounted } from "vue";
|
|
2
|
+
import { getStorageEstimate, formatBytes } from "../storage.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Reactive storage estimate. Shows available quota and usage.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* const { usage, quota, percentUsed, formattedUsage, formattedQuota, loading } = useSwoffStorage();
|
|
9
|
+
*
|
|
10
|
+
* <div v-if="!loading && percentUsed > 80">Storage almost full</div>
|
|
11
|
+
*
|
|
12
|
+
* @param autoRefresh - Re-check on visibility change (default true)
|
|
13
|
+
*/
|
|
14
|
+
export function useSwoffStorage(autoRefresh = true) {
|
|
15
|
+
const usage = ref(0);
|
|
16
|
+
const quota = ref(0);
|
|
17
|
+
const percentUsed = ref(0);
|
|
18
|
+
const formattedUsage = ref("0 B");
|
|
19
|
+
const formattedQuota = ref("0 B");
|
|
20
|
+
const loading = ref(true);
|
|
21
|
+
const error = ref(null);
|
|
22
|
+
|
|
23
|
+
async function check() {
|
|
24
|
+
try {
|
|
25
|
+
const result = await getStorageEstimate();
|
|
26
|
+
usage.value = result.usage;
|
|
27
|
+
quota.value = result.quota;
|
|
28
|
+
percentUsed.value = result.percentUsed;
|
|
29
|
+
formattedUsage.value = formatBytes(result.usage);
|
|
30
|
+
formattedQuota.value = formatBytes(result.quota);
|
|
31
|
+
loading.value = false;
|
|
32
|
+
error.value = null;
|
|
33
|
+
} catch (err) {
|
|
34
|
+
loading.value = false;
|
|
35
|
+
error.value = String(err);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
onMounted(() => {
|
|
40
|
+
check();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
if (autoRefresh) {
|
|
44
|
+
onMounted(() => {
|
|
45
|
+
function onVisible() {
|
|
46
|
+
if (document.visibilityState === "visible") check();
|
|
47
|
+
}
|
|
48
|
+
document.addEventListener("visibilitychange", onVisible);
|
|
49
|
+
onUnmounted(() => {
|
|
50
|
+
document.removeEventListener("visibilitychange", onVisible);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return { usage, quota, percentUsed, formattedUsage, formattedQuota, loading, error };
|
|
56
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ref, onMounted, onUnmounted } from "vue";
|
|
2
|
+
import { getStorageEstimate, formatBytes } from "../storage";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Reactive storage estimate. Shows available quota and usage.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* const { usage, quota, percentUsed, formattedUsage, formattedQuota, loading } = useSwoffStorage();
|
|
9
|
+
*
|
|
10
|
+
* <div v-if="!loading && percentUsed > 80">Storage almost full</div>
|
|
11
|
+
*
|
|
12
|
+
* @param autoRefresh - Re-check on visibility change (default true)
|
|
13
|
+
* @returns {{ usage: Ref<number>, quota: Ref<number>, percentUsed: Ref<number>, formattedUsage: Ref<string>, formattedQuota: Ref<string>, loading: Ref<boolean>, error: Ref<string | null> }}
|
|
14
|
+
*/
|
|
15
|
+
export function useSwoffStorage(autoRefresh = true) {
|
|
16
|
+
const usage = ref(0);
|
|
17
|
+
const quota = ref(0);
|
|
18
|
+
const percentUsed = ref(0);
|
|
19
|
+
const formattedUsage = ref("0 B");
|
|
20
|
+
const formattedQuota = ref("0 B");
|
|
21
|
+
const loading = ref(true);
|
|
22
|
+
const error = ref<string | null>(null);
|
|
23
|
+
|
|
24
|
+
async function check() {
|
|
25
|
+
try {
|
|
26
|
+
const result = await getStorageEstimate();
|
|
27
|
+
usage.value = result.usage;
|
|
28
|
+
quota.value = result.quota;
|
|
29
|
+
percentUsed.value = result.percentUsed;
|
|
30
|
+
formattedUsage.value = formatBytes(result.usage);
|
|
31
|
+
formattedQuota.value = formatBytes(result.quota);
|
|
32
|
+
loading.value = false;
|
|
33
|
+
error.value = null;
|
|
34
|
+
} catch (err) {
|
|
35
|
+
loading.value = false;
|
|
36
|
+
error.value = String(err);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
onMounted(() => {
|
|
41
|
+
check();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
if (autoRefresh) {
|
|
45
|
+
onMounted(() => {
|
|
46
|
+
function onVisible() {
|
|
47
|
+
if (document.visibilityState === "visible") check();
|
|
48
|
+
}
|
|
49
|
+
document.addEventListener("visibilitychange", onVisible);
|
|
50
|
+
onUnmounted(() => {
|
|
51
|
+
document.removeEventListener("visibilitychange", onVisible);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return { usage, quota, percentUsed, formattedUsage, formattedQuota, loading, error };
|
|
57
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ref, onMounted, onUnmounted } from "vue";
|
|
2
|
+
import { retrySync } from "../mutation/sync.js";
|
|
3
|
+
|
|
4
|
+
export function useSwoffSync() {
|
|
5
|
+
const supported = ref(
|
|
6
|
+
typeof window !== "undefined" && typeof navigator !== "undefined"
|
|
7
|
+
? "serviceWorker" in navigator && "SyncManager" in window
|
|
8
|
+
: false,
|
|
9
|
+
);
|
|
10
|
+
const registered = ref(false);
|
|
11
|
+
const lastSync = ref(null);
|
|
12
|
+
|
|
13
|
+
onMounted(() => {
|
|
14
|
+
function onSyncComplete(e) {
|
|
15
|
+
registered.value = true;
|
|
16
|
+
lastSync.value = { succeeded: e.detail.succeeded, failed: e.detail.failed };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
window.addEventListener("background-sync-complete", onSyncComplete);
|
|
20
|
+
onUnmounted(() => {
|
|
21
|
+
window.removeEventListener("background-sync-complete", onSyncComplete);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
async function triggerSync() {
|
|
26
|
+
await retrySync();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return { supported, registered, lastSync, triggerSync };
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ref, onMounted, onUnmounted } from "vue";
|
|
2
|
+
import { retrySync } from "../mutation/sync";
|
|
3
|
+
|
|
4
|
+
export function useSwoffSync() {
|
|
5
|
+
const supported = ref(
|
|
6
|
+
typeof window !== "undefined" && typeof navigator !== "undefined"
|
|
7
|
+
? "serviceWorker" in navigator && "SyncManager" in window
|
|
8
|
+
: false,
|
|
9
|
+
);
|
|
10
|
+
const registered = ref(false);
|
|
11
|
+
const lastSync = ref<{ succeeded: number; failed: number } | null>(null);
|
|
12
|
+
|
|
13
|
+
onMounted(() => {
|
|
14
|
+
function onSyncComplete(e: CustomEvent) {
|
|
15
|
+
registered.value = true;
|
|
16
|
+
lastSync.value = { succeeded: e.detail.succeeded, failed: e.detail.failed };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
window.addEventListener("background-sync-complete", onSyncComplete);
|
|
20
|
+
onUnmounted(() => {
|
|
21
|
+
window.removeEventListener("background-sync-complete", onSyncComplete);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
async function triggerSync() {
|
|
26
|
+
await retrySync();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return { supported, registered, lastSync, triggerSync };
|
|
30
|
+
}
|