@volley/vwr-loader 1.0.0-alpha.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.
Files changed (54) hide show
  1. package/README.md +205 -0
  2. package/dist/amplitudeFlagFetcher.d.ts +23 -0
  3. package/dist/amplitudeFlagFetcher.d.ts.map +1 -0
  4. package/dist/amplitudeFlagFetcher.js +60 -0
  5. package/dist/amplitudeFlagFetcher.js.map +1 -0
  6. package/dist/cli.js +177 -0
  7. package/dist/cli.js.map +1 -0
  8. package/dist/envDefaults.d.ts +9 -0
  9. package/dist/envDefaults.d.ts.map +1 -0
  10. package/dist/envDefaults.js +36 -0
  11. package/dist/envDefaults.js.map +1 -0
  12. package/dist/getDeviceId.d.ts +65 -0
  13. package/dist/getDeviceId.d.ts.map +1 -0
  14. package/dist/getDeviceId.js +196 -0
  15. package/dist/getDeviceId.js.map +1 -0
  16. package/dist/getShellVersion.d.ts +34 -0
  17. package/dist/getShellVersion.d.ts.map +1 -0
  18. package/dist/getShellVersion.js +84 -0
  19. package/dist/getShellVersion.js.map +1 -0
  20. package/dist/index.d.ts +9 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.html +25 -0
  23. package/dist/index.js +6 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/loadVwr.d.ts +19 -0
  26. package/dist/loadVwr.d.ts.map +1 -0
  27. package/dist/loadVwr.js +104 -0
  28. package/dist/loadVwr.js.map +1 -0
  29. package/dist/logger.d.ts +7 -0
  30. package/dist/logger.d.ts.map +1 -0
  31. package/dist/logger.js +6 -0
  32. package/dist/logger.js.map +1 -0
  33. package/dist/main.js +2 -0
  34. package/dist/main.js.map +1 -0
  35. package/dist/vwrConfig.d.ts +19 -0
  36. package/dist/vwrConfig.d.ts.map +1 -0
  37. package/dist/vwrConfig.js +172 -0
  38. package/dist/vwrConfig.js.map +1 -0
  39. package/package.json +54 -0
  40. package/src/amplitudeFlagFetcher.test.ts +209 -0
  41. package/src/amplitudeFlagFetcher.ts +88 -0
  42. package/src/envDefaults.ts +45 -0
  43. package/src/getDeviceId.test.ts +237 -0
  44. package/src/getDeviceId.ts +243 -0
  45. package/src/getShellVersion.test.ts +278 -0
  46. package/src/getShellVersion.ts +114 -0
  47. package/src/index.html +25 -0
  48. package/src/index.ts +8 -0
  49. package/src/loadVwr.ts +126 -0
  50. package/src/logger.ts +14 -0
  51. package/src/main.ts +26 -0
  52. package/src/vite-env.d.ts +15 -0
  53. package/src/vwrConfig.test.ts +316 -0
  54. package/src/vwrConfig.ts +293 -0
package/README.md ADDED
@@ -0,0 +1,205 @@
1
+ # @volley/vwr-loader
2
+
3
+ VWR (Volley Web Runtime) loader for Volley TV platform shells (Samsung, LG, Fire TV, etc.).
4
+
5
+ ## Features
6
+
7
+ - **Amplitude Flag Fetching**: Fetch feature flags from Amplitude Experiment REST API
8
+ - **Chrome 66+ Compatible**: Uses modern browser APIs (Fetch API, async/await, AbortController)
9
+ - **Safe Defaults**: Returns fallback values on error to ensure graceful degradation
10
+ - **Shell Loader Template**: HTML template for shell initialization with VWR integration
11
+ - **Device ID Resolution**: Cross-platform device ID handling
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ pnpm add @volley/vwr-loader
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ### CLI Build (Recommended)
22
+
23
+ You can build the loader for a specific platform and environment using the CLI. This is useful for native shells (iOS, Android, FireTV, Samsung, LG) and CI/CD pipelines.
24
+
25
+ ```bash
26
+ # Using npx (if installed globally or in project)
27
+ npx build-loader --platform IOS_MOBILE --env dev --output ./dist-ios
28
+
29
+ # Or via pnpm
30
+ pnpm build-loader --platform IOS_MOBILE --env dev --output ./dist-ios
31
+ ```
32
+
33
+ **Options:**
34
+
35
+ - `--platform`: Target platform (`IOS_MOBILE`, `ANDROID_MOBILE`, `FIRE_TV`, `SAMSUNG_TV`, `LG_TV`, `WEB`)
36
+ - `--env`: Environment (`local`, `dev`, `staging`, `prod`)
37
+ - `--output`: Output directory for `index.html` and `main.js`
38
+ - `--hubUrl`: Override Hub URL (optional)
39
+ - `--vwrUrl`: Override VWR URL (optional)
40
+ - `--amplitudeKey`: Override Amplitude deployment key (optional)
41
+
42
+ ### Fetching Amplitude Flags
43
+
44
+ ```typescript
45
+ import { fetchAmplitudeFlags } from '@volley/vwr-loader'
46
+
47
+ const flags = await fetchAmplitudeFlags(
48
+ 'device-id-123',
49
+ 'samsung',
50
+ {
51
+ apiKey: 'your-amplitude-api-key',
52
+ timeout: 2000
53
+ }
54
+ )
55
+
56
+ console.log(flags['vwr-enabled']) // boolean
57
+ console.log(flags['vwr-url']) // string
58
+ ```
59
+
60
+ ### Using the VWR Loader Template
61
+
62
+ The package includes a `vwr-loader.html` template that can be used as the entry point for platform shells. The template:
63
+
64
+ 1. Fetches feature flags from Amplitude
65
+ 2. Conditionally loads VWR (Volley Web Runtime) or falls back to legacy Hub
66
+ 3. Handles device ID resolution across platforms
67
+ 4. Validates that build-time config was properly injected
68
+
69
+ **Build-time placeholders** (must be replaced during build):
70
+ - `__PLATFORM__` - Platform name (samsung-tv, lg-tv, firetv, etc.)
71
+ - `__AMPLITUDE_KEY__` - Amplitude deployment key
72
+ - `__HUB_URL__` - Hub application URL
73
+ - `__VWR_URL__` - Default VWR bundle URL
74
+
75
+ ## Development Commands
76
+
77
+ ```bash
78
+ # Run tests
79
+ pnpm test
80
+
81
+ # Type checking
82
+ pnpm typecheck
83
+
84
+ # Build
85
+ pnpm build
86
+
87
+ # Lint
88
+ pnpm lint
89
+ ```
90
+
91
+ ## Browser Compatibility
92
+
93
+ Requires Chrome 66+ or equivalent browser with support for:
94
+ - Fetch API
95
+ - async/await
96
+ - AbortController
97
+ - crypto.randomUUID (for fallback device ID generation)
98
+
99
+ ## API Reference
100
+
101
+ ### `fetchAmplitudeFlags(deviceId, platform, config)`
102
+
103
+ Fetches feature flags from Amplitude Experiment using GET method with query parameters.
104
+
105
+ **Parameters:**
106
+ - `deviceId` (string): Unique device identifier
107
+ - `platform` (string): Platform name (samsung-tv, lg-tv, firetv, ios, android)
108
+ - `config` (AmplitudeConfig):
109
+ - `apiKey` (string): Amplitude API key (client-side key starting with "client-")
110
+ - `apiUrl` (string, optional): API endpoint (defaults to Amplitude production)
111
+ - `timeout` (number, optional): Request timeout in ms (defaults to 2000)
112
+
113
+ **Returns:** `Promise<FlagResult>`
114
+ - `vwr-enabled` (boolean): Whether VWR should be loaded
115
+ - `vwr-url` (string): VWR bundle URL to load
116
+
117
+ **Error Handling:**
118
+ Returns safe defaults on error:
119
+ ```typescript
120
+ {
121
+ 'vwr-enabled': false,
122
+ 'vwr-url': 'https://vwr.volley.tv/v1/vwr.js'
123
+ }
124
+ ```
125
+
126
+ ## VWR Configuration System
127
+
128
+ The vwr-loader fetches configuration from S3 with a priority-based fallback system. This enables device-specific, shell-version-specific, or environment-specific configurations without rebuilding shells.
129
+
130
+ ### Configuration Schema
131
+
132
+ ```typescript
133
+ type VWRConfig = {
134
+ hubUrl: string // URL to the Hub application
135
+ vwrUrl: string // URL to the VWR runtime JavaScript file
136
+ launchUrl: string | undefined // Optional launch URL (defaults to hubUrl)
137
+ trustedDomains: Array<string> // List of trusted domains for iframe communication
138
+ amplitudeKey: string // Amplitude API key for analytics
139
+ }
140
+ ```
141
+
142
+ ### Configuration Priority
143
+
144
+ The loader tries to fetch configs in this order (first successful fetch wins):
145
+
146
+ 1. **Local config** (development only): `http://localhost:5174/vwrConfig.json`
147
+ 2. **Device-specific config**: `{configUrl}/device/{platform}/{deviceId}/vwrConfig.json`
148
+ 3. **Shell version config**: `{configUrl}/shellVersion/{environment}/{platform}/{shellVersion}/vwrConfig.json`
149
+ 4. **Environment config**: `{configUrl}/environments/{environment}/vwrConfig.json`
150
+ 5. **Fallback defaults**: Built-in defaults from `envDefaults.ts`
151
+
152
+ Where `configUrl` defaults to: `https://vwr.volley.tv/config/`
153
+
154
+ ### S3 Bucket Structure
155
+
156
+ ```
157
+ s3://volley-vwr/config/
158
+ ├── environments/
159
+ │ ├── dev/
160
+ │ │ └── vwrConfig.json
161
+ │ ├── staging/
162
+ │ │ └── vwrConfig.json
163
+ │ └── prod/
164
+ │ └── vwrConfig.json
165
+ ├── device/
166
+ │ ├── SAMSUNG_TV/
167
+ │ │ └── {deviceId}/
168
+ │ │ └── vwrConfig.json
169
+ │ ├── LG_TV/
170
+ │ ├── FIRE_TV/
171
+ │ └── WEB/
172
+ └── shellVersion/
173
+ └── {environment}/
174
+ └── {platform}/
175
+ └── {version}/
176
+ └── vwrConfig.json
177
+ ```
178
+
179
+ ### Fetching Config in Shells
180
+
181
+ ```typescript
182
+ import { getVWRConfig } from '@volley/vwr-loader'
183
+
184
+ const vwrConfig = await getVWRConfig({
185
+ configUrl: 'https://vwr.volley.tv/config/',
186
+ configFile: 'vwrConfig.json',
187
+ platform: 'SAMSUNG_TV',
188
+ deviceId: 'DEVICE123',
189
+ environment: 'prod',
190
+ shellVersion: '1.0.0',
191
+ timeout: 2000 // optional, defaults to 2000ms
192
+ })
193
+ ```
194
+
195
+ ### Default Values
196
+
197
+ If all config fetches fail, the loader falls back to built-in defaults per environment. See `src/envDefaults.ts` for current values.
198
+
199
+ ### Operations
200
+
201
+ For S3 config management (uploading, deleting, cache invalidation), see [VWR S3 Config Operations](../../docs/VWR_S3_CONFIG_OPERATIONS.md).
202
+
203
+ ## License
204
+
205
+ Proprietary - Volley Inc.
@@ -0,0 +1,23 @@
1
+ export interface AmplitudeConfig {
2
+ apiKey: string;
3
+ apiUrl?: string;
4
+ timeout?: number;
5
+ }
6
+ export interface FlagResult {
7
+ "vwr-enabled": boolean;
8
+ }
9
+ /**
10
+ * Fetch feature flags from Amplitude Experiment REST API.
11
+ *
12
+ * Uses GET method with query parameters and Authorization header.
13
+ * Includes platform and shell version in context for better flag targeting.
14
+ * Compatible with Chrome 66+ (Fetch API, async/await, AbortController).
15
+ *
16
+ * @param deviceId - Unique device identifier
17
+ * @param platform - Platform name (samsung, lg, firetv, ios, android)
18
+ * @param config - Amplitude configuration
19
+ * @param shellVersion - Optional shell version (if not provided, will be fetched automatically)
20
+ * @returns Flag values with safe defaults on error
21
+ */
22
+ export declare function fetchAmplitudeFlags(deviceId: string, platform: string, config: AmplitudeConfig, shellVersion?: string): Promise<FlagResult>;
23
+ //# sourceMappingURL=amplitudeFlagFetcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"amplitudeFlagFetcher.d.ts","sourceRoot":"","sources":["../src/amplitudeFlagFetcher.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,eAAe;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,UAAU;IACvB,aAAa,EAAE,OAAO,CAAA;CACzB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,mBAAmB,CACrC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,eAAe,EACvB,YAAY,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC,UAAU,CAAC,CAyDrB"}
@@ -0,0 +1,60 @@
1
+ import { getShellVersion } from "./getShellVersion";
2
+ /**
3
+ * Fetch feature flags from Amplitude Experiment REST API.
4
+ *
5
+ * Uses GET method with query parameters and Authorization header.
6
+ * Includes platform and shell version in context for better flag targeting.
7
+ * Compatible with Chrome 66+ (Fetch API, async/await, AbortController).
8
+ *
9
+ * @param deviceId - Unique device identifier
10
+ * @param platform - Platform name (samsung, lg, firetv, ios, android)
11
+ * @param config - Amplitude configuration
12
+ * @param shellVersion - Optional shell version (if not provided, will be fetched automatically)
13
+ * @returns Flag values with safe defaults on error
14
+ */
15
+ export async function fetchAmplitudeFlags(deviceId, platform, config, shellVersion) {
16
+ var _a, _b, _c;
17
+ const { apiKey, apiUrl = "https://api.lab.amplitude.com/v1/vardata", timeout = 2000, } = config;
18
+ const controller = new AbortController();
19
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
20
+ try {
21
+ // Get shell version if not provided
22
+ const version = shellVersion !== null && shellVersion !== void 0 ? shellVersion : (await getShellVersion(platform));
23
+ // Build context with user_properties
24
+ const context = {
25
+ user_properties: {
26
+ platformEnum: platform,
27
+ nativeShellAppVersion: version,
28
+ },
29
+ };
30
+ // Build query parameters
31
+ const params = new URLSearchParams({
32
+ user_id: deviceId,
33
+ flag_keys: "vwr-enabled",
34
+ context: JSON.stringify(context),
35
+ });
36
+ const response = await fetch(`${apiUrl}?${params}`, {
37
+ method: "GET",
38
+ headers: {
39
+ Authorization: `Api-Key ${apiKey}`,
40
+ },
41
+ signal: controller.signal,
42
+ });
43
+ clearTimeout(timeoutId);
44
+ if (!response.ok) {
45
+ throw new Error(`Amplitude API returned ${response.status}`);
46
+ }
47
+ const data = await response.json();
48
+ return {
49
+ "vwr-enabled": (_c = (_b = (_a = data["vwr-enabled"]) === null || _a === void 0 ? void 0 : _a.payload) === null || _b === void 0 ? void 0 : _b["vwr-enabled"]) !== null && _c !== void 0 ? _c : false,
50
+ };
51
+ }
52
+ catch (error) {
53
+ console.error("[Shell] Amplitude flag fetch failed:", error);
54
+ // Return safe defaults - runs legacy path
55
+ return {
56
+ "vwr-enabled": false,
57
+ };
58
+ }
59
+ }
60
+ //# sourceMappingURL=amplitudeFlagFetcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"amplitudeFlagFetcher.js","sourceRoot":"","sources":["../src/amplitudeFlagFetcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAYnD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACrC,QAAgB,EAChB,QAAgB,EAChB,MAAuB,EACvB,YAAqB;;IAErB,MAAM,EACF,MAAM,EACN,MAAM,GAAG,0CAA0C,EACnD,OAAO,GAAG,IAAI,GACjB,GAAG,MAAM,CAAA;IAEV,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAA;IACx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AE5D,0CAA0C;QAC1C,OAAO;YACH,aAAa,EAAE,KAAK;SACvB,CAAA;IACL,CAAC;AACL,CAAC"}
package/dist/cli.js ADDED
@@ -0,0 +1,177 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "commander";
3
+ import { config as config$1 } from "dotenv";
4
+ import fs from "fs-extra";
5
+ import path from "path";
6
+ import os from "os";
7
+ import { fileURLToPath } from "url";
8
+ import { build } from "vite";
9
+ const CONFIG_URL_DEFAULT = "https://vwr.volley.tv/config/";
10
+ const CONFIG_FILE_DEFAULT = "vwrConfig.json";
11
+ const VWR_URL_PATH_DEFAULT = "v1/latest/vwr.js";
12
+ const prodConfig = {
13
+ hubUrl: "https://game-clients.volley.tv/hub",
14
+ vwrUrl: `https://vwr.volley.tv/${VWR_URL_PATH_DEFAULT}`,
15
+ configUrl: CONFIG_URL_DEFAULT,
16
+ configFile: CONFIG_FILE_DEFAULT,
17
+ amplitudeKey: ""
18
+ };
19
+ const ENV_DEFAULTS = {
20
+ local: {
21
+ hubUrl: "http://localhost:5173",
22
+ vwrUrl: "http://localhost:5174/vwr.js",
23
+ configUrl: "http://localhost:5174/config/",
24
+ configFile: CONFIG_FILE_DEFAULT,
25
+ amplitudeKey: "client-uJJVW3zKPC1G9kqPhUumLnZN6eaY42iQ"
26
+ },
27
+ dev: {
28
+ hubUrl: "https://game-clients-dev.volley.tv/hub",
29
+ vwrUrl: `https://vwr.volley.tv/dev/${VWR_URL_PATH_DEFAULT}`,
30
+ configUrl: CONFIG_URL_DEFAULT,
31
+ configFile: CONFIG_FILE_DEFAULT,
32
+ amplitudeKey: "client-uJJVW3zKPC1G9kqPhUumLnZN6eaY42iQ"
33
+ },
34
+ staging: {
35
+ hubUrl: "https://game-clients-staging.volley.tv/hub",
36
+ vwrUrl: `https://vwr.volley.tv/staging/${VWR_URL_PATH_DEFAULT}`,
37
+ configUrl: CONFIG_URL_DEFAULT,
38
+ configFile: CONFIG_FILE_DEFAULT,
39
+ amplitudeKey: ""
40
+ },
41
+ prod: prodConfig,
42
+ production: prodConfig
43
+ // Alias for prod
44
+ };
45
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
46
+ const cliPackageJson = JSON.parse(
47
+ fs.readFileSync(path.join(__dirname, "../package.json"), "utf-8")
48
+ );
49
+ const VALID_PLATFORMS = [
50
+ "FIRE_TV",
51
+ "ANDROID_MOBILE",
52
+ "IOS_MOBILE",
53
+ "SAMSUNG_TV",
54
+ "LG_TV",
55
+ "WEB"
56
+ ];
57
+ const program = new Command();
58
+ program.name("build-loader").version(cliPackageJson.version).description("Build vwr-loader with environment configuration").requiredOption(
59
+ "--platform <platform>",
60
+ "Platform: FIRE_TV, ANDROID_MOBILE, IOS_MOBILE, SAMSUNG_TV, LG_TV, WEB"
61
+ ).requiredOption("--env <env>", "Environment: local, dev, staging, prod").requiredOption("--output <path>", "Output directory").option("--hubUrl <url>", "Override Hub URL").option("--amplitudeKey <key>", "Override Amplitude deployment key").option("--vwrUrl <url>", "Override VWR URL").option("--configUrl <url>", "Override VWR Config URL").option("--configFile <filename>", "Override VWR Config Filename").option("--launchUrl <url>", "Override launch url").parse();
62
+ const opts = program.opts();
63
+ const normalizedPlatform = opts.platform.toUpperCase();
64
+ if (!VALID_PLATFORMS.includes(normalizedPlatform)) {
65
+ console.error(`❌ Unknown platform: ${opts.platform}`);
66
+ console.error(` Valid: ${VALID_PLATFORMS.join(", ")}`);
67
+ process.exit(1);
68
+ }
69
+ opts.platform = normalizedPlatform;
70
+ const envFile = path.join(process.cwd(), `.env.${opts.env}`);
71
+ let shellEnv = {};
72
+ if (fs.existsSync(envFile)) {
73
+ console.log(`📄 Reading config from ${envFile}`);
74
+ const result = config$1({ path: envFile });
75
+ shellEnv = result.parsed || {};
76
+ } else {
77
+ console.log(`ℹ️ No .env.${opts.env} found, using defaults/CLI flags`);
78
+ }
79
+ let shellVersion = "unknown";
80
+ const packageJsonPath = path.join(process.cwd(), "package.json");
81
+ if (fs.existsSync(packageJsonPath)) {
82
+ try {
83
+ const packageJson = JSON.parse(
84
+ fs.readFileSync(packageJsonPath, "utf-8")
85
+ );
86
+ shellVersion = packageJson.version || "unknown";
87
+ } catch {
88
+ console.warn(`⚠️ Could not read version from package.json`);
89
+ }
90
+ }
91
+ const envDefaults = ENV_DEFAULTS[opts.env];
92
+ if (!envDefaults) {
93
+ console.error(`❌ Unknown environment: ${opts.env}`);
94
+ console.error(` Valid: local, dev, staging, prod`);
95
+ process.exit(1);
96
+ }
97
+ const config = {
98
+ VITE_PLATFORM: opts.platform,
99
+ VITE_HUB_URL: opts.hubUrl || shellEnv.VITE_HUB_URL || envDefaults.hubUrl,
100
+ VITE_AMPLITUDE_DEPLOYMENT_KEY: opts.amplitudeKey || shellEnv.VITE_AMPLITUDE_DEPLOYMENT_KEY || envDefaults.amplitudeKey || "",
101
+ VITE_VWR_URL: opts.vwrUrl || shellEnv.VITE_VWR_URL || envDefaults.vwrUrl || "https://vwr.volley.tv/v1/latest/vwr.js",
102
+ VITE_CONFIG_URL: opts.configUrl || shellEnv.VITE_CONFIG_URL || envDefaults.configUrl,
103
+ VITE_CONFIG_FILE: opts.configFile || shellEnv.VITE_CONFIG_FILE || envDefaults.configFile,
104
+ VITE_LAUNCH_URL: opts.launchUrl || shellEnv.VITE_LAUNCH_URL || opts.hubUrl || shellEnv.VITE_HUB_URL || envDefaults.hubUrl
105
+ };
106
+ console.log("🔧 Build configuration:");
107
+ console.log(` Platform: ${config.VITE_PLATFORM}`);
108
+ console.log(` Hub URL: ${config.VITE_HUB_URL}`);
109
+ console.log(` VWR URL: ${config.VITE_VWR_URL}`);
110
+ if (config.VITE_AMPLITUDE_DEPLOYMENT_KEY) {
111
+ console.log(` Amplitude: ***`);
112
+ } else {
113
+ console.warn(` Amplitude: (not set)`);
114
+ console.warn(
115
+ ` ⚠️ VWR flag fetching will use safe defaults (vwr-enabled: false)`
116
+ );
117
+ }
118
+ const loaderSrcDir = path.join(__dirname, "../src");
119
+ const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "vwr-loader-"));
120
+ const loaderDistDir = tmpDir;
121
+ try {
122
+ console.log(`⏳ Building loader...`);
123
+ await build({
124
+ configFile: false,
125
+ root: loaderSrcDir,
126
+ mode: opts.env,
127
+ logLevel: "warn",
128
+ build: {
129
+ outDir: loaderDistDir,
130
+ emptyOutDir: true,
131
+ target: "es2017",
132
+ minify: opts.env === "prod" ? "esbuild" : false,
133
+ sourcemap: true,
134
+ rollupOptions: {
135
+ input: {
136
+ main: path.join(loaderSrcDir, "index.html")
137
+ },
138
+ output: {
139
+ entryFileNames: "[name].js",
140
+ assetFileNames: "[name].[ext]"
141
+ }
142
+ }
143
+ },
144
+ define: {
145
+ "import.meta.env.VITE_ENVIRONMENT": JSON.stringify(opts.env),
146
+ "import.meta.env.VITE_PLATFORM": JSON.stringify(config.VITE_PLATFORM),
147
+ "import.meta.env.VITE_SHELL_VERSION": JSON.stringify(shellVersion),
148
+ "import.meta.env.VITE_HUB_URL": JSON.stringify(config.VITE_HUB_URL),
149
+ "import.meta.env.VITE_AMPLITUDE_DEPLOYMENT_KEY": JSON.stringify(
150
+ config.VITE_AMPLITUDE_DEPLOYMENT_KEY
151
+ ),
152
+ "import.meta.env.VITE_VWR_URL": JSON.stringify(config.VITE_VWR_URL),
153
+ "import.meta.env.VITE_CONFIG_URL": JSON.stringify(
154
+ config.VITE_CONFIG_URL
155
+ ),
156
+ "import.meta.env.VITE_CONFIG_FILE": JSON.stringify(
157
+ config.VITE_CONFIG_FILE
158
+ ),
159
+ "import.meta.env.VITE_LAUNCH_URL": JSON.stringify(
160
+ config.VITE_LAUNCH_URL
161
+ )
162
+ }
163
+ });
164
+ const outputPath = path.resolve(opts.output);
165
+ await fs.ensureDir(outputPath);
166
+ await fs.copy(loaderDistDir, outputPath, { overwrite: true });
167
+ console.log(`✅ VWR loader built successfully`);
168
+ console.log(` Output: ${outputPath}`);
169
+ console.log(` Files: index.html, main.js`);
170
+ } finally {
171
+ try {
172
+ await fs.remove(tmpDir);
173
+ } catch (e) {
174
+ console.warn("⚠️ Failed to cleanup temp dir:", e);
175
+ }
176
+ }
177
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sources":["../src/envDefaults.ts","../scripts/build.ts"],"sourcesContent":["export interface EnvConfig {\n hubUrl: string\n vwrUrl: string\n configUrl: string\n configFile: string\n amplitudeKey: string // Used for amplitude flag fetch, not part of VWRConfig\n}\n\nconst CONFIG_URL_DEFAULT = \"https://vwr.volley.tv/config/\"\nconst CONFIG_FILE_DEFAULT = \"vwrConfig.json\"\nconst VWR_URL_PATH_DEFAULT = \"v1/latest/vwr.js\"\n\nconst prodConfig: EnvConfig = {\n hubUrl: \"https://game-clients.volley.tv/hub\",\n vwrUrl: `https://vwr.volley.tv/${VWR_URL_PATH_DEFAULT}`,\n configUrl: CONFIG_URL_DEFAULT,\n configFile: CONFIG_FILE_DEFAULT,\n amplitudeKey: \"\",\n}\n\nexport const ENV_DEFAULTS: Record<string, EnvConfig> = {\n local: {\n hubUrl: \"http://localhost:5173\",\n vwrUrl: \"http://localhost:5174/vwr.js\",\n configUrl: \"http://localhost:5174/config/\",\n configFile: CONFIG_FILE_DEFAULT,\n amplitudeKey: \"client-uJJVW3zKPC1G9kqPhUumLnZN6eaY42iQ\",\n },\n dev: {\n hubUrl: \"https://game-clients-dev.volley.tv/hub\",\n vwrUrl: `https://vwr.volley.tv/dev/${VWR_URL_PATH_DEFAULT}`,\n configUrl: CONFIG_URL_DEFAULT,\n configFile: CONFIG_FILE_DEFAULT,\n amplitudeKey: \"client-uJJVW3zKPC1G9kqPhUumLnZN6eaY42iQ\",\n },\n staging: {\n hubUrl: \"https://game-clients-staging.volley.tv/hub\",\n vwrUrl: `https://vwr.volley.tv/staging/${VWR_URL_PATH_DEFAULT}`,\n configUrl: CONFIG_URL_DEFAULT,\n configFile: CONFIG_FILE_DEFAULT,\n amplitudeKey: \"\",\n },\n prod: prodConfig,\n production: prodConfig, // Alias for prod\n}\n","import { Command } from \"commander\"\nimport { config as loadDotenv } from \"dotenv\"\nimport fs from \"fs-extra\"\nimport path from \"path\"\nimport os from \"os\"\nimport { fileURLToPath } from \"url\"\nimport { build } from \"vite\"\n\nimport { ENV_DEFAULTS } from \"../src/envDefaults.js\"\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url))\n\n// Read package version for --version flag\nconst cliPackageJson = JSON.parse(\n fs.readFileSync(path.join(__dirname, \"../package.json\"), \"utf-8\")\n)\n\nconst VALID_PLATFORMS = [\n \"FIRE_TV\",\n \"ANDROID_MOBILE\",\n \"IOS_MOBILE\",\n \"SAMSUNG_TV\",\n \"LG_TV\",\n \"WEB\",\n]\n\nconst program = new Command()\n\nprogram\n .name(\"build-loader\")\n .version(cliPackageJson.version)\n .description(\"Build vwr-loader with environment configuration\")\n .requiredOption(\n \"--platform <platform>\",\n \"Platform: FIRE_TV, ANDROID_MOBILE, IOS_MOBILE, SAMSUNG_TV, LG_TV, WEB\"\n )\n .requiredOption(\"--env <env>\", \"Environment: local, dev, staging, prod\")\n .requiredOption(\"--output <path>\", \"Output directory\")\n .option(\"--hubUrl <url>\", \"Override Hub URL\")\n .option(\"--amplitudeKey <key>\", \"Override Amplitude deployment key\")\n .option(\"--vwrUrl <url>\", \"Override VWR URL\")\n .option(\"--configUrl <url>\", \"Override VWR Config URL\")\n .option(\"--configFile <filename>\", \"Override VWR Config Filename\")\n .option(\"--launchUrl <url>\", \"Override launch url\")\n .parse()\n\nconst opts = program.opts()\n\n// Validate platform\nconst normalizedPlatform = opts.platform.toUpperCase()\nif (!VALID_PLATFORMS.includes(normalizedPlatform)) {\n console.error(`❌ Unknown platform: ${opts.platform}`)\n console.error(` Valid: ${VALID_PLATFORMS.join(\", \")}`)\n process.exit(1)\n}\nopts.platform = normalizedPlatform\n\n// Try to read from shell's .env file (run from shell directory)\nconst envFile = path.join(process.cwd(), `.env.${opts.env}`)\nlet shellEnv: Record<string, string> = {}\n\nif (fs.existsSync(envFile)) {\n console.log(`📄 Reading config from ${envFile}`)\n const result = loadDotenv({ path: envFile })\n shellEnv = result.parsed || {}\n} else {\n console.log(`ℹ️ No .env.${opts.env} found, using defaults/CLI flags`)\n}\n\n// Read shell version from package.json (for web shell)\nlet shellVersion = \"unknown\"\nconst packageJsonPath = path.join(process.cwd(), \"package.json\")\nif (fs.existsSync(packageJsonPath)) {\n try {\n const packageJson = JSON.parse(\n fs.readFileSync(packageJsonPath, \"utf-8\")\n )\n shellVersion = packageJson.version || \"unknown\"\n } catch {\n console.warn(`⚠️ Could not read version from package.json`)\n }\n}\n\n// Get predefined defaults\nconst envDefaults = ENV_DEFAULTS[opts.env]\nif (!envDefaults) {\n console.error(`❌ Unknown environment: ${opts.env}`)\n console.error(` Valid: local, dev, staging, prod`)\n process.exit(1)\n}\n\n// Config precedence: CLI > shell .env > defaults\nconst config = {\n VITE_PLATFORM: opts.platform,\n VITE_HUB_URL: opts.hubUrl || shellEnv.VITE_HUB_URL || envDefaults.hubUrl,\n VITE_AMPLITUDE_DEPLOYMENT_KEY:\n opts.amplitudeKey ||\n shellEnv.VITE_AMPLITUDE_DEPLOYMENT_KEY ||\n envDefaults.amplitudeKey ||\n \"\",\n VITE_VWR_URL:\n opts.vwrUrl ||\n shellEnv.VITE_VWR_URL ||\n envDefaults.vwrUrl ||\n \"https://vwr.volley.tv/v1/latest/vwr.js\",\n VITE_CONFIG_URL:\n opts.configUrl || shellEnv.VITE_CONFIG_URL || envDefaults.configUrl,\n VITE_CONFIG_FILE:\n opts.configFile || shellEnv.VITE_CONFIG_FILE || envDefaults.configFile,\n VITE_LAUNCH_URL:\n opts.launchUrl ||\n shellEnv.VITE_LAUNCH_URL ||\n opts.hubUrl ||\n shellEnv.VITE_HUB_URL ||\n envDefaults.hubUrl,\n}\n\nconsole.log(\"🔧 Build configuration:\")\nconsole.log(` Platform: ${config.VITE_PLATFORM}`)\nconsole.log(` Hub URL: ${config.VITE_HUB_URL}`)\nconsole.log(` VWR URL: ${config.VITE_VWR_URL}`)\nif (config.VITE_AMPLITUDE_DEPLOYMENT_KEY) {\n console.log(` Amplitude: ***`)\n} else {\n console.warn(` Amplitude: (not set)`)\n console.warn(\n ` ⚠️ VWR flag fetching will use safe defaults (vwr-enabled: false)`\n )\n}\n\n// Build with Vite (inline config to avoid path resolution issues)\nconst loaderSrcDir = path.join(__dirname, \"../src\")\nconst tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), \"vwr-loader-\"))\nconst loaderDistDir = tmpDir\n\ntry {\n console.log(`⏳ Building loader...`)\n await build({\n configFile: false,\n root: loaderSrcDir,\n mode: opts.env,\n logLevel: \"warn\",\n build: {\n outDir: loaderDistDir,\n emptyOutDir: true,\n target: \"es2017\",\n minify: opts.env === \"prod\" ? \"esbuild\" : false,\n sourcemap: true,\n rollupOptions: {\n input: {\n main: path.join(loaderSrcDir, \"index.html\"),\n },\n output: {\n entryFileNames: \"[name].js\",\n assetFileNames: \"[name].[ext]\",\n },\n },\n },\n define: {\n \"import.meta.env.VITE_ENVIRONMENT\": JSON.stringify(opts.env),\n \"import.meta.env.VITE_PLATFORM\": JSON.stringify(config.VITE_PLATFORM),\n \"import.meta.env.VITE_SHELL_VERSION\": JSON.stringify(shellVersion),\n \"import.meta.env.VITE_HUB_URL\": JSON.stringify(config.VITE_HUB_URL),\n \"import.meta.env.VITE_AMPLITUDE_DEPLOYMENT_KEY\": JSON.stringify(\n config.VITE_AMPLITUDE_DEPLOYMENT_KEY\n ),\n \"import.meta.env.VITE_VWR_URL\": JSON.stringify(config.VITE_VWR_URL),\n \"import.meta.env.VITE_CONFIG_URL\": JSON.stringify(\n config.VITE_CONFIG_URL\n ),\n \"import.meta.env.VITE_CONFIG_FILE\": JSON.stringify(\n config.VITE_CONFIG_FILE\n ),\n \"import.meta.env.VITE_LAUNCH_URL\": JSON.stringify(\n config.VITE_LAUNCH_URL\n ),\n },\n })\n\n // Copy build output to specified directory\n const outputPath = path.resolve(opts.output)\n\n await fs.ensureDir(outputPath)\n await fs.copy(loaderDistDir, outputPath, { overwrite: true })\n\n console.log(`✅ VWR loader built successfully`)\n console.log(` Output: ${outputPath}`)\n console.log(` Files: index.html, main.js`)\n\n} finally {\n // Cleanup temp dir\n try {\n await fs.remove(tmpDir)\n } catch (e) {\n console.warn(\"⚠️ Failed to cleanup temp dir:\", e)\n }\n}\n"],"names":["loadDotenv"],"mappings":";;;;;;;;AAQA,MAAM,qBAAqB;AAC3B,MAAM,sBAAsB;AAC5B,MAAM,uBAAuB;AAE7B,MAAM,aAAwB;AAAA,EAC1B,QAAQ;AAAA,EACR,QAAQ,yBAAyB,oBAAoB;AAAA,EACrD,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,cAAc;AAClB;AAEO,MAAM,eAA0C;AAAA,EACnD,OAAO;AAAA,IACH,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,cAAc;AAAA,EAAA;AAAA,EAElB,KAAK;AAAA,IACD,QAAQ;AAAA,IACR,QAAQ,6BAA6B,oBAAoB;AAAA,IACzD,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,cAAc;AAAA,EAAA;AAAA,EAElB,SAAS;AAAA,IACL,QAAQ;AAAA,IACR,QAAQ,iCAAiC,oBAAoB;AAAA,IAC7D,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,cAAc;AAAA,EAAA;AAAA,EAElB,MAAM;AAAA,EACN,YAAY;AAAA;AAChB;AClCA,MAAM,YAAY,KAAK,QAAQ,cAAc,YAAY,GAAG,CAAC;AAG7D,MAAM,iBAAiB,KAAK;AAAA,EACxB,GAAG,aAAa,KAAK,KAAK,WAAW,iBAAiB,GAAG,OAAO;AACpE;AAEA,MAAM,kBAAkB;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ;AAEA,MAAM,UAAU,IAAI,QAAA;AAEpB,QACK,KAAK,cAAc,EACnB,QAAQ,eAAe,OAAO,EAC9B,YAAY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c,YAAY;AAAA,QAAA;AAAA,QAE9C,QAAQ;AAAA,UACJ,gBAAgB;AAAA,UAChB,gBAAgB;AAAA,QAAA;AAAA,MACpB;AAAA,IACJ;AAAA,IAEJ,QAAQ;AAAA,MACJ,oCAAoC,KAAK,UAAU,KAAK,GAAG;AAAA,MAC3D,iCAAiC,KAAK,UAAU,OAAO,aAAa;AAAA,MACpE,sCAAsC,KAAK,UAAU,YAAY;AAAA,MACjE,gCAAgC,KAAK,UAAU,OAAO,YAAY;AAAA,MAClE,iDAAiD,KAAK;AAAA,QAClD,OAAO;AAAA,MAAA;AAAA,MAEX,gCAAgC,KAAK,UAAU,OAAO,YAAY;AAAA,MAClE,mCAAmC,KAAK;AAAA,QACpC,OAAO;AAAA,MAAA;AAAA,MAEX,oCAAoC,KAAK;AAAA,QACrC,OAAO;AAAA,MAAA;AAAA,MAEX,mCAAmC,KAAK;AAAA,QACpC,OAAO;AAAA,MAAA;AAAA,IACX;AAAA,EACJ,CACH;AAGD,QAAM,aAAa,KAAK,QAAQ,KAAK,MAAM;AAE3C,QAAM,GAAG,UAAU,UAAU;AAC7B,QAAM,GAAG,KAAK,eAAe,YAAY,EAAE,WAAW,MAAM;AAE5D,UAAQ,IAAI,iCAAiC;AAC7C,UAAQ,IAAI,cAAc,UAAU,EAAE;AACtC,UAAQ,IAAI,+BAA+B;AAE/C,UAAA;AAEI,MAAI;AACA,UAAM,GAAG,OAAO,MAAM;AAAA,EAC1B,SAAS,GAAG;AACR,YAAQ,KAAK,kCAAkC,CAAC;AAAA,EACpD;AACJ;"}
@@ -0,0 +1,9 @@
1
+ export interface EnvConfig {
2
+ hubUrl: string;
3
+ vwrUrl: string;
4
+ configUrl: string;
5
+ configFile: string;
6
+ amplitudeKey: string;
7
+ }
8
+ export declare const ENV_DEFAULTS: Record<string, EnvConfig>;
9
+ //# sourceMappingURL=envDefaults.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envDefaults.d.ts","sourceRoot":"","sources":["../src/envDefaults.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,MAAM,CAAA;CACvB;AAcD,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAwBlD,CAAA"}
@@ -0,0 +1,36 @@
1
+ const CONFIG_URL_DEFAULT = "https://vwr.volley.tv/config/";
2
+ const CONFIG_FILE_DEFAULT = "vwrConfig.json";
3
+ const VWR_URL_PATH_DEFAULT = "v1/latest/vwr.js";
4
+ const prodConfig = {
5
+ hubUrl: "https://game-clients.volley.tv/hub",
6
+ vwrUrl: `https://vwr.volley.tv/${VWR_URL_PATH_DEFAULT}`,
7
+ configUrl: CONFIG_URL_DEFAULT,
8
+ configFile: CONFIG_FILE_DEFAULT,
9
+ amplitudeKey: "",
10
+ };
11
+ export const ENV_DEFAULTS = {
12
+ local: {
13
+ hubUrl: "http://localhost:5173",
14
+ vwrUrl: "http://localhost:5174/vwr.js",
15
+ configUrl: "http://localhost:5174/config/",
16
+ configFile: CONFIG_FILE_DEFAULT,
17
+ amplitudeKey: "client-uJJVW3zKPC1G9kqPhUumLnZN6eaY42iQ",
18
+ },
19
+ dev: {
20
+ hubUrl: "https://game-clients-dev.volley.tv/hub",
21
+ vwrUrl: `https://vwr.volley.tv/dev/${VWR_URL_PATH_DEFAULT}`,
22
+ configUrl: CONFIG_URL_DEFAULT,
23
+ configFile: CONFIG_FILE_DEFAULT,
24
+ amplitudeKey: "client-uJJVW3zKPC1G9kqPhUumLnZN6eaY42iQ",
25
+ },
26
+ staging: {
27
+ hubUrl: "https://game-clients-staging.volley.tv/hub",
28
+ vwrUrl: `https://vwr.volley.tv/staging/${VWR_URL_PATH_DEFAULT}`,
29
+ configUrl: CONFIG_URL_DEFAULT,
30
+ configFile: CONFIG_FILE_DEFAULT,
31
+ amplitudeKey: "",
32
+ },
33
+ prod: prodConfig,
34
+ production: prodConfig, // Alias for prod
35
+ };
36
+ //# sourceMappingURL=envDefaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envDefaults.js","sourceRoot":"","sources":["../src/envDefaults.ts"],"names":[],"mappings":"AAQA,MAAM,kBAAkB,GAAG,+BAA+B,CAAA;AAC1D,MAAM,mBAAmB,GAAG,gBAAgB,CAAA;AAC5C,MAAM,oBAAoB,GAAG,kBAAkB,CAAA;AAE/C,MAAM,UAAU,GAAc;IAC1B,MAAM,EAAE,oCAAoC;IAC5C,MAAM,EAAE,yBAAyB,oBAAoB,EAAE;IACvD,SAAS,EAAE,kBAAkB;IAC7B,UAAU,EAAE,mBAAmB;IAC/B,YAAY,EAAE,EAAE;CACnB,CAAA;AAED,MAAM,CAAC,MAAM,YAAY,GAA8B;IACnD,KAAK,EAAE;QACH,MAAM,EAAE,uBAAuB;QAC/B,MAAM,EAAE,8BAA8B;QACtC,SAAS,EAAE,+BAA+B;QAC1C,UAAU,EAAE,mBAAmB;QAC/B,YAAY,EAAE,yCAAyC;KAC1D;IACD,GAAG,EAAE;QACD,MAAM,EAAE,wCAAwC;QAChD,MAAM,EAAE,6BAA6B,oBAAoB,EAAE;QAC3D,SAAS,EAAE,kBAAkB;QAC7B,UAAU,EAAE,mBAAmB;QAC/B,YAAY,EAAE,yCAAyC;KAC1D;IACD,OAAO,EAAE;QACL,MAAM,EAAE,4CAA4C;QACpD,MAAM,EAAE,iCAAiC,oBAAoB,EAAE;QAC/D,SAAS,EAAE,kBAAkB;QAC7B,UAAU,EAAE,mBAAmB;QAC/B,YAAY,EAAE,EAAE;KACnB;IACD,IAAI,EAAE,UAAU;IAChB,UAAU,EAAE,UAAU,EAAE,iBAAiB;CAC5C,CAAA"}
@@ -0,0 +1,65 @@
1
+ import { type Logger } from "./logger";
2
+ /**
3
+ * Get a unique device identifier for the current platform.
4
+ *
5
+ * This function attempts to retrieve a device ID from platform-specific APIs.
6
+ *
7
+ * Platform handling:
8
+ * - FireTV: DeviceInfo (Capacitor plugin)
9
+ * - Android/iOS: NativeBridge
10
+ * - Samsung TV: webapis
11
+ * - LG TV: webOS Luna service
12
+ * - Web: localStorage (with generated UUID fallback)
13
+ *
14
+ * @param platform - Platform identifier ('FIRE_TV', 'SAMSUNG_TV', 'LG_TV', 'ANDROID_MOBILE', 'IOS_MOBILE', 'WEB')
15
+ * @param logger - Optional logger for error reporting. Defaults to defaultLogger.
16
+ * @returns A promise that resolves to a unique device identifier string, or null if retrieval fails
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const deviceId = await getDeviceId('SAMSUNG_TV', logger)
21
+ * if (!deviceId) {
22
+ * // Handle error
23
+ * }
24
+ * ```
25
+ */
26
+ export declare function getDeviceId(platform: string, logger?: Logger): Promise<string | null>;
27
+ interface LGDeviceIdResponse {
28
+ idList?: Array<{
29
+ idValue?: string;
30
+ }>;
31
+ }
32
+ declare global {
33
+ interface Window {
34
+ DeviceInfo?: {
35
+ getAndroidId: () => Promise<{
36
+ androidId: string;
37
+ }>;
38
+ };
39
+ NativeBridge?: {
40
+ getDeviceId: () => Promise<string>;
41
+ };
42
+ webapis?: {
43
+ productinfo?: {
44
+ getDuid: () => string;
45
+ };
46
+ };
47
+ webOS?: {
48
+ service?: {
49
+ request: (uri: string, options: {
50
+ method?: string;
51
+ parameters?: Record<string, unknown>;
52
+ onSuccess?: (response: LGDeviceIdResponse) => void;
53
+ onFailure?: (error: {
54
+ errorText?: string;
55
+ }) => void;
56
+ subscribe?: boolean;
57
+ }) => {
58
+ cancel: () => void;
59
+ };
60
+ };
61
+ };
62
+ }
63
+ }
64
+ export {};
65
+ //# sourceMappingURL=getDeviceId.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getDeviceId.d.ts","sourceRoot":"","sources":["../src/getDeviceId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,MAAM,EAAE,MAAM,UAAU,CA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