pi-kiosk-shared 1.0.4 → 1.0.7

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.
@@ -4,9 +4,28 @@ export interface EnvironmentConfig {
4
4
  wsUrl: string;
5
5
  enableMockPayments: boolean;
6
6
  paymentAccountNumber: string;
7
+ paymentMode: 'mock' | 'sandbox' | 'production';
7
8
  showDebugInfo: boolean;
9
+ logLevel: 'debug' | 'info' | 'warn' | 'error';
10
+ kioskUrl: string;
11
+ adminUrl: string;
12
+ backendUrl: string;
8
13
  }
9
14
  export declare const getCurrentEnvironment: () => Environment;
10
15
  export declare const getEnvironmentConfig: () => EnvironmentConfig;
11
16
  export declare const isDevelopment: () => boolean;
12
17
  export declare const isProduction: () => boolean;
18
+ export declare const getBackendUrl: () => string;
19
+ export declare const getKioskUrl: () => string;
20
+ export declare const getAdminUrl: () => string;
21
+ export declare const getApiUrl: () => string;
22
+ export declare const getWsUrl: () => string;
23
+ export declare const getPaymentConfig: () => {
24
+ enableMockPayments: boolean;
25
+ paymentAccountNumber: string;
26
+ paymentMode: "production" | "mock" | "sandbox";
27
+ };
28
+ export declare const getUIConfig: () => {
29
+ showDebugInfo: boolean;
30
+ logLevel: "debug" | "info" | "warn" | "error";
31
+ };
@@ -1,38 +1,111 @@
1
1
  "use strict";
2
- // Simple environment configuration
2
+ // Centralized environment configuration for all services
3
+ // This ensures consistency across backend, kiosk, and admin apps
3
4
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.isProduction = exports.isDevelopment = exports.getEnvironmentConfig = exports.getCurrentEnvironment = void 0;
5
+ exports.getUIConfig = exports.getPaymentConfig = exports.getWsUrl = exports.getApiUrl = exports.getAdminUrl = exports.getKioskUrl = exports.getBackendUrl = exports.isProduction = exports.isDevelopment = exports.getEnvironmentConfig = exports.getCurrentEnvironment = void 0;
5
6
  // Helper function to get environment variables dynamically
6
7
  function getEnvVar(key, defaultValue) {
7
- return process.env[key] || defaultValue;
8
+ // Try to get from process.env (Node.js) or import.meta.env (Vite)
9
+ let value;
10
+ // Check for process.env (Node.js environment)
11
+ if (typeof process !== 'undefined' && process.env) {
12
+ value = process.env[key];
13
+ }
14
+ // If not found and we're in a browser, try to access Vite's environment
15
+ if (!value && typeof window !== 'undefined') {
16
+ try {
17
+ // Use eval to access import.meta at runtime (not at parse time)
18
+ // @ts-ignore
19
+ const viteEnv = eval('typeof import !== "undefined" && import.meta && import.meta.env');
20
+ if (viteEnv && typeof viteEnv === 'object') {
21
+ value = viteEnv[key];
22
+ }
23
+ }
24
+ catch (e) {
25
+ // Ignore errors, fall back to default
26
+ }
27
+ }
28
+ return value || defaultValue;
8
29
  }
9
30
  function getEnvBool(key, defaultValue) {
10
- return process.env[key] === 'true' || defaultValue;
31
+ const value = getEnvVar(key, defaultValue.toString());
32
+ return value === 'true';
11
33
  }
34
+ // Centralized service URLs configuration
35
+ const SERVICE_URLS = {
36
+ development: {
37
+ backend: 'http://localhost:3015',
38
+ kiosk: 'http://localhost:3000',
39
+ admin: 'http://localhost:3001',
40
+ },
41
+ production: {
42
+ backend: 'https://rpapp-bckend-production.up.railway.app',
43
+ kiosk: 'https://rpapp-kiosk-production.up.railway.app',
44
+ admin: 'https://extraordinary-healing-production-88f4.up.railway.app',
45
+ }
46
+ };
12
47
  // Get environment configuration dynamically
13
48
  function getConfigForEnvironment(env) {
49
+ const urls = SERVICE_URLS[env];
14
50
  if (env === 'development') {
15
51
  return {
16
- apiUrl: getEnvVar('REACT_APP_API_URL', 'http://localhost:3015'),
17
- wsUrl: getEnvVar('REACT_APP_WS_URL', 'ws://localhost:3015'),
52
+ // API Configuration
53
+ apiUrl: getEnvVar('REACT_APP_API_URL', urls.backend),
54
+ wsUrl: getEnvVar('REACT_APP_WS_URL', urls.backend.replace('http', 'ws')),
55
+ // Payment Configuration
18
56
  enableMockPayments: getEnvBool('REACT_APP_ENABLE_MOCK_PAYMENTS', true),
19
57
  paymentAccountNumber: getEnvVar('REACT_APP_PAYMENT_ACCOUNT', '1234567890'),
58
+ paymentMode: getEnvVar('REACT_APP_PAYMENT_MODE', 'mock'),
59
+ // UI Configuration
20
60
  showDebugInfo: getEnvBool('REACT_APP_SHOW_DEBUG_INFO', true),
61
+ logLevel: getEnvVar('REACT_APP_LOG_LEVEL', 'debug'),
62
+ // Service URLs
63
+ kioskUrl: getEnvVar('REACT_APP_KIOSK_URL', urls.kiosk),
64
+ adminUrl: getEnvVar('REACT_APP_ADMIN_URL', urls.admin),
65
+ backendUrl: getEnvVar('REACT_APP_BACKEND_URL', urls.backend),
21
66
  };
22
67
  }
23
68
  else {
24
69
  return {
25
- apiUrl: getEnvVar('REACT_APP_API_URL', 'https://kiosk-prod.railway.app'),
26
- wsUrl: getEnvVar('REACT_APP_WS_URL', 'wss://kiosk-prod.railway.app'),
70
+ // API Configuration
71
+ apiUrl: getEnvVar('REACT_APP_API_URL', urls.backend),
72
+ wsUrl: getEnvVar('REACT_APP_WS_URL', urls.backend.replace('https', 'wss')),
73
+ // Payment Configuration
27
74
  enableMockPayments: getEnvBool('REACT_APP_ENABLE_MOCK_PAYMENTS', false),
28
75
  paymentAccountNumber: getEnvVar('REACT_APP_PAYMENT_ACCOUNT', '1234567890'),
76
+ paymentMode: getEnvVar('REACT_APP_PAYMENT_MODE', 'production'),
77
+ // UI Configuration
29
78
  showDebugInfo: getEnvBool('REACT_APP_SHOW_DEBUG_INFO', false),
79
+ logLevel: getEnvVar('REACT_APP_LOG_LEVEL', 'warn'),
80
+ // Service URLs
81
+ kioskUrl: getEnvVar('REACT_APP_KIOSK_URL', urls.kiosk),
82
+ adminUrl: getEnvVar('REACT_APP_ADMIN_URL', urls.admin),
83
+ backendUrl: getEnvVar('REACT_APP_BACKEND_URL', urls.backend),
30
84
  };
31
85
  }
32
86
  }
33
87
  // Simple environment detection
34
88
  const getCurrentEnvironment = () => {
35
- return process.env.NODE_ENV === 'production' ? 'production' : 'development';
89
+ let nodeEnv;
90
+ // Check for process.env (Node.js environment)
91
+ if (typeof process !== 'undefined' && process.env) {
92
+ nodeEnv = process.env.NODE_ENV;
93
+ }
94
+ // If not found and we're in a browser, try to access Vite's environment
95
+ if (!nodeEnv && typeof window !== 'undefined') {
96
+ try {
97
+ // Use eval to access import.meta at runtime (not at parse time)
98
+ // @ts-ignore
99
+ const viteEnv = eval('typeof import !== "undefined" && import.meta && import.meta.env');
100
+ if (viteEnv && typeof viteEnv === 'object') {
101
+ nodeEnv = viteEnv.NODE_ENV;
102
+ }
103
+ }
104
+ catch (e) {
105
+ // Ignore errors, fall back to default
106
+ }
107
+ }
108
+ return nodeEnv === 'production' ? 'production' : 'development';
36
109
  };
37
110
  exports.getCurrentEnvironment = getCurrentEnvironment;
38
111
  // Get current environment configuration
@@ -46,3 +119,32 @@ const isDevelopment = () => (0, exports.getCurrentEnvironment)() === 'developmen
46
119
  exports.isDevelopment = isDevelopment;
47
120
  const isProduction = () => (0, exports.getCurrentEnvironment)() === 'production';
48
121
  exports.isProduction = isProduction;
122
+ // Utility functions for easy access to service URLs
123
+ const getBackendUrl = () => (0, exports.getEnvironmentConfig)().backendUrl;
124
+ exports.getBackendUrl = getBackendUrl;
125
+ const getKioskUrl = () => (0, exports.getEnvironmentConfig)().kioskUrl;
126
+ exports.getKioskUrl = getKioskUrl;
127
+ const getAdminUrl = () => (0, exports.getEnvironmentConfig)().adminUrl;
128
+ exports.getAdminUrl = getAdminUrl;
129
+ const getApiUrl = () => (0, exports.getEnvironmentConfig)().apiUrl;
130
+ exports.getApiUrl = getApiUrl;
131
+ const getWsUrl = () => (0, exports.getEnvironmentConfig)().wsUrl;
132
+ exports.getWsUrl = getWsUrl;
133
+ // Service-specific configuration helpers
134
+ const getPaymentConfig = () => {
135
+ const config = (0, exports.getEnvironmentConfig)();
136
+ return {
137
+ enableMockPayments: config.enableMockPayments,
138
+ paymentAccountNumber: config.paymentAccountNumber,
139
+ paymentMode: config.paymentMode,
140
+ };
141
+ };
142
+ exports.getPaymentConfig = getPaymentConfig;
143
+ const getUIConfig = () => {
144
+ const config = (0, exports.getEnvironmentConfig)();
145
+ return {
146
+ showDebugInfo: config.showDebugInfo,
147
+ logLevel: config.logLevel,
148
+ };
149
+ };
150
+ exports.getUIConfig = getUIConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-kiosk-shared",
3
- "version": "1.0.4",
3
+ "version": "1.0.7",
4
4
  "private": false,
5
5
  "description": "Shared components and utilities for Pi Kiosk system",
6
6
  "keywords": [