@networkpro/web 1.25.0 β 1.25.2
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/CHANGELOG.md +56 -1
- package/package.json +1 -1
- package/src/hooks.server.js +11 -2
- package/src/lib/stores/posthog.js +15 -2
- package/src/lib/utils/env.js +43 -37
- package/src/routes/status/+page.server.js +2 -2
- package/vite.config.js +47 -16
package/CHANGELOG.md
CHANGED
|
@@ -22,6 +22,58 @@ This project attempts to follow [Keep a Changelog](https://keepachangelog.com/en
|
|
|
22
22
|
|
|
23
23
|
---
|
|
24
24
|
|
|
25
|
+
## [1.25.2]
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
- **Unified Environment Detection (`env.js`)**
|
|
30
|
+
- Added support for server-side hostname injection via optional `hostOverride` parameter.
|
|
31
|
+
- Enables accurate audit environment detection on both server (`hooks.server.js`) and client.
|
|
32
|
+
- Logs the resolved environment and host when executed on the server.
|
|
33
|
+
- Maintains safe fallback behavior for client-only usage.
|
|
34
|
+
|
|
35
|
+
- **CSP Handling (`hooks.server.js`)**
|
|
36
|
+
- Replaced reliance on `window.location` (unavailable on server) with `event.url.hostname` for host detection.
|
|
37
|
+
- Now correctly applies hardened audit-mode CSP in deployments matching `*.audit.netwk.pro`.
|
|
38
|
+
- Improved logging for audit/test/prod environment resolution during server request lifecycle.
|
|
39
|
+
|
|
40
|
+
- **Build Diagnostics (`vite.config.js`)**
|
|
41
|
+
- Added `stderr` output for `audit` mode builds to ensure visibility in CI logs.
|
|
42
|
+
- Displays a prominent `π Audit Mode Detected` tag during Vercel and local builds.
|
|
43
|
+
- Continues to log `ENV_MODE`, `PUBLIC_ENV_MODE`, and `NODE_ENV` for build-time inspection.
|
|
44
|
+
|
|
45
|
+
- Bumped project version to `v1.25.2`.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## [1.25.1]
|
|
50
|
+
|
|
51
|
+
### Added
|
|
52
|
+
|
|
53
|
+
- Introduced new **environment diagnostics endpoint** at `src/routes/api/env-check/+server.js`.
|
|
54
|
+
- Returns resolved build and runtime environment data for verification.
|
|
55
|
+
- Useful for confirming `ENV_MODE` / `PUBLIC_ENV_MODE` propagation on Vercel builds.
|
|
56
|
+
- Helps troubleshoot environment mismatches between build-time and client-side contexts.
|
|
57
|
+
|
|
58
|
+
### Changed
|
|
59
|
+
|
|
60
|
+
- **vite.config.js**
|
|
61
|
+
- Enhanced configuration to log build mode and environment variables during bundling.
|
|
62
|
+
- Prints `mode`, `ENV_MODE`, `PUBLIC_ENV_MODE`, and `NODE_ENV` to aid CI/CD debugging.
|
|
63
|
+
- Uses color-coded console output for clear visibility in build logs.
|
|
64
|
+
- **env.js**
|
|
65
|
+
- Simplified and stabilized environment detection logic for better cross-environment consistency.
|
|
66
|
+
- Removed redundant imports and corrected handling of static vs dynamic `BUILD_ENV_MODE`.
|
|
67
|
+
- Improved comments and type annotations for maintainability and IDE autocompletion.
|
|
68
|
+
- Bumped project version to `v1.25.1`.
|
|
69
|
+
|
|
70
|
+
### Developer Experience
|
|
71
|
+
|
|
72
|
+
- Build logs now clearly display environment information before bundling.
|
|
73
|
+
- `env-check` API endpoint provides real-time environment inspection without rebuilding.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
25
77
|
## [1.25.0]
|
|
26
78
|
|
|
27
79
|
### Added
|
|
@@ -60,6 +112,7 @@ This project attempts to follow [Keep a Changelog](https://keepachangelog.com/en
|
|
|
60
112
|
- Simplified step output and summary formatting for clearer reporting in the Actions log and job summary.
|
|
61
113
|
- Maintains lightweight permissions (`contents: read`) and executes entirely without repository writes.
|
|
62
114
|
- Improves reliability of branch protection monitoring without affecting CI or merge operations.
|
|
115
|
+
- Bumped project version to `v1.25.0`.
|
|
63
116
|
|
|
64
117
|
### Fixed
|
|
65
118
|
|
|
@@ -1583,7 +1636,9 @@ This enables analytics filtering and CSP hardening for the audit environment.
|
|
|
1583
1636
|
|
|
1584
1637
|
<!-- Link references -->
|
|
1585
1638
|
|
|
1586
|
-
[Unreleased]: https://github.com/netwk-pro/netwk-pro.github.io/compare/v1.25.
|
|
1639
|
+
[Unreleased]: https://github.com/netwk-pro/netwk-pro.github.io/compare/v1.25.2...HEAD
|
|
1640
|
+
[1.25.2]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.25.2
|
|
1641
|
+
[1.25.1]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.25.1
|
|
1587
1642
|
[1.25.0]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.25.0
|
|
1588
1643
|
[1.24.5]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.24.5
|
|
1589
1644
|
[1.24.4]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.24.4
|
package/package.json
CHANGED
package/src/hooks.server.js
CHANGED
|
@@ -14,9 +14,18 @@ import { detectEnvironment } from '$lib/utils/env.js';
|
|
|
14
14
|
*/
|
|
15
15
|
export async function handle({ event, resolve }) {
|
|
16
16
|
const response = await resolve(event);
|
|
17
|
-
const { isAudit, isTest, isProd } = detectEnvironment();
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
const env = detectEnvironment(event.url.hostname);
|
|
19
|
+
const { isAudit, isTest, isProd, mode, effective } = env;
|
|
20
|
+
|
|
21
|
+
console.log('[CSP Debug ENV]', {
|
|
22
|
+
mode,
|
|
23
|
+
effective,
|
|
24
|
+
hostname: event.url.hostname,
|
|
25
|
+
isAudit,
|
|
26
|
+
isTest,
|
|
27
|
+
isProd,
|
|
28
|
+
});
|
|
20
29
|
|
|
21
30
|
// Determine report URI
|
|
22
31
|
const reportUri =
|
|
@@ -45,15 +45,28 @@ 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 } = detectEnvironment();
|
|
48
|
+
const { isAudit, isDev, isTest, mode, effective } = detectEnvironment();
|
|
49
49
|
|
|
50
50
|
// π Hybrid hostname + environment guard
|
|
51
51
|
const host = window.location.hostname;
|
|
52
52
|
const isAuditHost = /(^|\.)audit\.netwk\.pro$/i.test(host);
|
|
53
53
|
const effectiveAudit = isAudit || isAuditHost;
|
|
54
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
|
|
55
66
|
if (effectiveAudit) {
|
|
56
|
-
console.info(
|
|
67
|
+
console.info(
|
|
68
|
+
`[PostHog] Skipping analytics (${effective} mode, host: ${host}).`,
|
|
69
|
+
);
|
|
57
70
|
return;
|
|
58
71
|
}
|
|
59
72
|
|
package/src/lib/utils/env.js
CHANGED
|
@@ -16,7 +16,7 @@ This file is part of Network Pro.
|
|
|
16
16
|
*
|
|
17
17
|
* @module src/lib/utils
|
|
18
18
|
* @author Scott Lopez
|
|
19
|
-
* @updated 2025-11-
|
|
19
|
+
* @updated 2025-11-03
|
|
20
20
|
*
|
|
21
21
|
* @example
|
|
22
22
|
* import { detectEnvironment } from '$lib/utils/env.js';
|
|
@@ -26,49 +26,55 @@ This file is part of Network Pro.
|
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* @typedef {object} EnvironmentInfo
|
|
29
|
-
* @property {string} mode
|
|
30
|
-
* @property {
|
|
31
|
-
* @property {boolean}
|
|
32
|
-
* @property {boolean}
|
|
33
|
-
* @property {boolean}
|
|
34
|
-
* @property {boolean}
|
|
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
|
|
35
36
|
*/
|
|
36
37
|
|
|
37
38
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
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 and host-based checks.
|
|
48
|
+
* Supports browser, server, and build-time contexts.
|
|
40
49
|
*
|
|
41
|
-
* @
|
|
50
|
+
* @param {string} [hostOverride] Optional hostname to use for environment resolution (e.g., from event.url.hostname)
|
|
51
|
+
* @returns {EnvironmentInfo}
|
|
42
52
|
*/
|
|
43
|
-
export function detectEnvironment() {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const
|
|
53
|
+
export function detectEnvironment(hostOverride) {
|
|
54
|
+
const mode = BUILD_ENV_MODE;
|
|
55
|
+
|
|
56
|
+
// Determine host based on execution context
|
|
57
|
+
const host =
|
|
58
|
+
hostOverride ||
|
|
59
|
+
(typeof window !== 'undefined' ? window.location.hostname : '');
|
|
60
|
+
|
|
61
|
+
const hostIsAudit = /(^|\.)audit\.netwk\.pro$/i.test(host);
|
|
48
62
|
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
63
|
+
const isDev = ['development', 'dev'].includes(mode);
|
|
64
|
+
const isProd = ['production', 'prod'].includes(mode);
|
|
65
|
+
const isAudit = mode === 'audit' || hostIsAudit;
|
|
66
|
+
const isCI = mode === 'ci';
|
|
67
|
+
const isTest = mode === 'test';
|
|
54
68
|
|
|
55
|
-
|
|
56
|
-
const envMode =
|
|
57
|
-
typeof process !== 'undefined' && process?.env?.ENV_MODE
|
|
58
|
-
? process.env.ENV_MODE
|
|
59
|
-
: undefined;
|
|
69
|
+
const effective = hostIsAudit && !isAudit ? 'audit(host)' : mode;
|
|
60
70
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
71
|
+
if (typeof window === 'undefined') {
|
|
72
|
+
console.log('[detectEnvironment] Server-side build mode:', mode);
|
|
73
|
+
console.log('[detectEnvironment] Hostname:', host || '(none)');
|
|
74
|
+
if (hostIsAudit && mode !== 'audit') {
|
|
75
|
+
console.log('[detectEnvironment] Host suggests audit, overriding mode.');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
64
78
|
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
mode,
|
|
68
|
-
isDev: ['development', 'dev'].includes(mode),
|
|
69
|
-
isProd: ['production', 'prod'].includes(mode),
|
|
70
|
-
isAudit: mode === 'audit',
|
|
71
|
-
isCI: mode === 'ci',
|
|
72
|
-
isTest: mode === 'test',
|
|
73
|
-
};
|
|
79
|
+
return { mode, effective, isDev, isProd, isAudit, isCI, isTest };
|
|
74
80
|
}
|
|
@@ -12,11 +12,11 @@ This file is part of Network Pro.
|
|
|
12
12
|
* Logs runtime environment variables for debugging purposes.
|
|
13
13
|
* This function executes on the server during SSR and is used to verify
|
|
14
14
|
* that environment variables (e.g., ENV_MODE and NODE_ENV) are properly
|
|
15
|
-
* injected and available during runtime in
|
|
15
|
+
* injected and available during runtime in Vercel's SSR context.
|
|
16
16
|
*
|
|
17
17
|
* @module src/routes/status
|
|
18
18
|
* @author Scott Lopez
|
|
19
|
-
* @updated 2025-
|
|
19
|
+
* @updated 2025-11-03
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
export const prerender = false;
|
package/vite.config.js
CHANGED
|
@@ -17,20 +17,51 @@ 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
|
+
if (
|
|
35
|
+
process.env.ENV_MODE === 'audit' ||
|
|
36
|
+
process.env.PUBLIC_ENV_MODE === 'audit' ||
|
|
37
|
+
mode === 'audit'
|
|
38
|
+
) {
|
|
39
|
+
process.stderr.write(
|
|
40
|
+
'π Audit Mode Detected β hardened CSP and no analytics will be applied.\n',
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
console.log(
|
|
44
|
+
'\x1b[36m%s\x1b[0m',
|
|
45
|
+
'ββββββββββββββββββββββββββββββββββββββββββββββ',
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
// -----------------------------------------------------------------------
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
plugins: [
|
|
52
|
+
tsconfigPaths(),
|
|
53
|
+
devtoolsJson({
|
|
54
|
+
projectRoot: resolve(projectRoot),
|
|
55
|
+
normalizeForWindowsContainer: true,
|
|
56
|
+
uuid: 'ad0db4f4-6172-4c1e-ae17-26b1bee53764',
|
|
57
|
+
}),
|
|
58
|
+
sveltekit(),
|
|
59
|
+
lightningcssPlugin({
|
|
60
|
+
minify: process.env.NODE_ENV === 'production',
|
|
61
|
+
pruneUnusedFontFaceRules: true,
|
|
62
|
+
pruneUnusedKeyframes: true,
|
|
63
|
+
removeUnusedFontFaces: true,
|
|
64
|
+
}),
|
|
65
|
+
],
|
|
66
|
+
};
|
|
36
67
|
});
|