@networkpro/web 1.25.2 → 1.25.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/.env.template +1 -1
- package/CHANGELOG.md +56 -4
- package/package.json +2 -2
- package/src/hooks.server.js +14 -11
- package/src/lib/stores/posthog.js +23 -12
- package/src/lib/utils/env.js +21 -6
- package/vite.config.js +2 -1
- package/.github/workflows/branch-guard.yml +0 -53
package/.env.template
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# Rename to `.env` (or `.env.local`) and customize as needed
|
|
6
6
|
|
|
7
7
|
# Custom environment mode for scripts and tooling
|
|
8
|
-
# One of: dev, test, ci, preview,
|
|
8
|
+
# One of: dev, test, ci, preview, production
|
|
9
9
|
ENV_MODE=dev
|
|
10
10
|
|
|
11
11
|
# Optional: API keys or tokens for local dev (never commit real values)
|
package/CHANGELOG.md
CHANGED
|
@@ -22,7 +22,57 @@ This project attempts to follow [Keep a Changelog](https://keepachangelog.com/en
|
|
|
22
22
|
|
|
23
23
|
---
|
|
24
24
|
|
|
25
|
-
## [1.25.
|
|
25
|
+
## [1.25.4] - 2025-11-03
|
|
26
|
+
|
|
27
|
+
### Added
|
|
28
|
+
|
|
29
|
+
- `detectEnvironment()` now returns:
|
|
30
|
+
- `isDebug` boolean (true if `isDev` or `isTest`)
|
|
31
|
+
- `isLocalhost` (optional, in browser contexts)
|
|
32
|
+
- Support for `PUBLIC_POSTHOG_PROJECT_KEY` using `import.meta.env`
|
|
33
|
+
- Dynamic PostHog initialization (`initPostHog`) now uses env-based key injection
|
|
34
|
+
- vite.config.js:
|
|
35
|
+
- `envPrefix: ['PUBLIC_']` added to expose public vars to client
|
|
36
|
+
- Console banner for `ENV_MODE`, `PUBLIC_ENV_MODE`, and audit-mode warning
|
|
37
|
+
- CSP debug logs gated behind `isDebug` and server-only context
|
|
38
|
+
- `.env.production` support via `--mode=production` guidance
|
|
39
|
+
- Conditional `minify` flag for `lightningcssPlugin` based on `mode` (`production` or `audit`)
|
|
40
|
+
|
|
41
|
+
### Changed
|
|
42
|
+
|
|
43
|
+
- Environment detection (`env.js`) now respects hostname overrides and normalizes fallback logic for SSR/client consistency
|
|
44
|
+
- Logs in `hooks.server.js` and PostHog analytics client are now gated by `isDebug` to avoid unnecessary noise in production
|
|
45
|
+
- Better logging structure for PostHog initialization, including full `import.meta.env` dump in debug mode
|
|
46
|
+
- Bumped project version to `v1.25.4`
|
|
47
|
+
|
|
48
|
+
### Fixed
|
|
49
|
+
|
|
50
|
+
- Broken or undefined env var behavior due to missing `envPrefix` in `vite.config.js`
|
|
51
|
+
- Client-only `import.meta.env.PUBLIC_*` variables incorrectly resolving as `undefined` in production builds
|
|
52
|
+
- CSP not reflecting audit context due to host-based detection mismatch
|
|
53
|
+
|
|
54
|
+
### Developer Notes
|
|
55
|
+
|
|
56
|
+
- `.env.production` is **now required** for full environment variable injection during `npm run build --mode=production` or Vercel deployments.
|
|
57
|
+
- Without it, `PUBLIC_` variables (e.g. `PUBLIC_POSTHOG_PROJECT_KEY`) may resolve as undefined in the client bundle.
|
|
58
|
+
- Local builds can still fall back to `.env` or `.env.development` by default.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## [1.25.3] - 2025-11-03
|
|
63
|
+
|
|
64
|
+
### Changed
|
|
65
|
+
|
|
66
|
+
- Updated `posthog.js` to display environmental context logs only in development and testing environments.
|
|
67
|
+
- Bumped project version to `v1.25.3`.
|
|
68
|
+
|
|
69
|
+
### Removed
|
|
70
|
+
|
|
71
|
+
- Removed **Branch Guard** workflow (`.github/workflows/branch-guard.yml`), as it was resulting in mostly false positives.
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## [1.25.2] - 2025-11-03
|
|
26
76
|
|
|
27
77
|
### Changed
|
|
28
78
|
|
|
@@ -46,7 +96,7 @@ This project attempts to follow [Keep a Changelog](https://keepachangelog.com/en
|
|
|
46
96
|
|
|
47
97
|
---
|
|
48
98
|
|
|
49
|
-
## [1.25.1]
|
|
99
|
+
## [1.25.1] - 2025-11-02
|
|
50
100
|
|
|
51
101
|
### Added
|
|
52
102
|
|
|
@@ -74,7 +124,7 @@ This project attempts to follow [Keep a Changelog](https://keepachangelog.com/en
|
|
|
74
124
|
|
|
75
125
|
---
|
|
76
126
|
|
|
77
|
-
## [1.25.0]
|
|
127
|
+
## [1.25.0] - 2025-11-02
|
|
78
128
|
|
|
79
129
|
### Added
|
|
80
130
|
|
|
@@ -1636,7 +1686,9 @@ This enables analytics filtering and CSP hardening for the audit environment.
|
|
|
1636
1686
|
|
|
1637
1687
|
<!-- Link references -->
|
|
1638
1688
|
|
|
1639
|
-
[Unreleased]: https://github.com/netwk-pro/netwk-pro.github.io/compare/v1.25.
|
|
1689
|
+
[Unreleased]: https://github.com/netwk-pro/netwk-pro.github.io/compare/v1.25.4...HEAD
|
|
1690
|
+
[1.25.4]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.25.4
|
|
1691
|
+
[1.25.3]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.25.3
|
|
1640
1692
|
[1.25.2]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.25.2
|
|
1641
1693
|
[1.25.1]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.25.1
|
|
1642
1694
|
[1.25.0]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.25.0
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@networkpro/web",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.25.
|
|
4
|
+
"version": "1.25.4",
|
|
5
5
|
"description": "Locking Down Networks, Unlocking Confidence™ | Security, Networking, Privacy — Network Pro Strategies",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"advisory",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"dev:audit": "vite --mode audit",
|
|
39
39
|
"start": "npm run dev",
|
|
40
40
|
"dev:vercel": "vercel dev",
|
|
41
|
-
"build": "vite build",
|
|
41
|
+
"build": "vite build --mode production",
|
|
42
42
|
"build:audit": "vite build --mode audit",
|
|
43
43
|
"build:vercel": "vercel build",
|
|
44
44
|
"preview": "vite preview",
|
package/src/hooks.server.js
CHANGED
|
@@ -16,16 +16,19 @@ export async function handle({ event, resolve }) {
|
|
|
16
16
|
const response = await resolve(event);
|
|
17
17
|
|
|
18
18
|
const env = detectEnvironment(event.url.hostname);
|
|
19
|
-
const { isAudit, isTest, isProd, mode, effective } = env;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
const { isAudit, isDebug, isTest, isProd, mode, effective } = env;
|
|
20
|
+
|
|
21
|
+
// Show logs in dev only
|
|
22
|
+
if (isDebug) {
|
|
23
|
+
console.log('[CSP Debug ENV]', {
|
|
24
|
+
mode,
|
|
25
|
+
effective,
|
|
26
|
+
hostname: event.url.hostname,
|
|
27
|
+
isAudit,
|
|
28
|
+
isTest,
|
|
29
|
+
isProd,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
29
32
|
|
|
30
33
|
// Determine report URI
|
|
31
34
|
const reportUri =
|
|
@@ -49,7 +52,7 @@ export async function handle({ event, resolve }) {
|
|
|
49
52
|
];
|
|
50
53
|
|
|
51
54
|
// 🧪 Looser CSP for local/CI test environments
|
|
52
|
-
if (
|
|
55
|
+
if (isDebug) {
|
|
53
56
|
cspDirectives[1] =
|
|
54
57
|
"script-src 'self' 'unsafe-inline' 'unsafe-eval' http://localhost:* ws://localhost:*;";
|
|
55
58
|
cspDirectives[2] = "style-src 'self' 'unsafe-inline' http://localhost:*;";
|
|
@@ -45,7 +45,8 @@ let ph = null;
|
|
|
45
45
|
export async function initPostHog() {
|
|
46
46
|
if (initialized || typeof window === 'undefined') return;
|
|
47
47
|
|
|
48
|
-
const { isAudit, isDev, isTest, mode, effective } =
|
|
48
|
+
const { isAudit, isDebug, isDev, isTest, mode, effective } =
|
|
49
|
+
detectEnvironment();
|
|
49
50
|
|
|
50
51
|
// 🌐 Hybrid hostname + environment guard
|
|
51
52
|
const host = window.location.hostname;
|
|
@@ -53,14 +54,16 @@ export async function initPostHog() {
|
|
|
53
54
|
const effectiveAudit = isAudit || isAuditHost;
|
|
54
55
|
|
|
55
56
|
// 🧭 Log environment context before any conditional logic
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
if (isDebug) {
|
|
58
|
+
console.info('[PostHog ENV]', {
|
|
59
|
+
buildMode: mode,
|
|
60
|
+
effectiveMode: effective,
|
|
61
|
+
host,
|
|
62
|
+
effectiveAudit,
|
|
63
|
+
isDev,
|
|
64
|
+
isTest,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
64
67
|
|
|
65
68
|
// 🚫 Skip analytics in audit context
|
|
66
69
|
if (effectiveAudit) {
|
|
@@ -71,7 +74,7 @@ export async function initPostHog() {
|
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
// 🧱 Skip entirely in dev/test contexts
|
|
74
|
-
if (
|
|
77
|
+
if (isDebug) {
|
|
75
78
|
console.info('[PostHog] Skipping init in dev/test mode.');
|
|
76
79
|
return;
|
|
77
80
|
}
|
|
@@ -92,9 +95,17 @@ export async function initPostHog() {
|
|
|
92
95
|
const posthogModule = await import('posthog-js');
|
|
93
96
|
ph = posthogModule.default;
|
|
94
97
|
|
|
98
|
+
// ✅ Load public key from env
|
|
99
|
+
const key = import.meta.env.PUBLIC_POSTHOG_PROJECT_KEY;
|
|
100
|
+
//console.log('✅ Key in runtime:', key);
|
|
101
|
+
|
|
102
|
+
if (!key) {
|
|
103
|
+
console.warn('[PostHog] ⚠️ PUBLIC_POSTHOG_PROJECT_KEY is not set.');
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
95
107
|
// ✅ Initialize PostHog
|
|
96
|
-
|
|
97
|
-
ph.init('phc_Qshfo6AXzh4pS7aPigfqyeo4qj1qlyh7gDuHDeVMSR0', {
|
|
108
|
+
ph.init(key, {
|
|
98
109
|
api_host: '/relay-MSR0/',
|
|
99
110
|
ui_host: 'https://us.posthog.com',
|
|
100
111
|
autocapture: true,
|
package/src/lib/utils/env.js
CHANGED
|
@@ -33,6 +33,8 @@ This file is part of Network Pro.
|
|
|
33
33
|
* @property {boolean} isAudit
|
|
34
34
|
* @property {boolean} isCI
|
|
35
35
|
* @property {boolean} isTest
|
|
36
|
+
* @property {boolean} isDebug - True in dev or test mode (but not prod/audit)
|
|
37
|
+
* @property {boolean} isLocalhost - True if running on localhost (client context only)
|
|
36
38
|
*/
|
|
37
39
|
|
|
38
40
|
/**
|
|
@@ -51,7 +53,7 @@ export const BUILD_ENV_MODE =
|
|
|
51
53
|
* @returns {EnvironmentInfo}
|
|
52
54
|
*/
|
|
53
55
|
export function detectEnvironment(hostOverride) {
|
|
54
|
-
const mode = BUILD_ENV_MODE;
|
|
56
|
+
const mode = (BUILD_ENV_MODE || '').toLowerCase();
|
|
55
57
|
|
|
56
58
|
// Determine host based on execution context
|
|
57
59
|
const host =
|
|
@@ -59,22 +61,35 @@ export function detectEnvironment(hostOverride) {
|
|
|
59
61
|
(typeof window !== 'undefined' ? window.location.hostname : '');
|
|
60
62
|
|
|
61
63
|
const hostIsAudit = /(^|\.)audit\.netwk\.pro$/i.test(host);
|
|
64
|
+
const isLocalhost = /^localhost$|^127\.0\.0\.1$/.test(host);
|
|
62
65
|
|
|
63
66
|
const isDev = ['development', 'dev'].includes(mode);
|
|
64
67
|
const isProd = ['production', 'prod'].includes(mode);
|
|
65
68
|
const isAudit = mode === 'audit' || hostIsAudit;
|
|
66
69
|
const isCI = mode === 'ci';
|
|
67
70
|
const isTest = mode === 'test';
|
|
71
|
+
const isDebug = isDev || isTest;
|
|
68
72
|
|
|
69
73
|
const effective = hostIsAudit && !isAudit ? 'audit(host)' : mode;
|
|
70
74
|
|
|
71
|
-
if (typeof window === 'undefined') {
|
|
72
|
-
console.log('[
|
|
73
|
-
console.log('[
|
|
75
|
+
if (typeof window === 'undefined' && isDebug) {
|
|
76
|
+
console.log('🧭 [env] Server-side build mode:', mode);
|
|
77
|
+
console.log('🧭 [env] Hostname:', host || '(none)');
|
|
78
|
+
console.log('🧭 [env] Raw env:', import.meta.env);
|
|
74
79
|
if (hostIsAudit && mode !== 'audit') {
|
|
75
|
-
console.log('[
|
|
80
|
+
console.log('[env] Host suggests audit, overriding mode.');
|
|
76
81
|
}
|
|
77
82
|
}
|
|
78
83
|
|
|
79
|
-
return {
|
|
84
|
+
return {
|
|
85
|
+
mode,
|
|
86
|
+
effective,
|
|
87
|
+
isDev,
|
|
88
|
+
isProd,
|
|
89
|
+
isAudit,
|
|
90
|
+
isCI,
|
|
91
|
+
isTest,
|
|
92
|
+
isDebug,
|
|
93
|
+
isLocalhost,
|
|
94
|
+
};
|
|
80
95
|
}
|
package/vite.config.js
CHANGED
|
@@ -48,6 +48,7 @@ export default defineConfig(({ mode }) => {
|
|
|
48
48
|
// -----------------------------------------------------------------------
|
|
49
49
|
|
|
50
50
|
return {
|
|
51
|
+
envPrefix: ['PUBLIC_'],
|
|
51
52
|
plugins: [
|
|
52
53
|
tsconfigPaths(),
|
|
53
54
|
devtoolsJson({
|
|
@@ -57,7 +58,7 @@ export default defineConfig(({ mode }) => {
|
|
|
57
58
|
}),
|
|
58
59
|
sveltekit(),
|
|
59
60
|
lightningcssPlugin({
|
|
60
|
-
minify:
|
|
61
|
+
minify: ['production', 'audit'].includes(mode),
|
|
61
62
|
pruneUnusedFontFaceRules: true,
|
|
62
63
|
pruneUnusedKeyframes: true,
|
|
63
64
|
removeUnusedFontFaces: true,
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# .github/workflows/branch-guard.yml
|
|
2
|
-
#
|
|
3
|
-
# Copyright © 2025 Network Pro Strategies (Network Pro™)
|
|
4
|
-
# SPDX-License-Identifier: CC-BY-4.0 OR GPL-3.0-or-later
|
|
5
|
-
# This file is part of Network Pro
|
|
6
|
-
#
|
|
7
|
-
# Warns if commits are pushed directly to master/main instead of via PR.
|
|
8
|
-
# Does NOT block the commit — it just posts a workflow summary and log warning.
|
|
9
|
-
|
|
10
|
-
name: Branch Guard
|
|
11
|
-
|
|
12
|
-
on:
|
|
13
|
-
push:
|
|
14
|
-
branches:
|
|
15
|
-
- master
|
|
16
|
-
- main
|
|
17
|
-
|
|
18
|
-
permissions:
|
|
19
|
-
contents: read
|
|
20
|
-
|
|
21
|
-
jobs:
|
|
22
|
-
warn-direct-commit:
|
|
23
|
-
runs-on: ubuntu-24.04
|
|
24
|
-
steps:
|
|
25
|
-
- name: Check commit source
|
|
26
|
-
run: |
|
|
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
|
|
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
|