@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.
Files changed (60) hide show
  1. package/README.md +21 -0
  2. package/dist/amplitudeFlagFetcher.d.ts +4 -2
  3. package/dist/amplitudeFlagFetcher.d.ts.map +1 -1
  4. package/dist/amplitudeFlagFetcher.js +26 -19
  5. package/dist/amplitudeFlagFetcher.js.map +1 -1
  6. package/dist/cli.js +213 -0
  7. package/dist/cli.js.map +1 -0
  8. package/dist/envDefaults.d.ts +3 -0
  9. package/dist/envDefaults.d.ts.map +1 -1
  10. package/dist/envDefaults.js +16 -4
  11. package/dist/envDefaults.js.map +1 -1
  12. package/dist/getDeviceId.d.ts +2 -40
  13. package/dist/getDeviceId.d.ts.map +1 -1
  14. package/dist/getDeviceId.js +31 -18
  15. package/dist/getDeviceId.js.map +1 -1
  16. package/dist/getEnvironment.d.ts +1 -1
  17. package/dist/getEnvironment.d.ts.map +1 -1
  18. package/dist/getEnvironment.js +15 -7
  19. package/dist/getEnvironment.js.map +1 -1
  20. package/dist/getShellVersion.d.ts +2 -19
  21. package/dist/getShellVersion.d.ts.map +1 -1
  22. package/dist/getShellVersion.js +41 -6
  23. package/dist/getShellVersion.js.map +1 -1
  24. package/dist/index.html +1 -1
  25. package/dist/loadVwr.d.ts.map +1 -1
  26. package/dist/loadVwr.js +8 -6
  27. package/dist/loadVwr.js.map +1 -1
  28. package/dist/main.js +1 -1
  29. package/dist/main.js.map +1 -1
  30. package/dist/types.d.ts +87 -0
  31. package/dist/types.d.ts.map +1 -0
  32. package/dist/types.js +5 -0
  33. package/dist/types.js.map +1 -0
  34. package/dist/vwrConfig.d.ts +2 -0
  35. package/dist/vwrConfig.d.ts.map +1 -1
  36. package/dist/vwrConfig.js +148 -119
  37. package/dist/vwrConfig.js.map +1 -1
  38. package/package.json +16 -5
  39. package/src/amplitudeFlagFetcher.test.ts +36 -59
  40. package/src/amplitudeFlagFetcher.ts +31 -22
  41. package/src/envDefaults.ts +23 -4
  42. package/src/getDeviceId.test.ts +89 -27
  43. package/src/getDeviceId.ts +35 -58
  44. package/src/getEnvironment.test.ts +479 -0
  45. package/src/getEnvironment.ts +16 -8
  46. package/src/getShellVersion.test.ts +123 -4
  47. package/src/getShellVersion.ts +46 -21
  48. package/src/loadVwr.ts +13 -6
  49. package/src/main.ts +3 -1
  50. package/src/types.ts +88 -0
  51. package/src/vite-env.d.ts +3 -0
  52. package/src/vwrConfig.test.ts +2 -2
  53. package/src/vwrConfig.ts +202 -199
  54. package/eslint.config.mjs +0 -23
  55. package/scripts/build.js +0 -2
  56. package/scripts/build.ts +0 -207
  57. package/tsconfig.eslint.json +0 -16
  58. package/tsconfig.json +0 -17
  59. package/vite.config.ts +0 -24
  60. package/vitest.config.ts +0 -8
@@ -1,4 +1,5 @@
1
1
  import { defaultLogger, type Logger } from "./logger"
2
+ import type { MobileExtendedWindow } from "./types"
2
3
 
3
4
  /**
4
5
  * Retrieve shell app version for different platforms.
@@ -7,10 +8,10 @@ import { defaultLogger, type Logger } from "./logger"
7
8
  * - SAMSUNG_TV: Tizen Application API `tizen.application.getAppInfo().version`
8
9
  * - LG_TV: webOS Application API `webOS.fetchAppInfo()`
9
10
  * - FIRE_TV: Native bridge via Capacitor DeviceInfo plugin
10
- * - MOBILE: Native bridge (future implementation)
11
+ * - ANDROID_MOBILE/IOS_MOBILE: Native app context `window.iosAppContext.appVersion` / `window.androidAppContext.appVersion`
11
12
  * - WEB/Unknown: Returns 'unknown'
12
13
  *
13
- * @param platform - Platform identifier (SAMSUNG_TV, LG_TV, FIRE_TV, MOBILE, WEB)
14
+ * @param platform - Platform identifier (SAMSUNG_TV, LG_TV, FIRE_TV, ANDROID_MOBILE, IOS_MOBILE, WEB)
14
15
  * @param logger - Optional logger for warning reporting. Defaults to defaultLogger.
15
16
  * @returns Shell version string or 'unknown' if not available
16
17
  */
@@ -65,10 +66,12 @@ export async function getShellVersion(
65
66
  return "unknown"
66
67
  }
67
68
 
68
- // Mobile: Future implementation via native bridge
69
- if (normalizedPlatform === "MOBILE") {
70
- // TODO: Implement native bridge version retrieval when available
71
- return "unknown"
69
+ // Mobile: Get version from native app context
70
+ if (
71
+ normalizedPlatform === "ANDROID_MOBILE" ||
72
+ normalizedPlatform === "IOS_MOBILE"
73
+ ) {
74
+ return getMobileAppVersion(logger)
72
75
  }
73
76
 
74
77
  // Web platform: Check for injected version at build time
@@ -90,21 +93,43 @@ export async function getShellVersion(
90
93
  }
91
94
  }
92
95
 
93
- // Global type declarations for platform APIs
94
- declare global {
95
- interface Window {
96
- Capacitor?: {
97
- Plugins?: {
98
- DeviceInfo?: {
99
- getDeviceInfo(): Promise<{
100
- versionName?: string
101
- [key: string]: any
102
- }>
103
- [key: string]: any
104
- }
105
- [key: string]: any
106
- }
107
- [key: string]: any
96
+ /**
97
+ * Get app version from mobile native app context (iOS/Android)
98
+ *
99
+ * iOS exposes appVersion via window.iosAppContext
100
+ * Android exposes appVersion via window.androidAppContext (also check window.top for iframes)
101
+ */
102
+ function getMobileAppVersion(logger: Logger): string {
103
+ // Try iOS first
104
+ const iosVersion = (window as MobileExtendedWindow).iosAppContext
105
+ ?.appVersion
106
+ if (iosVersion && iosVersion.trim()) {
107
+ return iosVersion
108
+ }
109
+
110
+ // Try Android (check both window and window.top for iframe scenarios)
111
+ const androidContext = (window as MobileExtendedWindow).androidAppContext
112
+ try {
113
+ const androidVersion =
114
+ androidContext?.appVersion ??
115
+ (window.top as MobileExtendedWindow | null)?.androidAppContext
116
+ ?.appVersion
117
+ if (androidVersion && androidVersion.trim()) {
118
+ return androidVersion
119
+ }
120
+ } catch {
121
+ // window.top access can throw if cross-origin
122
+ const androidVersion = androidContext?.appVersion
123
+ if (androidVersion && androidVersion.trim()) {
124
+ return androidVersion
108
125
  }
109
126
  }
127
+
128
+ logger.warn("[VWR:MobileAppVersion] appVersion not found", {
129
+ iosAppContext: !!(window as MobileExtendedWindow).iosAppContext,
130
+ androidAppContext: !!androidContext,
131
+ })
132
+ return "unknown"
110
133
  }
134
+
135
+ // Types imported from ./types.ts
package/src/loadVwr.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type * as VWR from "@volley/vwr"
2
+
1
3
  import { fetchAmplitudeFlags } from "./amplitudeFlagFetcher"
2
4
  import { ENV_DEFAULTS } from "./envDefaults"
3
5
  import { getDeviceId } from "./getDeviceId"
@@ -83,7 +85,8 @@ export const loadVwr = async (logger: Logger = defaultLogger) => {
83
85
  apiKey: amplitudeKey,
84
86
  timeout: 2000,
85
87
  },
86
- shellVersion
88
+ shellVersion,
89
+ logger
87
90
  )
88
91
 
89
92
  logger.info("[Shell] Flags fetched", { flags })
@@ -115,7 +118,10 @@ export const loadVwr = async (logger: Logger = defaultLogger) => {
115
118
  vwrUrl: vwrConfig.vwrUrl,
116
119
  })
117
120
  try {
118
- const vwr = await import(/* @vite-ignore */ vwrConfig.vwrUrl)
121
+ const vwr = (await import(
122
+ /* @vite-ignore */ vwrConfig.vwrUrl
123
+ )) as typeof VWR
124
+
119
125
  logger.info("[Shell] VWR module loaded successfully")
120
126
 
121
127
  if (typeof vwr.init !== "function") {
@@ -124,11 +130,12 @@ export const loadVwr = async (logger: Logger = defaultLogger) => {
124
130
 
125
131
  await vwr.init({
126
132
  hubUrl: vwrConfig.hubUrl,
127
- launchUrl: vwrConfig.launchUrl,
128
133
  platform: PLATFORM,
129
- deviceId,
130
- environment: ENVIRONMENT,
131
- trustedDomains: vwrConfig.trustedDomains,
134
+ stage: ENVIRONMENT,
135
+ appVersion: shellVersion,
136
+ platformApiUrl: vwrConfig.platformApiUrl,
137
+ platformAuthApiUrl: vwrConfig.platformAuthApiUrl,
138
+ trustedOrigins: new Set(vwrConfig.trustedDomains),
132
139
  nativeShellVersion: shellVersion,
133
140
  })
134
141
  logger.info("[Shell] VWR initialized successfully")
package/src/main.ts CHANGED
@@ -18,7 +18,9 @@ async function init() {
18
18
  }
19
19
  } finally {
20
20
  //Fallback, can't trust config exists
21
- window.location.href = HUB_URL
21
+ const fallbackUrl = new URL(HUB_URL)
22
+ fallbackUrl.searchParams.set("volley_platform", PLATFORM)
23
+ window.location.href = fallbackUrl.toString()
22
24
  }
23
25
  }
24
26
  }
package/src/types.ts ADDED
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Shared type definitions for vwr-loader platform APIs
3
+ */
4
+
5
+ /**
6
+ * Extended window interface for mobile app context.
7
+ * Matches the types from @volley/sdk ExtendedWindow.ts
8
+ */
9
+ export interface MobileExtendedWindow extends Window {
10
+ iosAppContext?: {
11
+ appVersion: string
12
+ environment?: string
13
+ phoneDeviceId?: string
14
+ }
15
+ androidAppContext?: {
16
+ appVersion: string
17
+ environment?: string
18
+ phoneDeviceId?: string
19
+ }
20
+ }
21
+
22
+ /**
23
+ * Global type declarations for platform APIs
24
+ */
25
+ declare global {
26
+ interface Window {
27
+ Capacitor?: {
28
+ Plugins?: {
29
+ DeviceInfo?: {
30
+ getDeviceInfo(): Promise<{
31
+ versionName?: string
32
+ [key: string]: any
33
+ }>
34
+ getAndroidId(): Promise<{
35
+ androidId?: string
36
+ [key: string]: any
37
+ }>
38
+ getNativeShellAppEnvironment(): Promise<{
39
+ environment?: string
40
+ }>
41
+ [key: string]: any
42
+ }
43
+ [key: string]: any
44
+ }
45
+ [key: string]: any
46
+ }
47
+ webapis?: {
48
+ productinfo?: {
49
+ getDuid: () => string
50
+ }
51
+ }
52
+ webOS?: {
53
+ service?: {
54
+ request: (
55
+ uri: string,
56
+ options: {
57
+ method?: string
58
+ parameters?: Record<string, unknown>
59
+ onSuccess?: (response: LGDeviceIdResponse) => void
60
+ onFailure?: (error: { errorText?: string }) => void
61
+ subscribe?: boolean
62
+ }
63
+ ) => {
64
+ cancel: () => void
65
+ }
66
+ }
67
+ fetchAppInfo?: (
68
+ callback: (appInfo?: { version?: string }) => void
69
+ ) => void
70
+ }
71
+ tizen?: {
72
+ application?: {
73
+ getAppInfo: () => { version?: string }
74
+ }
75
+ }
76
+ }
77
+ }
78
+
79
+ /**
80
+ * LG Luna service response for device ID
81
+ */
82
+ export interface LGDeviceIdResponse {
83
+ idList?: Array<{
84
+ idType?: string
85
+ idValue?: string
86
+ }>
87
+ returnValue?: boolean
88
+ }
package/src/vite-env.d.ts CHANGED
@@ -8,6 +8,9 @@ interface ImportMetaEnv {
8
8
  readonly VITE_SHELL_VERSION: string
9
9
  readonly VITE_CONFIG_URL: string
10
10
  readonly VITE_CONFIG_FILE: string
11
+ readonly VITE_PLATFORM_API_URL: string
12
+ readonly VITE_PLATFORM_AUTH_API_URL: string
13
+ readonly VITE_TRUSTED_ORIGINS: string
11
14
  }
12
15
 
13
16
  interface ImportMeta {
@@ -90,8 +90,8 @@ describe("vwrConfig", async () => {
90
90
  expect(config.hubUrl).toBe("https://game-clients.volley.tv/hub")
91
91
  expect(config.launchUrl).toBeUndefined() // Optional, not set by default
92
92
  expect(config.trustedDomains).toEqual([
93
- "https://game-clients.volley.tv/hub",
94
- "https://vwr.volley.tv/v1/latest/vwr.js",
93
+ "https://game-clients.volley.tv",
94
+ "https://vwr.volley.tv",
95
95
  ])
96
96
  })
97
97