@networkpro/web 1.1.3 → 1.3.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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@networkpro/web",
3
3
  "private": false,
4
4
  "sideEffects": false,
5
- "version": "1.1.3",
5
+ "version": "1.3.0",
6
6
  "description": "Locking Down Networks, Unlocking Confidence | Security, Networking, Privacy — Network Pro Strategies",
7
7
  "keywords": [
8
8
  "security",
@@ -51,6 +51,10 @@
51
51
  "lint:md": "npx markdownlint-cli2 \"**/*.{md,markdown}\" \"#node_modules/**\" \"#build/**\"",
52
52
  "lint:css": "stylelint \"**/*.{css,svelte}\" --ignore-path .stylelintignore",
53
53
  "lint:all": "npm run lint && npm run lint:md && npm run lint:css && npm run format",
54
+ "lhci": "lhci",
55
+ "lighthouse": "npm run lighthouse:local",
56
+ "lighthouse:local": "npm run build && npm run preview & wait-on http://localhost:4173 && npm run lhci:run",
57
+ "lhci:run": "lhci autorun --config=.lighthouserc.cjs",
54
58
  "test": "npm run test:all",
55
59
  "test:all": "npm run test:client -- --run && npm run test:server -- --run",
56
60
  "test:client": "vitest --config vitest.config.client.js",
@@ -1,3 +1,10 @@
1
+ /* ==========================================================================
2
+ playwright.config.js
3
+
4
+ SPDX-License-Identifier: CC-BY-4.0 OR GPL-3.0-or-later
5
+ This file is part of Network Pro.
6
+ ========================================================================== */
7
+
1
8
  // @ts-check
2
9
  import { defineConfig, devices } from "@playwright/test";
3
10
 
@@ -0,0 +1,15 @@
1
+ /* ==========================================================================
2
+ src/global.d.ts
3
+
4
+ SPDX-License-Identifier: CC-BY-4.0 OR GPL-3.0-or-later
5
+ This file is part of Network Pro.
6
+ ========================================================================== */
7
+
8
+ interface BeforeInstallPromptEvent extends Event {
9
+ readonly platforms: string[];
10
+ readonly userChoice: Promise<{
11
+ outcome: 'accepted' | 'dismissed';
12
+ platform: string;
13
+ }>;
14
+ prompt(): Promise<void>;
15
+ }
@@ -0,0 +1,93 @@
1
+ <!-- ==========================================================================
2
+ src/lib/components/PWAInstallButton.svelte
3
+
4
+ SPDX-License-Identifier: CC-BY-4.0 OR GPL-3.0-or-later
5
+ This file is part of Network Pro.
6
+ ========================================================================== -->
7
+
8
+ <script>
9
+ import { onMount } from "svelte";
10
+ import { fade } from "svelte/transition";
11
+
12
+ let show = false;
13
+
14
+ /** @type {BeforeInstallPromptEvent | null} */
15
+ let deferredPrompt = null;
16
+
17
+ /**
18
+ * @typedef {CustomEvent<BeforeInstallPromptEvent>} PWAInstallAvailableEvent
19
+ */
20
+
21
+ onMount(() => {
22
+ /**
23
+ * Listen for the custom event fired by registerServiceWorker.js
24
+ * to enable a custom install experience.
25
+ *
26
+ * TypeScript / svelte-check does not recognize custom events by default,
27
+ * so we cast the base Event to CustomEvent manually.
28
+ */
29
+ window.addEventListener(
30
+ "pwa-install-available",
31
+ (/** @type {Event} */ e) => {
32
+ const customEvent = /** @type {PWAInstallAvailableEvent} */ (e);
33
+ deferredPrompt = customEvent.detail;
34
+ show = true;
35
+ },
36
+ );
37
+ });
38
+
39
+ /**
40
+ * Trigger the native install prompt and handle user response
41
+ */
42
+ async function promptInstall() {
43
+ if (!deferredPrompt) return;
44
+
45
+ deferredPrompt.prompt();
46
+
47
+ const { outcome } = await deferredPrompt.userChoice;
48
+ console.log(`User response to PWA install prompt: ${outcome}`);
49
+
50
+ // Always hide the button after interaction
51
+ show = false;
52
+ deferredPrompt = null;
53
+ }
54
+ </script>
55
+
56
+ {#if show}
57
+ <button
58
+ id="pwa-install"
59
+ class="install-button"
60
+ on:click={promptInstall}
61
+ transition:fade={{ duration: 600 }}>
62
+ Install App
63
+ </button>
64
+ {/if}
65
+
66
+ <style>
67
+ .install-button {
68
+ display: block;
69
+ padding: 0.5rem 1rem;
70
+ border: none;
71
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
72
+ font-size: 1rem;
73
+ font-weight: bold;
74
+ color: #000;
75
+ background-color: #ffc627;
76
+ transition: background-color 0.2s ease-in-out;
77
+ border-radius: 6px;
78
+ cursor: pointer;
79
+ font-family: inherit;
80
+ margin-left: auto;
81
+ margin-right: auto;
82
+ margin-top: 1rem;
83
+ }
84
+
85
+ .install-button:hover {
86
+ background-color: #e6b300;
87
+ }
88
+
89
+ .install-button:focus {
90
+ outline: 2px solid #000;
91
+ outline-offset: 2px;
92
+ }
93
+ </style>
@@ -5,25 +5,31 @@ SPDX-License-Identifier: CC-BY-4.0 OR GPL-3.0-or-later
5
5
  This file is part of Network Pro.
6
6
  ========================================================================== */
7
7
 
8
+ /**
9
+ * Registers the service worker and handles update lifecycle, install prompt, and
10
+ * browser/environment compatibility checks. This supports offline usage and PWA behavior.
11
+ */
8
12
  export function registerServiceWorker() {
9
13
  if ('serviceWorker' in navigator) {
10
14
  // Skip registration in Firefox during development
11
- const isFirefox = navigator.userAgent.indexOf('Firefox') !== -1;
12
- const isDevelopment = window.location.hostname === 'localhost' ||
13
- window.location.hostname === '127.0.0.1';
15
+ const isFirefox = navigator.userAgent.includes('Firefox');
16
+ const isDevelopment =
17
+ window.location.hostname === 'localhost' ||
18
+ window.location.hostname === '127.0.0.1';
14
19
 
15
20
  if (isFirefox && isDevelopment) {
16
21
  console.log('Service Worker registration skipped in Firefox development mode');
17
22
  return;
18
23
  }
19
24
 
20
- // Wait until after the page fully loads for better performance
25
+ // Wait until after full page load for performance optimization
21
26
  window.addEventListener('load', () => {
22
- navigator.serviceWorker.register('service-worker.js')
27
+ navigator.serviceWorker
28
+ .register('service-worker.js')
23
29
  .then((registration) => {
24
30
  console.log('Service Worker registered with scope:', registration.scope);
25
31
 
26
- // Track installation of new service worker
32
+ // Track installation of a new service worker
27
33
  registration.addEventListener('updatefound', () => {
28
34
  const newWorker = registration.installing;
29
35
  console.log('New service worker installing...');
@@ -40,7 +46,7 @@ export function registerServiceWorker() {
40
46
  ) {
41
47
  updatePrompted = true;
42
48
 
43
- // Custom prompt: reload to update
49
+ // Custom prompt: ask user to reload for latest content
44
50
  if (confirm('New content is available. Reload to update?')) {
45
51
  window.location.reload();
46
52
  }
@@ -52,7 +58,7 @@ export function registerServiceWorker() {
52
58
  console.error('Service Worker registration failed:', error);
53
59
  });
54
60
 
55
- // Ensure page reloads when new service worker takes control
61
+ // Ensure the page reloads automatically when the new service worker takes control
56
62
  let refreshing = false;
57
63
  navigator.serviceWorker.addEventListener('controllerchange', () => {
58
64
  if (!refreshing) {
@@ -60,6 +66,14 @@ export function registerServiceWorker() {
60
66
  window.location.reload();
61
67
  }
62
68
  });
69
+
70
+ // Optional PWA install prompt logic
71
+ window.addEventListener('beforeinstallprompt', (e) => {
72
+ e.preventDefault();
73
+ window.dispatchEvent(new CustomEvent('pwa-install-available', {
74
+ detail: /** @type {BeforeInstallPromptEvent} */ (e)
75
+ }));
76
+ });
63
77
  });
64
78
  }
65
79
  }
@@ -12,8 +12,8 @@ This file is part of Network Pro.
12
12
  import Footer from "$lib/components/layout/Footer.svelte";
13
13
  import HeaderDefault from "$lib/components/layout/HeaderDefault.svelte";
14
14
  import HeaderHome from "$lib/components/layout/HeaderHome.svelte";
15
+ import PWAInstallButton from "$lib/components/PWAInstallButton.svelte";
15
16
  import { browser } from "$app/environment";
16
- // TODO: Testing in progress
17
17
  import { registerServiceWorker } from "$lib/registerServiceWorker.js";
18
18
  import "$lib/styles";
19
19
 
@@ -47,7 +47,6 @@ This file is part of Network Pro.
47
47
  // Preload Apple Touch icon
48
48
  touchImg.src = appleTouchIcon;
49
49
 
50
- // TODO: Testing in progress
51
50
  // Register the service worker
52
51
  registerServiceWorker();
53
52
  }
@@ -92,9 +91,11 @@ This file is part of Network Pro.
92
91
  {#if data.pathname === "/"}
93
92
  <!-- Render the Home Header for the root route -->
94
93
  <HeaderHome />
94
+ <PWAInstallButton />
95
95
  {:else}
96
96
  <!-- Render the Default Header for all other routes -->
97
97
  <HeaderDefault />
98
+ <PWAInstallButton />
98
99
  {/if}
99
100
  </ContainerSection>
100
101
  </header>
@@ -8,25 +8,71 @@ This file is part of Network Pro.
8
8
  /** @type {ServiceWorkerGlobalScope} */
9
9
  const sw = self;
10
10
 
11
+ const disallowedHosts = ["licdn.com", "googletagmanager.com"];
12
+
11
13
  import { build, files, version } from "$service-worker";
12
14
 
13
15
  /** @type {string} */
14
16
  const CACHE = `cache-${version}`;
15
17
 
16
18
  /** @type {string[]} */
17
- const ASSETS = Array.from(new Set([...build, ...files, "/offline.html"]));
19
+ const excludedAssets = [];
20
+
21
+ /** @type {string[]} */
22
+ const ASSETS = Array.from(
23
+ new Set(
24
+ [...build, ...files, "/offline.html"].filter((path) => {
25
+ try {
26
+ const url = new URL(path, location.origin);
27
+ const hostname = url.hostname;
28
+
29
+ const shouldExclude =
30
+ path.startsWith("http") ||
31
+ disallowedHosts.some(
32
+ (host) => hostname === host || hostname.endsWith(`.${host}`),
33
+ ) ||
34
+ [
35
+ "/img/banner-1280x640.png",
36
+ "/img/banner-og-1200x630.png",
37
+ "/img/logo-transparent.png",
38
+ "/img/logo.png",
39
+ "/img/svelte.png",
40
+ "/robots.txt",
41
+ "/screenshots/desktop-foss.png",
42
+ "/sitemap.xml",
43
+ "/CNAME",
44
+ ].includes(path);
45
+
46
+ if (shouldExclude) excludedAssets.push(path);
47
+ return !shouldExclude;
48
+ } catch (err) {
49
+ console.warn("[SW] URL parse failed, skipping path:", path, err);
50
+ excludedAssets.push(path);
51
+ return true;
52
+ }
53
+ }),
54
+ ),
55
+ );
18
56
 
19
- console.log("[SW] Assets to cache:", ASSETS); // Helps debug duplicates
57
+ const uniqueExcludedAssets = [...new Set(excludedAssets)].sort();
58
+
59
+ console.log("[SW] Assets to precache:", ASSETS);
60
+ console.log("[SW] Excluded assets:", uniqueExcludedAssets);
20
61
 
21
62
  /**
22
63
  * @param {ExtendableEvent} event
23
64
  */
24
65
  sw.addEventListener("install", (event) => {
25
- /** @type {ExtendableEvent} */ (event).waitUntil(
26
- caches
27
- .open(CACHE)
28
- .then((cache) => cache.addAll(ASSETS))
29
- .then(() => sw.skipWaiting()),
66
+ event.waitUntil(
67
+ (async () => {
68
+ const cache = await caches.open(CACHE);
69
+ try {
70
+ await cache.addAll(ASSETS);
71
+ sw.skipWaiting();
72
+ } catch (err) {
73
+ console.warn("[SW] Failed to precache some assets:", err);
74
+ }
75
+ })(),
30
76
  );
31
77
  });
32
78
 
@@ -64,8 +110,10 @@ sw.addEventListener("activate", (event) => {
64
110
  sw.addEventListener("fetch", (event) => {
65
111
  /** @type {FetchEvent} */ (event).respondWith(
66
112
  (async () => {
67
- const cached = await caches.match(event.request);
68
- if (cached) return cached;
113
+ if (new URL(event.request.url).origin === location.origin) {
114
+ const cached = await caches.match(event.request);
115
+ if (cached) return cached;
116
+ }
69
117
 
70
118
  try {
71
119
  if (event.request.mode === "navigate") {
@@ -1,10 +1,15 @@
1
1
  {
2
+ "id": "/",
3
+ "start_url": "/?utm_source=homescreen",
4
+ "scope": "/",
2
5
  "name": "Network Pro Strategies",
3
6
  "short_name": "Network Pro",
4
7
  "description": "Access our expert cybersecurity services anytime, anywhere with our streamlined Progressive Web App. Optimized for speed, security, and mobile use, this app offers a seamless experience to explore our solutions, view project highlights, and get in touch—all in one place.",
5
- "start_url": "/?utm_source=homescreen",
8
+ "lang": "en-US",
9
+ "dir": "ltr",
6
10
  "display": "standalone",
7
11
  "display_override": ["window-controls-overlay", "minimal-ui"],
12
+ "orientation": "any",
8
13
  "background_color": "#191919",
9
14
  "theme_color": "#ffc627",
10
15
  "icons": [
@@ -22,7 +27,7 @@
22
27
  "src": "/icon-512x512-maskable.png",
23
28
  "type": "image/png",
24
29
  "sizes": "512x512",
25
- "purpose": "maskable"
30
+ "purpose": "any maskable"
26
31
  },
27
32
  {
28
33
  "src": "/icon-splash.png",
@@ -30,6 +35,8 @@
30
35
  "sizes": "512x512"
31
36
  }
32
37
  ],
38
+ "categories": ["business", "security", "technology", "network", "privacy"],
39
+ "prefer_related_applications": false,
33
40
  "screenshots": [
34
41
  {
35
42
  "src": "/screenshots/desktop-home.png",
@@ -60,9 +67,6 @@
60
67
  "label": "FOSS Spotlight on mobile"
61
68
  }
62
69
  ],
63
- "orientation": "any",
64
- "scope": "/",
65
- "categories": ["business", "security", "technology", "network", "privacy"],
66
70
  "shortcuts": [
67
71
  {
68
72
  "name": "Consulting Services",