@volley/vwr-loader 1.0.5 → 1.1.0
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/README.md +21 -0
- package/dist/amplitudeFlagFetcher.d.ts +4 -2
- package/dist/amplitudeFlagFetcher.d.ts.map +1 -1
- package/dist/amplitudeFlagFetcher.js +26 -19
- package/dist/amplitudeFlagFetcher.js.map +1 -1
- package/dist/cli.js +213 -0
- package/dist/cli.js.map +1 -0
- package/dist/envDefaults.d.ts +3 -0
- package/dist/envDefaults.d.ts.map +1 -1
- package/dist/envDefaults.js +16 -4
- package/dist/envDefaults.js.map +1 -1
- package/dist/getDeviceId.d.ts +2 -40
- package/dist/getDeviceId.d.ts.map +1 -1
- package/dist/getDeviceId.js +31 -18
- package/dist/getDeviceId.js.map +1 -1
- package/dist/getEnvironment.d.ts +1 -1
- package/dist/getEnvironment.d.ts.map +1 -1
- package/dist/getEnvironment.js +15 -7
- package/dist/getEnvironment.js.map +1 -1
- package/dist/getShellVersion.d.ts +2 -19
- package/dist/getShellVersion.d.ts.map +1 -1
- package/dist/getShellVersion.js +41 -6
- package/dist/getShellVersion.js.map +1 -1
- package/dist/index.html +1 -1
- package/dist/loadVwr.d.ts.map +1 -1
- package/dist/loadVwr.js +8 -6
- package/dist/loadVwr.js.map +1 -1
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/types.d.ts +87 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/vwrConfig.d.ts +2 -0
- package/dist/vwrConfig.d.ts.map +1 -1
- package/dist/vwrConfig.js +148 -119
- package/dist/vwrConfig.js.map +1 -1
- package/package.json +16 -5
- package/src/amplitudeFlagFetcher.test.ts +36 -59
- package/src/amplitudeFlagFetcher.ts +31 -22
- package/src/envDefaults.ts +23 -4
- package/src/getDeviceId.test.ts +89 -27
- package/src/getDeviceId.ts +35 -58
- package/src/getEnvironment.test.ts +479 -0
- package/src/getEnvironment.ts +16 -8
- package/src/getShellVersion.test.ts +123 -4
- package/src/getShellVersion.ts +46 -21
- package/src/loadVwr.ts +13 -6
- package/src/main.ts +3 -1
- package/src/types.ts +88 -0
- package/src/vite-env.d.ts +3 -0
- package/src/vwrConfig.test.ts +2 -2
- package/src/vwrConfig.ts +202 -199
- package/eslint.config.mjs +0 -23
- package/scripts/build.js +0 -2
- package/scripts/build.ts +0 -207
- package/tsconfig.eslint.json +0 -16
- package/tsconfig.json +0 -17
- package/vite.config.ts +0 -24
- package/vitest.config.ts +0 -8
package/src/vwrConfig.ts
CHANGED
|
@@ -5,6 +5,8 @@ export type VWRConfig = {
|
|
|
5
5
|
hubUrl: string
|
|
6
6
|
vwrUrl: string
|
|
7
7
|
launchUrl: string | undefined
|
|
8
|
+
platformApiUrl: string
|
|
9
|
+
platformAuthApiUrl: string
|
|
8
10
|
trustedDomains: Array<string>
|
|
9
11
|
}
|
|
10
12
|
|
|
@@ -38,227 +40,223 @@ const buildUrl = (path: string, base: string): URL => {
|
|
|
38
40
|
return new URL(path, normalizedBase)
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
),
|
|
63
|
-
tryGetShellVersionConfig(
|
|
64
|
-
request.configUrl,
|
|
65
|
-
request.configFile,
|
|
66
|
-
request.environment,
|
|
67
|
-
request.platform,
|
|
68
|
-
request.shellVersion,
|
|
69
|
-
timeout,
|
|
70
|
-
logger
|
|
71
|
-
),
|
|
72
|
-
tryGetEnvironmentConfig(
|
|
73
|
-
request.configUrl,
|
|
74
|
-
request.configFile,
|
|
75
|
-
request.environment,
|
|
76
|
-
timeout,
|
|
77
|
-
logger
|
|
78
|
-
),
|
|
79
|
-
])
|
|
80
|
-
|
|
81
|
-
// Return first successful config in priority order
|
|
82
|
-
if (localConfig !== null) {
|
|
83
|
-
logger.info("[VWR Config] ✓ Using config from: local", localConfig)
|
|
84
|
-
return localConfig
|
|
85
|
-
}
|
|
86
|
-
if (deviceConfig !== null) {
|
|
87
|
-
logger.info("[VWR Config] ✓ Using config from: device", deviceConfig)
|
|
88
|
-
return deviceConfig
|
|
43
|
+
class VWRConfigFetcher {
|
|
44
|
+
private readonly defaults: VWRConfig
|
|
45
|
+
private readonly timeout: number
|
|
46
|
+
private readonly logger: Logger
|
|
47
|
+
private readonly configUrl: string
|
|
48
|
+
private readonly configFile: string
|
|
49
|
+
private readonly platform: string
|
|
50
|
+
private readonly deviceId: string
|
|
51
|
+
private readonly environment: string
|
|
52
|
+
private readonly shellVersion: string
|
|
53
|
+
|
|
54
|
+
constructor(request: VWRConfigRequest, logger: Logger) {
|
|
55
|
+
this.defaults = getDefaultConfig(request.environment)
|
|
56
|
+
this.timeout = request.timeout ?? DEFAULT_CONFIG_TIMEOUT
|
|
57
|
+
this.logger = logger
|
|
58
|
+
this.configUrl = request.configUrl
|
|
59
|
+
this.configFile = request.configFile
|
|
60
|
+
this.platform = request.platform
|
|
61
|
+
this.deviceId = request.deviceId
|
|
62
|
+
this.environment = request.environment
|
|
63
|
+
this.shellVersion = request.shellVersion
|
|
89
64
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
)
|
|
95
|
-
return shellVersionConfig
|
|
96
|
-
}
|
|
97
|
-
if (environmentConfig !== null) {
|
|
98
|
-
logger.info(
|
|
99
|
-
"[VWR Config] ✓ Using config from: environment",
|
|
100
|
-
environmentConfig
|
|
65
|
+
|
|
66
|
+
async fetch(): Promise<VWRConfig> {
|
|
67
|
+
this.logger.info(
|
|
68
|
+
"[VWR Config] Fetching config with priority: local → device → shellVersion → environment → defaults"
|
|
101
69
|
)
|
|
102
|
-
return environmentConfig
|
|
103
|
-
}
|
|
104
70
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
71
|
+
// Fetch all configs in parallel for performance
|
|
72
|
+
const [
|
|
73
|
+
localConfig,
|
|
74
|
+
deviceConfig,
|
|
75
|
+
shellVersionConfig,
|
|
76
|
+
environmentConfig,
|
|
77
|
+
] = await Promise.all([
|
|
78
|
+
this.tryGetLocalConfig(),
|
|
79
|
+
this.tryGetDeviceConfig(),
|
|
80
|
+
this.tryGetShellVersionConfig(),
|
|
81
|
+
this.tryGetEnvironmentConfig(),
|
|
82
|
+
])
|
|
112
83
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
84
|
+
// Return first successful config in priority order
|
|
85
|
+
if (localConfig !== null) {
|
|
86
|
+
this.logger.info(
|
|
87
|
+
"[VWR Config] ✓ Using config from: local",
|
|
88
|
+
localConfig
|
|
89
|
+
)
|
|
90
|
+
return localConfig
|
|
91
|
+
}
|
|
92
|
+
if (deviceConfig !== null) {
|
|
93
|
+
this.logger.info(
|
|
94
|
+
"[VWR Config] ✓ Using config from: device",
|
|
95
|
+
deviceConfig
|
|
96
|
+
)
|
|
97
|
+
return deviceConfig
|
|
98
|
+
}
|
|
99
|
+
if (shellVersionConfig !== null) {
|
|
100
|
+
this.logger.info(
|
|
101
|
+
"[VWR Config] ✓ Using config from: shellVersion",
|
|
102
|
+
shellVersionConfig
|
|
103
|
+
)
|
|
104
|
+
return shellVersionConfig
|
|
105
|
+
}
|
|
106
|
+
if (environmentConfig !== null) {
|
|
107
|
+
this.logger.info(
|
|
108
|
+
"[VWR Config] ✓ Using config from: environment",
|
|
109
|
+
environmentConfig
|
|
110
|
+
)
|
|
111
|
+
return environmentConfig
|
|
112
|
+
}
|
|
129
113
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
platform: string,
|
|
134
|
-
deviceId: string,
|
|
135
|
-
timeout: number,
|
|
136
|
-
logger: Logger
|
|
137
|
-
): Promise<VWRConfig | null> => {
|
|
138
|
-
try {
|
|
139
|
-
const url = buildUrl(
|
|
140
|
-
`device/${platform}/${deviceId}/${configFile}`,
|
|
141
|
-
configUrl
|
|
142
|
-
)
|
|
143
|
-
logger.info(`[VWR Config] Trying device: ${url}`)
|
|
144
|
-
return tryGetVWRConfig(url, timeout)
|
|
145
|
-
} catch (error) {
|
|
146
|
-
logger.error(
|
|
147
|
-
`[VWR Config] URL construction failed for device config: ${error}`
|
|
114
|
+
// All fetches failed, use defaults
|
|
115
|
+
this.logger.warn(
|
|
116
|
+
"[VWR Config] All config fetches failed, using built-in defaults"
|
|
148
117
|
)
|
|
149
|
-
return
|
|
118
|
+
return this.defaults
|
|
150
119
|
}
|
|
151
|
-
}
|
|
152
120
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
} catch (error) {
|
|
168
|
-
logger.error(
|
|
169
|
-
`[VWR Config] URL construction failed for environment config: ${error}`
|
|
170
|
-
)
|
|
171
|
-
return null
|
|
121
|
+
private async tryGetLocalConfig(): Promise<VWRConfig | null> {
|
|
122
|
+
try {
|
|
123
|
+
const url = buildUrl(
|
|
124
|
+
this.configFile,
|
|
125
|
+
ENV_DEFAULTS["local"]?.configUrl ?? ""
|
|
126
|
+
)
|
|
127
|
+
this.logger.info(`[VWR Config] Trying local: ${url}`)
|
|
128
|
+
return this.tryFetchConfig(url)
|
|
129
|
+
} catch (error) {
|
|
130
|
+
this.logger.error(
|
|
131
|
+
`[VWR Config] URL construction failed for local config: ${error}`
|
|
132
|
+
)
|
|
133
|
+
return null
|
|
134
|
+
}
|
|
172
135
|
}
|
|
173
|
-
}
|
|
174
136
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
logger.info(`[VWR Config] Trying shellVersion: ${url}`)
|
|
190
|
-
return tryGetVWRConfig(url, timeout)
|
|
191
|
-
} catch (error) {
|
|
192
|
-
logger.error(
|
|
193
|
-
`[VWR Config] URL construction failed for shellVersion config: ${error}`
|
|
194
|
-
)
|
|
195
|
-
return null
|
|
137
|
+
private async tryGetDeviceConfig(): Promise<VWRConfig | null> {
|
|
138
|
+
try {
|
|
139
|
+
const url = buildUrl(
|
|
140
|
+
`device/${this.platform}/${this.deviceId}/${this.configFile}`,
|
|
141
|
+
this.configUrl
|
|
142
|
+
)
|
|
143
|
+
this.logger.info(`[VWR Config] Trying device: ${url}`)
|
|
144
|
+
return this.tryFetchConfig(url)
|
|
145
|
+
} catch (error) {
|
|
146
|
+
this.logger.error(
|
|
147
|
+
`[VWR Config] URL construction failed for device config: ${error}`
|
|
148
|
+
)
|
|
149
|
+
return null
|
|
150
|
+
}
|
|
196
151
|
}
|
|
197
|
-
}
|
|
198
152
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
)
|
|
153
|
+
private async tryGetEnvironmentConfig(): Promise<VWRConfig | null> {
|
|
154
|
+
try {
|
|
155
|
+
const url = buildUrl(
|
|
156
|
+
`environments/${this.environment}/${this.configFile}`,
|
|
157
|
+
this.configUrl
|
|
158
|
+
)
|
|
159
|
+
this.logger.info(`[VWR Config] Trying environment: ${url}`)
|
|
160
|
+
return this.tryFetchConfig(url)
|
|
161
|
+
} catch (error) {
|
|
162
|
+
this.logger.error(
|
|
163
|
+
`[VWR Config] URL construction failed for environment config: ${error}`
|
|
164
|
+
)
|
|
165
|
+
return null
|
|
166
|
+
}
|
|
167
|
+
}
|
|
215
168
|
|
|
216
|
-
|
|
217
|
-
|
|
169
|
+
private async tryGetShellVersionConfig(): Promise<VWRConfig | null> {
|
|
170
|
+
try {
|
|
171
|
+
const url = buildUrl(
|
|
172
|
+
`shellVersion/${this.environment}/${this.platform}/${this.shellVersion}/${this.configFile}`,
|
|
173
|
+
this.configUrl
|
|
174
|
+
)
|
|
175
|
+
this.logger.info(`[VWR Config] Trying shellVersion: ${url}`)
|
|
176
|
+
return this.tryFetchConfig(url)
|
|
177
|
+
} catch (error) {
|
|
178
|
+
this.logger.error(
|
|
179
|
+
`[VWR Config] URL construction failed for shellVersion config: ${error}`
|
|
180
|
+
)
|
|
218
181
|
return null
|
|
219
182
|
}
|
|
183
|
+
}
|
|
220
184
|
|
|
221
|
-
|
|
222
|
-
|
|
185
|
+
private async tryFetchConfig(url: URL): Promise<VWRConfig | null> {
|
|
186
|
+
const controller = new AbortController()
|
|
187
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout)
|
|
223
188
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
189
|
+
try {
|
|
190
|
+
const response = await fetch(
|
|
191
|
+
new Request(url, {
|
|
192
|
+
headers: { "Content-Type": "application/json" },
|
|
193
|
+
signal: controller.signal,
|
|
194
|
+
})
|
|
195
|
+
)
|
|
231
196
|
|
|
232
|
-
|
|
233
|
-
|
|
197
|
+
if (!response.ok) {
|
|
198
|
+
clearTimeout(timeoutId)
|
|
199
|
+
return null
|
|
200
|
+
}
|
|
234
201
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
202
|
+
const config = await response.json()
|
|
203
|
+
clearTimeout(timeoutId)
|
|
204
|
+
return this.parseConfig(config)
|
|
205
|
+
} catch {
|
|
206
|
+
clearTimeout(timeoutId)
|
|
207
|
+
return null
|
|
208
|
+
}
|
|
240
209
|
}
|
|
241
210
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
config.
|
|
211
|
+
private parseConfig(config: Partial<VWRConfig>): VWRConfig {
|
|
212
|
+
const result: VWRConfig = {
|
|
213
|
+
hubUrl: config.hubUrl || this.defaults.hubUrl,
|
|
214
|
+
vwrUrl: config.vwrUrl || this.defaults.vwrUrl,
|
|
215
|
+
launchUrl: config.launchUrl,
|
|
216
|
+
platformApiUrl:
|
|
217
|
+
config.platformApiUrl || this.defaults.platformApiUrl,
|
|
218
|
+
platformAuthApiUrl:
|
|
219
|
+
config.platformAuthApiUrl || this.defaults.platformAuthApiUrl,
|
|
220
|
+
trustedDomains:
|
|
221
|
+
Array.isArray(config.trustedDomains) &&
|
|
222
|
+
config.trustedDomains.length > 0
|
|
223
|
+
? [...config.trustedDomains]
|
|
224
|
+
: [...this.defaults.trustedDomains],
|
|
246
225
|
}
|
|
247
|
-
}
|
|
248
226
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
if (!
|
|
252
|
-
|
|
227
|
+
// Ensure vwrUrl origin is in trustedDomains
|
|
228
|
+
const vwrUrlOrigin = new URL(result.vwrUrl).origin
|
|
229
|
+
if (!result.trustedDomains.includes(vwrUrlOrigin)) {
|
|
230
|
+
result.trustedDomains.push(vwrUrlOrigin)
|
|
253
231
|
}
|
|
254
|
-
}
|
|
255
232
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
233
|
+
// Ensure hubUrl origin is in trustedDomains
|
|
234
|
+
const hubUrlOrigin = new URL(result.hubUrl).origin
|
|
235
|
+
if (!result.trustedDomains.includes(hubUrlOrigin)) {
|
|
236
|
+
result.trustedDomains.push(hubUrlOrigin)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// launchUrl is optional - only add to trustedDomains if explicitly set
|
|
240
|
+
if (result.launchUrl) {
|
|
241
|
+
try {
|
|
242
|
+
const launchUrlOrigin = new URL(result.launchUrl).origin
|
|
243
|
+
if (!result.trustedDomains.includes(launchUrlOrigin)) {
|
|
244
|
+
result.trustedDomains.push(launchUrlOrigin)
|
|
245
|
+
}
|
|
246
|
+
} catch {
|
|
247
|
+
// Invalid launchUrl - skip adding to trustedDomains
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return result
|
|
259
252
|
}
|
|
253
|
+
}
|
|
260
254
|
|
|
261
|
-
|
|
255
|
+
export const getVWRConfig = async (
|
|
256
|
+
request: VWRConfigRequest,
|
|
257
|
+
logger: Logger = defaultLogger
|
|
258
|
+
): Promise<VWRConfig> => {
|
|
259
|
+
return new VWRConfigFetcher(request, logger).fetch()
|
|
262
260
|
}
|
|
263
261
|
|
|
264
262
|
export const validateConfig = (config: VWRConfig): boolean => {
|
|
@@ -274,13 +272,12 @@ export const validateConfig = (config: VWRConfig): boolean => {
|
|
|
274
272
|
return true
|
|
275
273
|
}
|
|
276
274
|
|
|
277
|
-
const getDefaultConfig = (): VWRConfig => {
|
|
278
|
-
const
|
|
279
|
-
const defaults = ENV_DEFAULTS[ENVIRONMENT]
|
|
275
|
+
const getDefaultConfig = (environment: string): VWRConfig => {
|
|
276
|
+
const defaults = ENV_DEFAULTS[environment]
|
|
280
277
|
|
|
281
278
|
if (!defaults) {
|
|
282
279
|
throw new Error(
|
|
283
|
-
`[VWR Config] Unknown environment: ${
|
|
280
|
+
`[VWR Config] Unknown environment: ${environment}. Valid: local, dev, staging, prod`
|
|
284
281
|
)
|
|
285
282
|
}
|
|
286
283
|
|
|
@@ -288,6 +285,12 @@ const getDefaultConfig = (): VWRConfig => {
|
|
|
288
285
|
hubUrl: defaults.hubUrl,
|
|
289
286
|
vwrUrl: defaults.vwrUrl,
|
|
290
287
|
launchUrl: undefined,
|
|
291
|
-
|
|
288
|
+
platformApiUrl: defaults.platformApiUrl,
|
|
289
|
+
platformAuthApiUrl: defaults.platformAuthApiUrl,
|
|
290
|
+
trustedDomains: [
|
|
291
|
+
new URL(defaults.hubUrl).origin,
|
|
292
|
+
new URL(defaults.vwrUrl).origin,
|
|
293
|
+
...(defaults.trustedOrigins ?? []),
|
|
294
|
+
],
|
|
292
295
|
}
|
|
293
296
|
}
|
package/eslint.config.mjs
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import baseConfig from "@platform/eslint-config"
|
|
2
|
-
|
|
3
|
-
export default [
|
|
4
|
-
...baseConfig,
|
|
5
|
-
{
|
|
6
|
-
ignores: ["dist/**", "node_modules/**"],
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
languageOptions: {
|
|
10
|
-
parserOptions: {
|
|
11
|
-
project: ["tsconfig.json", "tsconfig.eslint.json"],
|
|
12
|
-
tsconfigRootDir: import.meta.dirname,
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
rules: {
|
|
16
|
-
"no-console": "off",
|
|
17
|
-
"@typescript-eslint/explicit-function-return-type": "off",
|
|
18
|
-
"@typescript-eslint/prefer-nullish-coalescing": "off",
|
|
19
|
-
"@typescript-eslint/prefer-optional-chain": "off",
|
|
20
|
-
"@typescript-eslint/no-explicit-any": "off",
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
]
|
package/scripts/build.js
DELETED