@networkpro/web 1.25.0 → 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/CHANGELOG.md CHANGED
@@ -22,6 +22,33 @@ 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
+
25
52
  ## [1.25.0]
26
53
 
27
54
  ### Added
@@ -1583,7 +1610,8 @@ This enables analytics filtering and CSP hardening for the audit environment.
1583
1610
 
1584
1611
  <!-- Link references -->
1585
1612
 
1586
- [Unreleased]: https://github.com/netwk-pro/netwk-pro.github.io/compare/v1.25.0...HEAD
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
1587
1615
  [1.25.0]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.25.0
1588
1616
  [1.24.5]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.24.5
1589
1617
  [1.24.4]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.24.4
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@networkpro/web",
3
3
  "private": false,
4
- "version": "1.25.0",
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",
@@ -14,9 +14,9 @@ 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
- console.log('[CSP Debug ENV]', detectEnvironment());
18
+ const { isAudit, isTest, isProd, effective, mode } = detectEnvironment();
19
+ console.log('[CSP Debug ENV]', { mode, effective, isProd, isAudit, isTest });
20
20
 
21
21
  // Determine report URI
22
22
  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(`[PostHog] Skipping analytics (${mode} mode, host: ${host}).`);
67
+ console.info(
68
+ `[PostHog] Skipping analytics (${effective} mode, host: ${host}).`,
69
+ );
57
70
  return;
58
71
  }
59
72
 
@@ -26,49 +26,56 @@ This file is part of Network Pro.
26
26
 
27
27
  /**
28
28
  * @typedef {object} EnvironmentInfo
29
- * @property {string} mode - The detected environment mode (`dev`, `prod`, `audit`, etc.).
30
- * @property {boolean} isDev - True when running in a development or local environment.
31
- * @property {boolean} isProd - True when running in production.
32
- * @property {boolean} isAudit - True when running in audit / staging environments.
33
- * @property {boolean} isCI - True when running in continuous integration (CI) pipelines.
34
- * @property {boolean} isTest - True when running under test or mock environments.
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
- * Normalizes environment detection across client, SSR, and build contexts.
39
- * Uses `import.meta.env` for Vite build-time vars and `process.env` for runtime vars.
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.
40
50
  *
41
- * @returns {EnvironmentInfo} Normalized environment context flags.
51
+ * @returns {EnvironmentInfo}
42
52
  */
43
53
  export function detectEnvironment() {
44
- /** @type {string | undefined} */
45
- const viteMode = import.meta.env?.MODE;
46
- /** @type {string | undefined} */
47
- const publicEnvMode = import.meta.env?.PUBLIC_ENV_MODE;
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);
48
60
 
49
- /** @type {string | undefined} */
50
- const nodeEnv =
51
- typeof process !== 'undefined' && process?.env?.NODE_ENV
52
- ? process.env.NODE_ENV
53
- : undefined;
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';
54
66
 
55
- /** @type {string | undefined} */
56
- const envMode =
57
- typeof process !== 'undefined' && process?.env?.ENV_MODE
58
- ? process.env.ENV_MODE
59
- : undefined;
67
+ // Prefer host-based detection if it disagrees with build-time
68
+ const effective = hostIsAudit && !isAudit ? 'audit(host)' : mode;
60
69
 
61
- // Fallback order guarantees a mode string even if nothing is set
62
- /** @type {string} */
63
- const mode = envMode || publicEnvMode || viteMode || nodeEnv || 'unknown';
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
+ }
64
79
 
65
- // Return a normalized, typed object
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
- };
80
+ return { mode, effective, isDev, isProd, isAudit, isCI, isTest };
74
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/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
- plugins: [
22
- tsconfigPaths(), // Insert before sveltekit()
23
- devtoolsJson({
24
- projectRoot: resolve(projectRoot), // Correct key name
25
- normalizeForWindowsContainer: true, // optional, helps with path consistency on Windows or WSL
26
- uuid: 'ad0db4f4-6172-4c1e-ae17-26b1bee53764',
27
- }),
28
- sveltekit(),
29
- lightningcssPlugin({
30
- minify: process.env.NODE_ENV === 'production',
31
- pruneUnusedFontFaceRules: true,
32
- pruneUnusedKeyframes: true,
33
- removeUnusedFontFaces: true,
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
  });