@networkpro/web 1.24.5 → 1.25.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/.github/workflows/branch-guard.yml +26 -10
- package/CHANGELOG.md +98 -1
- package/cspell.json +1 -0
- package/package.json +3 -1
- package/src/hooks.server.js +38 -44
- package/src/lib/stores/posthog.js +35 -5
- package/src/lib/utils/env.js +81 -0
- package/src/routes/api/env-check/+server.js +25 -0
- package/src/service-worker.js +2 -1
- package/vite.config.js +38 -16
|
@@ -24,14 +24,30 @@ jobs:
|
|
|
24
24
|
steps:
|
|
25
25
|
- name: Check commit source
|
|
26
26
|
run: |
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
commit_msg="${{ github.event.head_commit.message }}"
|
|
28
|
+
actor="${{ github.actor }}"
|
|
29
|
+
branch="${GITHUB_REF##*/}"
|
|
30
|
+
|
|
31
|
+
echo "📝 Commit message: $commit_msg"
|
|
32
|
+
echo "👤 Actor: $actor"
|
|
33
|
+
echo "🌿 Branch: $branch"
|
|
34
|
+
|
|
35
|
+
# Define known safe patterns (merge or bot commits)
|
|
36
|
+
if echo "$commit_msg" | grep -Eq "Merge pull request|See merge request|Merge branch|(#\d+)$"; then
|
|
37
|
+
echo "✅ Merge-related commit detected — no warning."
|
|
38
|
+
exit 0
|
|
37
39
|
fi
|
|
40
|
+
|
|
41
|
+
if [[ "$actor" == "dependabot[bot]" ]] || [[ "$actor" == "renovate[bot]" ]] || [[ "$actor" == "github-actions[bot]" ]]; then
|
|
42
|
+
echo "🤖 Bot commit detected — skipping warning."
|
|
43
|
+
exit 0
|
|
44
|
+
fi
|
|
45
|
+
|
|
46
|
+
# Otherwise, warn for direct commits
|
|
47
|
+
echo "::warning ::⚠️ Direct commit to $branch by $actor."
|
|
48
|
+
{
|
|
49
|
+
echo "### ⚠️ Direct Commit Detected"
|
|
50
|
+
echo "A commit was pushed directly to \`$branch\` by **$actor**."
|
|
51
|
+
echo ""
|
|
52
|
+
echo "💡 It's recommended to use pull requests for traceability and CI validation."
|
|
53
|
+
} >> $GITHUB_STEP_SUMMARY
|
package/CHANGELOG.md
CHANGED
|
@@ -22,6 +22,98 @@ This project attempts to follow [Keep a Changelog](https://keepachangelog.com/en
|
|
|
22
22
|
|
|
23
23
|
---
|
|
24
24
|
|
|
25
|
+
## [1.25.1]
|
|
26
|
+
|
|
27
|
+
### Added
|
|
28
|
+
|
|
29
|
+
- Introduced new **environment diagnostics endpoint** at `src/routes/api/env-check/+server.js`.
|
|
30
|
+
- Returns resolved build and runtime environment data for verification.
|
|
31
|
+
- Useful for confirming `ENV_MODE` / `PUBLIC_ENV_MODE` propagation on Vercel builds.
|
|
32
|
+
- Helps troubleshoot environment mismatches between build-time and client-side contexts.
|
|
33
|
+
|
|
34
|
+
### Changed
|
|
35
|
+
|
|
36
|
+
- **vite.config.js**
|
|
37
|
+
- Enhanced configuration to log build mode and environment variables during bundling.
|
|
38
|
+
- Prints `mode`, `ENV_MODE`, `PUBLIC_ENV_MODE`, and `NODE_ENV` to aid CI/CD debugging.
|
|
39
|
+
- Uses color-coded console output for clear visibility in build logs.
|
|
40
|
+
- **env.js**
|
|
41
|
+
- Simplified and stabilized environment detection logic for better cross-environment consistency.
|
|
42
|
+
- Removed redundant imports and corrected handling of static vs dynamic `BUILD_ENV_MODE`.
|
|
43
|
+
- Improved comments and type annotations for maintainability and IDE autocompletion.
|
|
44
|
+
|
|
45
|
+
### Developer Experience
|
|
46
|
+
|
|
47
|
+
- Build logs now clearly display environment information before bundling.
|
|
48
|
+
- `env-check` API endpoint provides real-time environment inspection without rebuilding.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## [1.25.0]
|
|
53
|
+
|
|
54
|
+
### Added
|
|
55
|
+
|
|
56
|
+
- Introduced unified environment detection utility (`src/lib/utils/env.js`) with full **JSDoc typing**.
|
|
57
|
+
- Normalizes `process.env` and `import.meta.env` usage across SSR (Node) and client contexts.
|
|
58
|
+
- Safely handles browser environments where `process` is undefined.
|
|
59
|
+
- Provides standardized flags for:
|
|
60
|
+
- `isDev`, `isProd`, `isAudit`, `isCI`, and `isTest`
|
|
61
|
+
- Enables consistent environment checks across analytics, CSP, and runtime logic.
|
|
62
|
+
|
|
63
|
+
- Added hybrid **environment + host-based analytics guard** in `src/lib/stores/posthog.js`.
|
|
64
|
+
- Automatically disables PostHog tracking in `audit` mode or when hostname matches `*.audit.netwk.pro`.
|
|
65
|
+
- Prevents analytics initialization during development and test contexts.
|
|
66
|
+
- Uses the shared `detectEnvironment()` utility for centralized logic.
|
|
67
|
+
- Improves runtime logging for environment-specific behavior.
|
|
68
|
+
|
|
69
|
+
### Changed
|
|
70
|
+
|
|
71
|
+
- Updated `hooks.server.js` to include a dedicated **audit environment block** for Content Security Policy (CSP).
|
|
72
|
+
- Hardened audit CSP by removing all analytics-related sources (`posthog.com`, `posthog-assets.com`).
|
|
73
|
+
- Redirects CSP violation reporting to the mock endpoint (`/api/mock-csp`) in audit mode.
|
|
74
|
+
- Preserves full HSTS and other production security headers for audit deployments.
|
|
75
|
+
- Added clear separation between `test`, `audit`, and `prod` security policies.
|
|
76
|
+
- Improved console debugging for environment detection (`NODE_ENV`, `ENV_MODE`).
|
|
77
|
+
|
|
78
|
+
- Refactored **environment detection logic** for improved reliability across client and server contexts.
|
|
79
|
+
- Added unified environment resolver at `src/lib/utils/env.js` to standardize detection for `dev`, `prod`, `audit`, `ci`, and `test` modes.
|
|
80
|
+
- Ensures consistent handling of both `process.env.*` (Node/SSR) and `import.meta.env.*` (Vite/client) variables.
|
|
81
|
+
- Prevents mismatched behavior between browser-side analytics (`posthog.js`) and server-side policies (`hooks.server.js`).
|
|
82
|
+
- Automatically falls back to `'unknown'` if no explicit mode is set, avoiding build-time exceptions.
|
|
83
|
+
|
|
84
|
+
- Refactored **Branch Guard** workflow (`.github/workflows/branch-guard.yml`) for improved accuracy and reduced noise.
|
|
85
|
+
- Adjusted detection logic to **ignore merge commits**, Dependabot updates, and automated actions.
|
|
86
|
+
- Ensures workflow warnings are shown **only for true direct commits** to protected branches (`master`, `main`).
|
|
87
|
+
- Simplified step output and summary formatting for clearer reporting in the Actions log and job summary.
|
|
88
|
+
- Maintains lightweight permissions (`contents: read`) and executes entirely without repository writes.
|
|
89
|
+
- Improves reliability of branch protection monitoring without affecting CI or merge operations.
|
|
90
|
+
|
|
91
|
+
### Fixed
|
|
92
|
+
|
|
93
|
+
- Resolved client-side crash in browser environments caused by `process.env` being undefined.
|
|
94
|
+
- Implemented defensive checks in `env.js` for `process` availability.
|
|
95
|
+
- Eliminated reference errors during client-side initialization of analytics.
|
|
96
|
+
|
|
97
|
+
### Developer Experience
|
|
98
|
+
|
|
99
|
+
- Simplified future configuration by consolidating environment checks into a single typed utility.
|
|
100
|
+
- Improved maintainability and Vercel compatibility by ensuring `.env.audit` and `PUBLIC_ENV_MODE` variables propagate correctly to both client and server environments.
|
|
101
|
+
|
|
102
|
+
### Developer Notes
|
|
103
|
+
|
|
104
|
+
- When deploying audit builds, ensure Vercel environment variables include:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
ENV_MODE=audit
|
|
108
|
+
PUBLIC_ENV_MODE=audit
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
This enables analytics filtering and CSP hardening for the audit environment.
|
|
112
|
+
|
|
113
|
+
- Audit deployments retain full HTTPS and security headers but omit telemetry and external CSP reporting.
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
25
117
|
## [1.24.5]
|
|
26
118
|
|
|
27
119
|
### Added
|
|
@@ -54,6 +146,9 @@ This project attempts to follow [Keep a Changelog](https://keepachangelog.com/en
|
|
|
54
146
|
|
|
55
147
|
- For instructions on installing and configuring the new dependencies, please see the **[Editor Configuration](https://github.com/netwk-pro/netwk-pro.github.io/wiki/Editor-Configuration#automation)** section of the [Wiki](https://github.com/netwk-pro/netwk-pro.github.io/wiki).
|
|
56
148
|
|
|
149
|
+
> **Note:** Version `1.24.4` was merged but not tagged or released.
|
|
150
|
+
> Subsequent updates are reflected in `v1.24.5` and later.
|
|
151
|
+
|
|
57
152
|
---
|
|
58
153
|
|
|
59
154
|
## [1.24.4]
|
|
@@ -1515,7 +1610,9 @@ This project attempts to follow [Keep a Changelog](https://keepachangelog.com/en
|
|
|
1515
1610
|
|
|
1516
1611
|
<!-- Link references -->
|
|
1517
1612
|
|
|
1518
|
-
[Unreleased]: https://github.com/netwk-pro/netwk-pro.github.io/compare/v1.
|
|
1613
|
+
[Unreleased]: https://github.com/netwk-pro/netwk-pro.github.io/compare/v1.25.1...HEAD
|
|
1614
|
+
[1.25.1]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.25.1
|
|
1615
|
+
[1.25.0]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.25.0
|
|
1519
1616
|
[1.24.5]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.24.5
|
|
1520
1617
|
[1.24.4]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.24.4
|
|
1521
1618
|
[1.24.3]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.24.3
|
package/cspell.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@networkpro/web",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.25.1",
|
|
5
5
|
"description": "Locking Down Networks, Unlocking Confidence™ | Security, Networking, Privacy — Network Pro Strategies",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"advisory",
|
|
@@ -35,9 +35,11 @@
|
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"dev": "vite dev",
|
|
38
|
+
"dev:audit": "vite --mode audit",
|
|
38
39
|
"start": "npm run dev",
|
|
39
40
|
"dev:vercel": "vercel dev",
|
|
40
41
|
"build": "vite build",
|
|
42
|
+
"build:audit": "vite build --mode audit",
|
|
41
43
|
"build:vercel": "vercel build",
|
|
42
44
|
"preview": "vite preview",
|
|
43
45
|
"css:bundle": "node scripts/bundleCss.js",
|
package/src/hooks.server.js
CHANGED
|
@@ -6,33 +6,25 @@ SPDX-License-Identifier: CC-BY-4.0 OR GPL-3.0-or-later
|
|
|
6
6
|
This file is part of Network Pro.
|
|
7
7
|
========================================================================== */
|
|
8
8
|
|
|
9
|
+
import { detectEnvironment } from '$lib/utils/env.js';
|
|
10
|
+
|
|
9
11
|
/**
|
|
10
12
|
* SvelteKit server hook to set Content Security Policy (CSP) header.
|
|
11
13
|
* @type {import('@sveltejs/kit').Handle}
|
|
12
14
|
*/
|
|
13
15
|
export async function handle({ event, resolve }) {
|
|
14
|
-
// Create the response
|
|
15
16
|
const response = await resolve(event);
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const isTestEnvironment =
|
|
20
|
-
process.env.NODE_ENV === 'development' ||
|
|
21
|
-
process.env.ENV_MODE === 'dev' ||
|
|
22
|
-
process.env.ENV_MODE === 'ci';
|
|
23
|
-
const isProdEnvironment =
|
|
24
|
-
process.env.NODE_ENV === 'production' || process.env.ENV_MODE === 'prod';
|
|
25
|
-
|
|
26
|
-
console.log('[CSP Debug] NODE_ENV:', process.env.NODE_ENV);
|
|
27
|
-
console.log('[CSP Debug] ENV_MODE:', process.env.ENV_MODE);
|
|
18
|
+
const { isAudit, isTest, isProd, effective, mode } = detectEnvironment();
|
|
19
|
+
console.log('[CSP Debug ENV]', { mode, effective, isProd, isAudit, isTest });
|
|
28
20
|
|
|
29
21
|
// Determine report URI
|
|
30
22
|
const reportUri =
|
|
31
|
-
|
|
23
|
+
isProd && !isTest && !isAudit
|
|
32
24
|
? 'https://csp.netwk.pro/.netlify/functions/csp-report'
|
|
33
25
|
: '/api/mock-csp';
|
|
34
26
|
|
|
35
|
-
//
|
|
27
|
+
// Base hardened policy
|
|
36
28
|
const cspDirectives = [
|
|
37
29
|
"default-src 'self';",
|
|
38
30
|
"script-src 'self' 'unsafe-inline' https://us.i.posthog.com https://us-assets.i.posthog.com;",
|
|
@@ -45,40 +37,45 @@ export async function handle({ event, resolve }) {
|
|
|
45
37
|
"object-src 'none';",
|
|
46
38
|
"frame-ancestors 'none';",
|
|
47
39
|
'upgrade-insecure-requests;',
|
|
48
|
-
// Report CSP violations to external endpoint hosted at csp.netwk.pro
|
|
49
|
-
`report-uri ${reportUri};`,
|
|
50
|
-
'report-to csp-endpoint;',
|
|
51
40
|
];
|
|
52
41
|
|
|
53
|
-
//
|
|
54
|
-
if (
|
|
42
|
+
// 🧪 Looser CSP for local/CI test environments
|
|
43
|
+
if (isTest) {
|
|
55
44
|
cspDirectives[1] =
|
|
56
45
|
"script-src 'self' 'unsafe-inline' 'unsafe-eval' http://localhost:* ws://localhost:*;";
|
|
57
|
-
cspDirectives[2] =
|
|
58
|
-
|
|
59
|
-
cspDirectives[
|
|
60
|
-
cspDirectives[4] = "img-src 'self' data: http://localhost:*;";
|
|
61
|
-
cspDirectives[5] =
|
|
46
|
+
cspDirectives[2] = "style-src 'self' 'unsafe-inline' http://localhost:*;";
|
|
47
|
+
cspDirectives[3] = "img-src 'self' data: http://localhost:*;";
|
|
48
|
+
cspDirectives[4] =
|
|
62
49
|
"connect-src 'self' http://localhost:* ws://localhost:* https://us.i.posthog.com https://us-assets.i.posthog.com;";
|
|
63
50
|
}
|
|
64
51
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}),
|
|
77
|
-
);
|
|
52
|
+
// 🧩 Hardened CSP for audit environment — no analytics, no CSP reporting
|
|
53
|
+
if (isAudit) {
|
|
54
|
+
cspDirectives[1] = "script-src 'self' 'unsafe-inline';";
|
|
55
|
+
cspDirectives[2] = "style-src 'self' 'unsafe-inline';";
|
|
56
|
+
cspDirectives[3] = "img-src 'self' data:;";
|
|
57
|
+
cspDirectives[4] = "connect-src 'self';";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// 📋 Attach CSP report directives ONLY in production
|
|
61
|
+
if (isProd && !isAudit && !isTest) {
|
|
62
|
+
cspDirectives.push(`report-uri ${reportUri};`, 'report-to csp-endpoint;');
|
|
78
63
|
|
|
64
|
+
response.headers.set(
|
|
65
|
+
'Report-To',
|
|
66
|
+
JSON.stringify({
|
|
67
|
+
group: 'csp-endpoint',
|
|
68
|
+
max_age: 10886400, // 18 weeks
|
|
69
|
+
endpoints: [{ url: reportUri }],
|
|
70
|
+
include_subdomains: true,
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ✅ Apply final CSP
|
|
79
76
|
response.headers.set('Content-Security-Policy', cspDirectives.join(' '));
|
|
80
77
|
|
|
81
|
-
//
|
|
78
|
+
// Standard security headers
|
|
82
79
|
response.headers.set(
|
|
83
80
|
'Permissions-Policy',
|
|
84
81
|
[
|
|
@@ -103,10 +100,10 @@ export async function handle({ event, resolve }) {
|
|
|
103
100
|
response.headers.set('Referrer-Policy', 'strict-origin-when-cross-origin');
|
|
104
101
|
response.headers.set('X-Frame-Options', 'DENY');
|
|
105
102
|
|
|
106
|
-
if (
|
|
103
|
+
if (!isTest) {
|
|
107
104
|
response.headers.set(
|
|
108
105
|
'Strict-Transport-Security',
|
|
109
|
-
'max-age=31536000; includeSubDomains;',
|
|
106
|
+
'max-age=31536000; includeSubDomains;',
|
|
110
107
|
);
|
|
111
108
|
}
|
|
112
109
|
|
|
@@ -120,8 +117,5 @@ export async function handle({ event, resolve }) {
|
|
|
120
117
|
export function handleError({ error, event }) {
|
|
121
118
|
console.error('🔴 SSR Error in route:', event.url.pathname);
|
|
122
119
|
console.error(error);
|
|
123
|
-
|
|
124
|
-
return {
|
|
125
|
-
message: 'A server-side error occurred',
|
|
126
|
-
};
|
|
120
|
+
return { message: 'A server-side error occurred' };
|
|
127
121
|
}
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
remindUserToReconsent,
|
|
16
16
|
trackingPreferences,
|
|
17
17
|
} from '$lib/stores/trackingPreferences.js';
|
|
18
|
+
import { detectEnvironment } from '$lib/utils/env.js';
|
|
18
19
|
import { get, writable } from 'svelte/store';
|
|
19
20
|
|
|
20
21
|
/**
|
|
@@ -38,24 +39,52 @@ let ph = null;
|
|
|
38
39
|
/**
|
|
39
40
|
* Initializes the PostHog analytics client if tracking is permitted.
|
|
40
41
|
* Uses dynamic import to avoid SSR failures.
|
|
42
|
+
*
|
|
41
43
|
* @returns {Promise<void>}
|
|
42
44
|
*/
|
|
43
45
|
export async function initPostHog() {
|
|
44
46
|
if (initialized || typeof window === 'undefined') return;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
|
|
48
|
+
const { isAudit, isDev, isTest, mode, effective } = detectEnvironment();
|
|
49
|
+
|
|
50
|
+
// 🌐 Hybrid hostname + environment guard
|
|
51
|
+
const host = window.location.hostname;
|
|
52
|
+
const isAuditHost = /(^|\.)audit\.netwk\.pro$/i.test(host);
|
|
53
|
+
const effectiveAudit = isAudit || isAuditHost;
|
|
54
|
+
|
|
55
|
+
// 🧭 Log environment context before any conditional logic
|
|
56
|
+
console.info('[PostHog ENV]', {
|
|
57
|
+
buildMode: mode,
|
|
58
|
+
effectiveMode: effective,
|
|
59
|
+
host,
|
|
60
|
+
effectiveAudit,
|
|
61
|
+
isDev,
|
|
62
|
+
isTest,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// 🚫 Skip analytics in audit context
|
|
66
|
+
if (effectiveAudit) {
|
|
67
|
+
console.info(
|
|
68
|
+
`[PostHog] Skipping analytics (${effective} mode, host: ${host}).`,
|
|
69
|
+
);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 🧱 Skip entirely in dev/test contexts
|
|
74
|
+
if (isDev || isTest) {
|
|
75
|
+
console.info('[PostHog] Skipping init in dev/test mode.');
|
|
48
76
|
return;
|
|
49
77
|
}
|
|
50
78
|
|
|
79
|
+
// 🚀 Production analytics logic (with user consent)
|
|
51
80
|
initialized = true;
|
|
52
81
|
|
|
53
82
|
const { enabled } = get(trackingPreferences);
|
|
54
83
|
trackingEnabled.set(enabled);
|
|
55
|
-
showReminder.set(get(remindUserToReconsent));
|
|
84
|
+
showReminder.set(get(remindUserToReconsent));
|
|
56
85
|
|
|
57
86
|
if (!enabled) {
|
|
58
|
-
console.log('[PostHog] Tracking
|
|
87
|
+
console.log('[PostHog] Tracking disabled — user opted out.');
|
|
59
88
|
return;
|
|
60
89
|
}
|
|
61
90
|
|
|
@@ -63,6 +92,7 @@ export async function initPostHog() {
|
|
|
63
92
|
const posthogModule = await import('posthog-js');
|
|
64
93
|
ph = posthogModule.default;
|
|
65
94
|
|
|
95
|
+
// ✅ Initialize PostHog
|
|
66
96
|
// cspell:disable-next-line
|
|
67
97
|
ph.init('phc_Qshfo6AXzh4pS7aPigfqyeo4qj1qlyh7gDuHDeVMSR0', {
|
|
68
98
|
api_host: '/relay-MSR0/',
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/* ==========================================================================
|
|
2
|
+
src/lib/utils/env.js
|
|
3
|
+
|
|
4
|
+
Copyright © 2025 Network Pro Strategies (Network Pro™)
|
|
5
|
+
SPDX-License-Identifier: CC-BY-4.0 OR GPL-3.0-or-later
|
|
6
|
+
This file is part of Network Pro.
|
|
7
|
+
========================================================================== */
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @file env.js
|
|
11
|
+
* @description Unified environment detection utility.
|
|
12
|
+
* Normalizes process.env and import.meta.env for consistent behavior
|
|
13
|
+
* across SvelteKit server (SSR), client (browser), and build-time contexts.
|
|
14
|
+
*
|
|
15
|
+
* Supports: dev, prod, ci, test, audit.
|
|
16
|
+
*
|
|
17
|
+
* @module src/lib/utils
|
|
18
|
+
* @author Scott Lopez
|
|
19
|
+
* @updated 2025-11-02
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* import { detectEnvironment } from '$lib/utils/env.js';
|
|
23
|
+
* const { isAudit, isProd } = detectEnvironment();
|
|
24
|
+
* if (isAudit) console.log('Running in audit mode');
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {object} EnvironmentInfo
|
|
29
|
+
* @property {string} mode - The build-time environment mode.
|
|
30
|
+
* @property {string} effective - The environment actually being used (after host fallback).
|
|
31
|
+
* @property {boolean} isDev
|
|
32
|
+
* @property {boolean} isProd
|
|
33
|
+
* @property {boolean} isAudit
|
|
34
|
+
* @property {boolean} isCI
|
|
35
|
+
* @property {boolean} isTest
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Build-time mode injected by Vite.
|
|
40
|
+
* Always baked into the client bundle.
|
|
41
|
+
* Falls back to 'production' if nothing else is defined.
|
|
42
|
+
*/
|
|
43
|
+
export const BUILD_ENV_MODE =
|
|
44
|
+
import.meta.env.PUBLIC_ENV_MODE || import.meta.env.MODE || 'production';
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Detects the current environment, combining build-time
|
|
48
|
+
* and runtime (hostname-based) checks.
|
|
49
|
+
* Works safely in both Node and browser contexts.
|
|
50
|
+
*
|
|
51
|
+
* @returns {EnvironmentInfo}
|
|
52
|
+
*/
|
|
53
|
+
export function detectEnvironment() {
|
|
54
|
+
const mode = BUILD_ENV_MODE;
|
|
55
|
+
|
|
56
|
+
// Client-side fallback for audit/netwk environments
|
|
57
|
+
const host = typeof window !== 'undefined' ? window.location.hostname : '';
|
|
58
|
+
|
|
59
|
+
const hostIsAudit = /(^|\.)audit\.netwk\.pro$/i.test(host);
|
|
60
|
+
|
|
61
|
+
const isDev = ['development', 'dev'].includes(mode);
|
|
62
|
+
const isProd = ['production', 'prod'].includes(mode);
|
|
63
|
+
const isAudit = mode === 'audit' || hostIsAudit;
|
|
64
|
+
const isCI = mode === 'ci';
|
|
65
|
+
const isTest = mode === 'test';
|
|
66
|
+
|
|
67
|
+
// Prefer host-based detection if it disagrees with build-time
|
|
68
|
+
const effective = hostIsAudit && !isAudit ? 'audit(host)' : mode;
|
|
69
|
+
|
|
70
|
+
if (typeof window === 'undefined') {
|
|
71
|
+
// Only log on server / build to avoid client noise
|
|
72
|
+
console.log('[detectEnvironment] Build mode:', mode);
|
|
73
|
+
if (hostIsAudit && mode !== 'audit') {
|
|
74
|
+
console.log(
|
|
75
|
+
'[detectEnvironment] Host suggests audit, overriding build-time mode.',
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return { mode, effective, isDev, isProd, isAudit, isCI, isTest };
|
|
81
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* ==========================================================================
|
|
2
|
+
src/routes/api/env-check/+server.js
|
|
3
|
+
|
|
4
|
+
Copyright © 2025 Network Pro Strategies (Network Pro™)
|
|
5
|
+
SPDX-License-Identifier: CC-BY-4.0 OR GPL-3.0-or-later
|
|
6
|
+
This file is part of Network Pro.
|
|
7
|
+
========================================================================== */
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @file Returns the current environment state (client + server vars)
|
|
11
|
+
* @type {import('@sveltejs/kit').RequestHandler}
|
|
12
|
+
*/
|
|
13
|
+
export async function GET() {
|
|
14
|
+
const data = {
|
|
15
|
+
NODE_ENV: process.env.NODE_ENV,
|
|
16
|
+
ENV_MODE: process.env.ENV_MODE,
|
|
17
|
+
PUBLIC_ENV_MODE: process.env.PUBLIC_ENV_MODE,
|
|
18
|
+
IMPORT_META_MODE: import.meta.env.MODE,
|
|
19
|
+
IMPORT_META_PUBLIC: import.meta.env.PUBLIC_ENV_MODE,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return new Response(JSON.stringify(data, null, 2), {
|
|
23
|
+
headers: { 'Content-Type': 'application/json' },
|
|
24
|
+
});
|
|
25
|
+
}
|
package/src/service-worker.js
CHANGED
|
@@ -38,10 +38,11 @@ const IGNORE_PATHS = new Set([
|
|
|
38
38
|
'/pgp/contact@s.neteng.pro.asc',
|
|
39
39
|
'/pgp/github@sl.neteng.cc.asc',
|
|
40
40
|
'/pgp/security@s.neteng.pro.asc',
|
|
41
|
-
'/pgp/support@
|
|
41
|
+
'/pgp/support@netwk.pro.asc',
|
|
42
42
|
'/screenshots/desktop-foss.png',
|
|
43
43
|
'/webfonts/fa-brands-400.ttf',
|
|
44
44
|
'/webfonts/fa-solid-900.ttf',
|
|
45
|
+
'/7cbb39ce-750b-43da-83b8-8980e5554d4d.txt',
|
|
45
46
|
'/robots.txt',
|
|
46
47
|
'/sitemap.xml',
|
|
47
48
|
'/CNAME',
|
package/vite.config.js
CHANGED
|
@@ -17,20 +17,42 @@ import tsconfigPaths from 'vite-tsconfig-paths'; // NEW: tsconfig/jsconfig alias
|
|
|
17
17
|
// Compute absolute project root
|
|
18
18
|
const projectRoot = fileURLToPath(new URL('.', import.meta.url));
|
|
19
19
|
|
|
20
|
-
export default defineConfig({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
20
|
+
export default defineConfig(({ mode }) => {
|
|
21
|
+
// --- 🧩 Log Build Environment Info -------------------------------------
|
|
22
|
+
console.log(
|
|
23
|
+
'\x1b[36m%s\x1b[0m',
|
|
24
|
+
'──────────────────────────────────────────────',
|
|
25
|
+
);
|
|
26
|
+
console.log('\x1b[33m%s\x1b[0m', `📦 Building Network Pro — mode: ${mode}`);
|
|
27
|
+
console.log(
|
|
28
|
+
'\x1b[36m%s\x1b[0m',
|
|
29
|
+
'──────────────────────────────────────────────',
|
|
30
|
+
);
|
|
31
|
+
console.log('ENV_MODE:', process.env.ENV_MODE);
|
|
32
|
+
console.log('PUBLIC_ENV_MODE:', process.env.PUBLIC_ENV_MODE);
|
|
33
|
+
console.log('NODE_ENV:', process.env.NODE_ENV);
|
|
34
|
+
console.log(
|
|
35
|
+
'\x1b[36m%s\x1b[0m',
|
|
36
|
+
'──────────────────────────────────────────────',
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
// -----------------------------------------------------------------------
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
plugins: [
|
|
43
|
+
tsconfigPaths(),
|
|
44
|
+
devtoolsJson({
|
|
45
|
+
projectRoot: resolve(projectRoot),
|
|
46
|
+
normalizeForWindowsContainer: true,
|
|
47
|
+
uuid: 'ad0db4f4-6172-4c1e-ae17-26b1bee53764',
|
|
48
|
+
}),
|
|
49
|
+
sveltekit(),
|
|
50
|
+
lightningcssPlugin({
|
|
51
|
+
minify: process.env.NODE_ENV === 'production',
|
|
52
|
+
pruneUnusedFontFaceRules: true,
|
|
53
|
+
pruneUnusedKeyframes: true,
|
|
54
|
+
removeUnusedFontFaces: true,
|
|
55
|
+
}),
|
|
56
|
+
],
|
|
57
|
+
};
|
|
36
58
|
});
|