20
20
* SPDX-License-Identifier: Apache-2.0
21
21
********************************************************************************/
22
22
23
- /// <reference types="vite/client" />
24
-
25
- // Extend Window interface for runtime environment variables
26
- declare global {
27
- interface Window {
28
- ENV ?: {
29
- REQUIRE_HTTPS_URL_PATTERN ?: string ;
30
- ICHUB_BACKEND_URL ?: string ;
31
- PARTICIPANT_ID ?: string ;
32
- GOVERNANCE_CONFIG ?: string ;
33
- DTR_POLICIES_CONFIG ?: string ;
34
- }
35
- }
36
- }
37
-
38
23
// Types for governance configuration
39
24
export interface GovernanceConstraint {
40
25
leftOperand : string ;
@@ -60,70 +45,13 @@ export interface GovernanceConfig {
60
45
policies : GovernancePolicy [ ] ;
61
46
}
62
47
63
- /**
64
- * Ensures window.ENV is properly initialized
65
- * This function can be called to guarantee ENV is available before accessing it
66
- */
67
- const ensureWindowEnvInitialized = ( ) => {
68
- if ( ! window . ENV ) {
69
- console . warn ( 'window.ENV not found, initializing with fallback values' ) ;
70
- window . ENV = {
71
- REQUIRE_HTTPS_URL_PATTERN : import . meta. env . VITE_REQUIRE_HTTPS_URL_PATTERN || 'false' ,
72
- ICHUB_BACKEND_URL : import . meta. env . VITE_ICHUB_BACKEND_URL || '' ,
73
- PARTICIPANT_ID : import . meta. env . VITE_PARTICIPANT_ID || '' ,
74
- GOVERNANCE_CONFIG : import . meta. env . VITE_GOVERNANCE_CONFIG || '[]' ,
75
- DTR_POLICIES_CONFIG : import . meta. env . VITE_DTR_POLICIES_CONFIG || '[]'
76
- } ;
77
- }
78
- } ;
79
-
80
- export const isRequireHttpsUrlPattern = ( ) => {
81
- ensureWindowEnvInitialized ( ) ;
82
- return window ?. ENV ?. REQUIRE_HTTPS_URL_PATTERN !== 'false' ;
83
- } ;
48
+ export const isRequireHttpsUrlPattern = ( ) =>
49
+ import . meta. env . VITE_REQUIRE_HTTPS_URL_PATTERN !== 'false' ;
84
50
85
- export const getIchubBackendUrl = ( ) => {
86
- ensureWindowEnvInitialized ( ) ;
87
-
88
- // Debug: Log what's available
89
-
90
-
91
-
92
-
93
-
94
- // First try to get from window.ENV (runtime injection via Helm charts), then fallback to build-time env
95
- const backendUrl = window ?. ENV ?. ICHUB_BACKEND_URL ||
96
- import . meta. env . VITE_ICHUB_BACKEND_URL ;
97
-
98
-
99
-
100
- if ( ! backendUrl ) {
101
- console . warn ( '❌ ICHUB_BACKEND_URL not configured. Ensure environment variable is set via Helm chart or build configuration.' ) ;
102
- }
103
-
104
- return backendUrl ;
105
- } ;
106
- export const getParticipantId = ( ) => {
107
- ensureWindowEnvInitialized ( ) ;
108
-
109
- // Debug: Log what's available
110
-
111
-
112
-
113
-
114
- // First try to get from window.ENV (runtime injection via Helm charts), then fallback to build-time env
115
- const participantId = window ?. ENV ?. PARTICIPANT_ID ||
116
- import . meta. env . VITE_PARTICIPANT_ID ;
117
-
118
- // Use fallback value if no participant ID is configured
119
- const resolvedId = participantId ?? 'BPNL0000000093Q7' ;
120
-
121
-
122
- return resolvedId ;
123
- } ;
51
+ export const getIchubBackendUrl = ( ) => import . meta. env . VITE_ICHUB_BACKEND_URL ?? '' ;
52
+ export const getParticipantId = ( ) => import . meta. env . VITE_PARTICIPANT_ID ?? 'BPNL0000000093Q7' ;
124
53
125
54
export const getGovernanceConfig = ( ) : GovernanceConfig [ ] => {
126
- ensureWindowEnvInitialized ( ) ;
127
55
try {
128
56
// First try to get from window.ENV (runtime injection), then fallback to import.meta.env
129
57
const configStr = window ?. ENV ?. GOVERNANCE_CONFIG || import . meta. env . VITE_GOVERNANCE_CONFIG ;
@@ -136,7 +64,6 @@ export const getGovernanceConfig = (): GovernanceConfig[] => {
136
64
} ;
137
65
138
66
export const getDtrPoliciesConfig = ( ) : GovernancePolicy [ ] => {
139
- ensureWindowEnvInitialized ( ) ;
140
67
try {
141
68
// First try to get from window.ENV (runtime injection), then fallback to import.meta.env
142
69
const configStr = window ?. ENV ?. DTR_POLICIES_CONFIG || import . meta. env . VITE_DTR_POLICIES_CONFIG ;
@@ -216,4 +143,4 @@ const EnvironmentService = {
216
143
getDtrPoliciesConfig
217
144
} ;
218
145
219
- export default EnvironmentService ;
146
+ export default EnvironmentService ;
0 commit comments