@volley/vwr-loader 1.6.0 → 1.7.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/dist/cli.js +51 -25
- package/dist/cli.js.map +1 -1
- package/dist/vwr/src/envDefaults.d.ts.map +1 -1
- package/dist/vwr/src/envDefaults.js +6 -39
- package/dist/vwr/src/envDefaults.js.map +1 -1
- package/dist/vwr/src/iframe.d.ts +25 -0
- package/dist/vwr/src/iframe.d.ts.map +1 -0
- package/dist/vwr/src/iframe.js +82 -0
- package/dist/vwr/src/iframe.js.map +1 -0
- package/dist/vwr/src/native/app-lifecycle/factory.d.ts +7 -0
- package/dist/vwr/src/native/app-lifecycle/factory.d.ts.map +1 -0
- package/dist/vwr/src/native/app-lifecycle/factory.js +68 -0
- package/dist/vwr/src/native/app-lifecycle/factory.js.map +1 -0
- package/dist/vwr/src/native/app-lifecycle/rpc.d.ts +15 -0
- package/dist/vwr/src/native/app-lifecycle/rpc.d.ts.map +1 -0
- package/dist/vwr/src/native/app-lifecycle/rpc.js +46 -0
- package/dist/vwr/src/native/app-lifecycle/rpc.js.map +1 -0
- package/dist/vwr/src/native/capacitor-bridge/rpc.d.ts +33 -0
- package/dist/vwr/src/native/capacitor-bridge/rpc.d.ts.map +1 -0
- package/dist/vwr/src/native/capacitor-bridge/rpc.js +129 -0
- package/dist/vwr/src/native/capacitor-bridge/rpc.js.map +1 -0
- package/dist/vwr/src/native/device-info/factory.d.ts +9 -0
- package/dist/vwr/src/native/device-info/factory.d.ts.map +1 -0
- package/dist/vwr/src/native/device-info/factory.js +28 -0
- package/dist/vwr/src/native/device-info/factory.js.map +1 -0
- package/dist/vwr/src/native/device-info/firetvCollector.d.ts +9 -0
- package/dist/vwr/src/native/device-info/firetvCollector.d.ts.map +1 -0
- package/dist/vwr/src/native/device-info/firetvCollector.js +180 -0
- package/dist/vwr/src/native/device-info/firetvCollector.js.map +1 -0
- package/dist/vwr/src/native/device-info/lgCollector.d.ts +8 -0
- package/dist/vwr/src/native/device-info/lgCollector.d.ts.map +1 -0
- package/dist/vwr/src/native/device-info/lgCollector.js +136 -0
- package/dist/vwr/src/native/device-info/lgCollector.js.map +1 -0
- package/dist/vwr/src/native/device-info/mobileCollector.d.ts +9 -0
- package/dist/vwr/src/native/device-info/mobileCollector.d.ts.map +1 -0
- package/dist/vwr/src/native/device-info/mobileCollector.js +47 -0
- package/dist/vwr/src/native/device-info/mobileCollector.js.map +1 -0
- package/dist/vwr/src/native/device-info/rpc.d.ts +51 -0
- package/dist/vwr/src/native/device-info/rpc.d.ts.map +1 -0
- package/dist/vwr/src/native/device-info/rpc.js +46 -0
- package/dist/vwr/src/native/device-info/rpc.js.map +1 -0
- package/dist/vwr/src/native/device-info/samsungCollector.d.ts +9 -0
- package/dist/vwr/src/native/device-info/samsungCollector.d.ts.map +1 -0
- package/dist/vwr/src/native/device-info/samsungCollector.js +86 -0
- package/dist/vwr/src/native/device-info/samsungCollector.js.map +1 -0
- package/dist/vwr/src/native/device-info/webCollector.d.ts +4 -0
- package/dist/vwr/src/native/device-info/webCollector.d.ts.map +1 -0
- package/dist/vwr/src/native/device-info/webCollector.js +56 -0
- package/dist/vwr/src/native/device-info/webCollector.js.map +1 -0
- package/dist/vwr/src/native/native-bridge/rpc.d.ts +33 -0
- package/dist/vwr/src/native/native-bridge/rpc.d.ts.map +1 -0
- package/dist/vwr/src/native/native-bridge/rpc.js +114 -0
- package/dist/vwr/src/native/native-bridge/rpc.js.map +1 -0
- package/dist/vwr/src/native/screensaver-prevention/LGLunaService.d.ts +14 -0
- package/dist/vwr/src/native/screensaver-prevention/LGLunaService.d.ts.map +1 -0
- package/dist/vwr/src/native/screensaver-prevention/LGLunaService.js +187 -0
- package/dist/vwr/src/native/screensaver-prevention/LGLunaService.js.map +1 -0
- package/dist/vwr/src/native/screensaver-prevention/rpc.d.ts +27 -0
- package/dist/vwr/src/native/screensaver-prevention/rpc.d.ts.map +1 -0
- package/dist/vwr/src/native/screensaver-prevention/rpc.js +71 -0
- package/dist/vwr/src/native/screensaver-prevention/rpc.js.map +1 -0
- package/dist/vwr/src/observability.d.ts +35 -0
- package/dist/vwr/src/observability.d.ts.map +1 -0
- package/dist/vwr/src/observability.js +68 -0
- package/dist/vwr/src/observability.js.map +1 -0
- package/dist/vwr/src/shellEnvDefaults.d.ts +15 -0
- package/dist/vwr/src/shellEnvDefaults.d.ts.map +1 -0
- package/dist/vwr/src/shellEnvDefaults.js +34 -0
- package/dist/vwr/src/shellEnvDefaults.js.map +1 -0
- package/dist/vwr/src/types.d.ts +56 -0
- package/dist/vwr/src/types.d.ts.map +1 -0
- package/dist/vwr/src/types.js +27 -0
- package/dist/vwr/src/types.js.map +1 -0
- package/dist/vwr/src/urlUtils.d.ts +17 -0
- package/dist/vwr/src/urlUtils.d.ts.map +1 -0
- package/dist/vwr/src/urlUtils.js +42 -0
- package/dist/vwr/src/urlUtils.js.map +1 -0
- package/dist/vwr/src/vwrBootstrap.d.ts +26 -0
- package/dist/vwr/src/vwrBootstrap.d.ts.map +1 -0
- package/dist/vwr/src/vwrBootstrap.js +176 -0
- package/dist/vwr/src/vwrBootstrap.js.map +1 -0
- package/dist/vwr/src/vwrConfig.d.ts.map +1 -1
- package/dist/vwr/src/vwrConfig.js +11 -2
- package/dist/vwr/src/vwrConfig.js.map +1 -1
- package/{src → dist/vwr-loader}/index.html +1 -1
- package/dist/vwr-loader/src/__mocks__/invalidVwrModule.d.ts +2 -0
- package/dist/vwr-loader/src/__mocks__/invalidVwrModule.d.ts.map +1 -0
- package/dist/vwr-loader/src/__mocks__/invalidVwrModule.js +2 -0
- package/dist/vwr-loader/src/__mocks__/invalidVwrModule.js.map +1 -0
- package/dist/vwr-loader/src/index.d.ts +3 -3
- package/dist/vwr-loader/src/index.d.ts.map +1 -1
- package/dist/vwr-loader/src/index.js +2 -2
- package/dist/vwr-loader/src/index.js.map +1 -1
- package/dist/vwr-loader/src/loadVwr.d.ts.map +1 -1
- package/dist/vwr-loader/src/loadVwr.js +28 -22
- package/dist/vwr-loader/src/loadVwr.js.map +1 -1
- package/dist/vwr-loader/src/logger.d.ts +1 -1
- package/dist/vwr-loader/src/logger.d.ts.map +1 -1
- package/dist/vwr-loader/src/logger.js +1 -1
- package/dist/vwr-loader/src/logger.js.map +1 -1
- package/dist/vwr-loader/src/main.js +1 -1
- package/dist/vwr-loader/src/main.js.map +1 -1
- package/package.json +4 -5
- package/dist/assets/profiler-BRmTNL9s.js +0 -2
- package/dist/assets/profiler-BRmTNL9s.js.map +0 -1
- package/dist/assets/startRecording-CuFdVhxx.js +0 -3
- package/dist/assets/startRecording-CuFdVhxx.js.map +0 -1
- package/dist/index.html +0 -25
- package/dist/main.js +0 -12
- package/dist/main.js.map +0 -1
- package/src/__mocks__/@datadog/browser-logs.ts +0 -35
- package/src/__mocks__/@datadog/browser-rum.ts +0 -27
- package/src/__mocks__/vwrModule.ts +0 -3
- package/src/amplitudeFlagFetcher.test.ts +0 -175
- package/src/amplitudeFlagFetcher.ts +0 -105
- package/src/errors/InitializationError.ts +0 -105
- package/src/errors/ensureError.ts +0 -6
- package/src/errors/index.ts +0 -16
- package/src/exitHandler.test.ts +0 -417
- package/src/exitHandler.ts +0 -233
- package/src/getEnvironment.test.ts +0 -417
- package/src/getEnvironment.ts +0 -144
- package/src/getShellVersion.test.ts +0 -403
- package/src/getShellVersion.ts +0 -133
- package/src/index.ts +0 -7
- package/src/loadVwr.test.ts +0 -554
- package/src/loadVwr.ts +0 -363
- package/src/logger.ts +0 -11
- package/src/main.test.ts +0 -157
- package/src/main.ts +0 -128
- package/src/polyfills.ts +0 -32
- package/src/test-setup.ts +0 -5
- package/src/vite-env.d.ts +0 -33
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { vi } from "vitest"
|
|
2
|
-
|
|
3
|
-
const mockLogger = {
|
|
4
|
-
debug: vi.fn(),
|
|
5
|
-
info: vi.fn(),
|
|
6
|
-
warn: vi.fn(),
|
|
7
|
-
error: vi.fn(),
|
|
8
|
-
log: vi.fn(),
|
|
9
|
-
setLevel: vi.fn(),
|
|
10
|
-
setHandler: vi.fn(),
|
|
11
|
-
setContext: vi.fn(),
|
|
12
|
-
addContext: vi.fn(),
|
|
13
|
-
removeContext: vi.fn(),
|
|
14
|
-
clearContext: vi.fn(),
|
|
15
|
-
getContext: vi.fn(() => ({})),
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const datadogLogs = {
|
|
19
|
-
init: vi.fn(),
|
|
20
|
-
logger: mockLogger,
|
|
21
|
-
createLogger: vi.fn(() => mockLogger),
|
|
22
|
-
getLogger: vi.fn(() => mockLogger),
|
|
23
|
-
setUser: vi.fn(),
|
|
24
|
-
setUserProperty: vi.fn(),
|
|
25
|
-
removeUserProperty: vi.fn(),
|
|
26
|
-
clearUser: vi.fn(),
|
|
27
|
-
getUser: vi.fn(() => ({})),
|
|
28
|
-
setGlobalContext: vi.fn(),
|
|
29
|
-
setGlobalContextProperty: vi.fn(),
|
|
30
|
-
removeGlobalContextProperty: vi.fn(),
|
|
31
|
-
clearGlobalContext: vi.fn(),
|
|
32
|
-
getGlobalContext: vi.fn(() => ({})),
|
|
33
|
-
getInitConfiguration: vi.fn(() => ({})),
|
|
34
|
-
getInternalContext: vi.fn(() => ({})),
|
|
35
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { vi } from "vitest"
|
|
2
|
-
|
|
3
|
-
export const datadogRum = {
|
|
4
|
-
init: vi.fn(),
|
|
5
|
-
startSessionReplayRecording: vi.fn(),
|
|
6
|
-
stopSessionReplayRecording: vi.fn(),
|
|
7
|
-
addAction: vi.fn(),
|
|
8
|
-
addError: vi.fn(),
|
|
9
|
-
addTiming: vi.fn(),
|
|
10
|
-
setUser: vi.fn(),
|
|
11
|
-
setUserProperty: vi.fn(),
|
|
12
|
-
removeUserProperty: vi.fn(),
|
|
13
|
-
clearUser: vi.fn(),
|
|
14
|
-
setGlobalContext: vi.fn(),
|
|
15
|
-
setGlobalContextProperty: vi.fn(),
|
|
16
|
-
removeGlobalContextProperty: vi.fn(),
|
|
17
|
-
clearGlobalContext: vi.fn(),
|
|
18
|
-
getGlobalContext: vi.fn(() => ({})),
|
|
19
|
-
getUser: vi.fn(() => ({})),
|
|
20
|
-
getInitConfiguration: vi.fn(() => ({})),
|
|
21
|
-
getInternalContext: vi.fn(() => ({})),
|
|
22
|
-
addFeatureFlagEvaluation: vi.fn(),
|
|
23
|
-
startView: vi.fn(),
|
|
24
|
-
stopView: vi.fn(),
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export type RumGlobal = typeof datadogRum
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"
|
|
2
|
-
|
|
3
|
-
import { fetchAmplitudeFlags, FlagFetchError } from "./amplitudeFlagFetcher"
|
|
4
|
-
|
|
5
|
-
describe("fetchAmplitudeFlags", () => {
|
|
6
|
-
const mockFetch = vi.fn()
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
global.fetch = mockFetch
|
|
10
|
-
vi.clearAllMocks()
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
afterEach(() => {
|
|
14
|
-
vi.restoreAllMocks()
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
it("fetches flags successfully from Amplitude with context", async () => {
|
|
18
|
-
mockFetch.mockResolvedValueOnce({
|
|
19
|
-
ok: true,
|
|
20
|
-
json: async () => ({
|
|
21
|
-
"vwr-enabled": {
|
|
22
|
-
payload: {
|
|
23
|
-
"vwr-enabled": true,
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
}),
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
const result = await fetchAmplitudeFlags(
|
|
30
|
-
"device-123",
|
|
31
|
-
"SAMSUNG_TV",
|
|
32
|
-
{ apiKey: "test-key" },
|
|
33
|
-
"1.0.0"
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
expect(result).toEqual({
|
|
37
|
-
"vwr-enabled": true,
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
// Verify context is included in the request
|
|
41
|
-
const callArgs = mockFetch.mock.calls[0]
|
|
42
|
-
const url = new URL(callArgs[0])
|
|
43
|
-
const context = JSON.parse(url.searchParams.get("context") || "{}")
|
|
44
|
-
|
|
45
|
-
expect(context).toEqual({
|
|
46
|
-
user_properties: {
|
|
47
|
-
platformEnum: "SAMSUNG_TV",
|
|
48
|
-
nativeShellAppVersion: "1.0.0",
|
|
49
|
-
},
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
53
|
-
expect.stringContaining("user_id=device-123"),
|
|
54
|
-
expect.objectContaining({
|
|
55
|
-
method: "GET",
|
|
56
|
-
headers: { Authorization: "Api-Key test-key" },
|
|
57
|
-
})
|
|
58
|
-
)
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
it("includes provided shell version in context", async () => {
|
|
62
|
-
mockFetch.mockResolvedValueOnce({
|
|
63
|
-
ok: true,
|
|
64
|
-
json: async () => ({
|
|
65
|
-
"vwr-enabled": {
|
|
66
|
-
payload: {
|
|
67
|
-
"vwr-enabled": true,
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
}),
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
await fetchAmplitudeFlags(
|
|
74
|
-
"device-123",
|
|
75
|
-
"SAMSUNG_TV",
|
|
76
|
-
{
|
|
77
|
-
apiKey: "test-key",
|
|
78
|
-
},
|
|
79
|
-
"2.5.0"
|
|
80
|
-
)
|
|
81
|
-
|
|
82
|
-
const callArgs = mockFetch.mock.calls[0]
|
|
83
|
-
const url = new URL(callArgs[0])
|
|
84
|
-
const context = JSON.parse(url.searchParams.get("context") || "{}")
|
|
85
|
-
|
|
86
|
-
expect(context).toEqual({
|
|
87
|
-
user_properties: {
|
|
88
|
-
platformEnum: "SAMSUNG_TV",
|
|
89
|
-
nativeShellAppVersion: "2.5.0",
|
|
90
|
-
},
|
|
91
|
-
})
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
it("throws FlagFetchError on timeout", async () => {
|
|
95
|
-
mockFetch.mockImplementationOnce(
|
|
96
|
-
() => new Promise((resolve) => setTimeout(resolve, 3000))
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
await expect(
|
|
100
|
-
fetchAmplitudeFlags(
|
|
101
|
-
"device-123",
|
|
102
|
-
"FIRE_TV",
|
|
103
|
-
{ apiKey: "test-key", timeout: 100 },
|
|
104
|
-
"1.0.0"
|
|
105
|
-
)
|
|
106
|
-
).rejects.toThrow(FlagFetchError)
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
it("throws FlagFetchError on API error", async () => {
|
|
110
|
-
mockFetch.mockResolvedValueOnce({
|
|
111
|
-
ok: false,
|
|
112
|
-
status: 500,
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
await expect(
|
|
116
|
-
fetchAmplitudeFlags(
|
|
117
|
-
"device-123",
|
|
118
|
-
"MOBILE",
|
|
119
|
-
{ apiKey: "test-key" },
|
|
120
|
-
"1.0.0"
|
|
121
|
-
)
|
|
122
|
-
).rejects.toThrow(FlagFetchError)
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
it("throws FlagFetchError on network error", async () => {
|
|
126
|
-
mockFetch.mockRejectedValueOnce(new Error("Network error"))
|
|
127
|
-
|
|
128
|
-
await expect(
|
|
129
|
-
fetchAmplitudeFlags(
|
|
130
|
-
"device-123",
|
|
131
|
-
"MOBILE",
|
|
132
|
-
{ apiKey: "test-key" },
|
|
133
|
-
"1.0.0"
|
|
134
|
-
)
|
|
135
|
-
).rejects.toThrow(FlagFetchError)
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
it("handles missing flag values in response", async () => {
|
|
139
|
-
mockFetch.mockResolvedValueOnce({
|
|
140
|
-
ok: true,
|
|
141
|
-
json: async () => ({}),
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
const result = await fetchAmplitudeFlags(
|
|
145
|
-
"device-123",
|
|
146
|
-
"LG_TV",
|
|
147
|
-
{ apiKey: "test-key" },
|
|
148
|
-
"1.0.0"
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
expect(result).toEqual({
|
|
152
|
-
"vwr-enabled": false,
|
|
153
|
-
})
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
it("handles partial response with missing payload", async () => {
|
|
157
|
-
mockFetch.mockResolvedValueOnce({
|
|
158
|
-
ok: true,
|
|
159
|
-
json: async () => ({
|
|
160
|
-
"vwr-enabled": {},
|
|
161
|
-
}),
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
const result = await fetchAmplitudeFlags(
|
|
165
|
-
"device-123",
|
|
166
|
-
"LG_TV",
|
|
167
|
-
{ apiKey: "test-key" },
|
|
168
|
-
"1.0.0"
|
|
169
|
-
)
|
|
170
|
-
|
|
171
|
-
expect(result).toEqual({
|
|
172
|
-
"vwr-enabled": false,
|
|
173
|
-
})
|
|
174
|
-
})
|
|
175
|
-
})
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
export interface AmplitudeConfig {
|
|
2
|
-
apiKey: string
|
|
3
|
-
apiUrl?: string
|
|
4
|
-
timeout?: number
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface FlagResult {
|
|
8
|
-
"vwr-enabled": boolean
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export class FlagFetchError extends Error {
|
|
12
|
-
public readonly name = "FlagFetchError"
|
|
13
|
-
|
|
14
|
-
constructor(
|
|
15
|
-
message: string,
|
|
16
|
-
public readonly cause?: Error
|
|
17
|
-
) {
|
|
18
|
-
super(message)
|
|
19
|
-
Object.setPrototypeOf(this, FlagFetchError.prototype)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Fetch feature flags from Amplitude Experiment REST API.
|
|
25
|
-
*
|
|
26
|
-
* Uses GET method with query parameters and Authorization header.
|
|
27
|
-
* Includes platform and shell version in context for better flag targeting.
|
|
28
|
-
* Compatible with Chrome 66+ (Fetch API, async/await, AbortController).
|
|
29
|
-
*
|
|
30
|
-
* @param deviceId - Unique device identifier
|
|
31
|
-
* @param platform - Platform name (samsung, lg, firetv, ios, android)
|
|
32
|
-
* @param config - Amplitude configuration
|
|
33
|
-
* @param shellVersion - Shell version for flag targeting
|
|
34
|
-
* @param logger - Optional logger, defaults to console
|
|
35
|
-
* @returns Flag values on success
|
|
36
|
-
* @throws FlagFetchError on timeout or network error
|
|
37
|
-
*/
|
|
38
|
-
export async function fetchAmplitudeFlags(
|
|
39
|
-
deviceId: string,
|
|
40
|
-
platform: string,
|
|
41
|
-
config: AmplitudeConfig,
|
|
42
|
-
shellVersion: string
|
|
43
|
-
): Promise<FlagResult> {
|
|
44
|
-
const {
|
|
45
|
-
apiKey,
|
|
46
|
-
apiUrl = "https://api.lab.amplitude.com/v1/vardata",
|
|
47
|
-
timeout = 2000,
|
|
48
|
-
} = config
|
|
49
|
-
|
|
50
|
-
// Build context with user_properties
|
|
51
|
-
const context = {
|
|
52
|
-
user_properties: {
|
|
53
|
-
platformEnum: platform,
|
|
54
|
-
nativeShellAppVersion: shellVersion,
|
|
55
|
-
},
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Build query parameters
|
|
59
|
-
const params = new URLSearchParams({
|
|
60
|
-
user_id: deviceId,
|
|
61
|
-
flag_keys: "vwr-enabled",
|
|
62
|
-
context: JSON.stringify(context),
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
// Start timeout immediately before the fetch call for accurate timing
|
|
66
|
-
const controller = new AbortController()
|
|
67
|
-
const timeoutId = setTimeout(() => controller.abort(), timeout)
|
|
68
|
-
|
|
69
|
-
try {
|
|
70
|
-
const response = await fetch(`${apiUrl}?${params}`, {
|
|
71
|
-
method: "GET",
|
|
72
|
-
headers: {
|
|
73
|
-
Authorization: `Api-Key ${apiKey}`,
|
|
74
|
-
},
|
|
75
|
-
signal: controller.signal,
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
clearTimeout(timeoutId)
|
|
79
|
-
|
|
80
|
-
if (!response.ok) {
|
|
81
|
-
throw new Error(`Amplitude API returned ${response.status}`)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const data = await response.json()
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
"vwr-enabled":
|
|
88
|
-
data["vwr-enabled"]?.payload?.["vwr-enabled"] ?? false,
|
|
89
|
-
}
|
|
90
|
-
} catch (error) {
|
|
91
|
-
clearTimeout(timeoutId)
|
|
92
|
-
|
|
93
|
-
// Provide clear error message for abort vs other errors
|
|
94
|
-
if (error instanceof Error && error.name === "AbortError") {
|
|
95
|
-
throw new FlagFetchError(
|
|
96
|
-
`Amplitude flag fetch timed out after ${timeout}ms`
|
|
97
|
-
)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
throw new FlagFetchError(
|
|
101
|
-
"Amplitude flag fetch failed",
|
|
102
|
-
error instanceof Error ? error : undefined
|
|
103
|
-
)
|
|
104
|
-
}
|
|
105
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reason codes for VWR loader initialization failures.
|
|
3
|
-
* Each code maps to a specific failure point in the init flow.
|
|
4
|
-
*/
|
|
5
|
-
export const InitializationErrorReason = {
|
|
6
|
-
// Environment variable errors
|
|
7
|
-
ENV_VARS_MISSING: "ENV_VARS_MISSING",
|
|
8
|
-
ENV_UNKNOWN: "ENV_UNKNOWN",
|
|
9
|
-
|
|
10
|
-
// Device/platform errors
|
|
11
|
-
DEVICE_ID_FAILED: "DEVICE_ID_FAILED",
|
|
12
|
-
SHELL_VERSION_FAILED: "SHELL_VERSION_FAILED",
|
|
13
|
-
|
|
14
|
-
// Feature flag errors
|
|
15
|
-
FLAG_DISABLED: "FLAG_DISABLED",
|
|
16
|
-
FLAG_FETCH_FAILED: "FLAG_FETCH_FAILED",
|
|
17
|
-
|
|
18
|
-
// Runtime config errors
|
|
19
|
-
CONFIG_FETCH_FAILED: "CONFIG_FETCH_FAILED",
|
|
20
|
-
CONFIG_INVALID: "CONFIG_INVALID",
|
|
21
|
-
|
|
22
|
-
// Module loading errors
|
|
23
|
-
MODULE_FETCH_FAILED: "MODULE_FETCH_FAILED",
|
|
24
|
-
MODULE_INVALID: "MODULE_INVALID",
|
|
25
|
-
|
|
26
|
-
// VWR init errors
|
|
27
|
-
INIT_FAILED: "INIT_FAILED",
|
|
28
|
-
} as const
|
|
29
|
-
|
|
30
|
-
export type InitializationErrorReason =
|
|
31
|
-
(typeof InitializationErrorReason)[keyof typeof InitializationErrorReason]
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Context for initialization errors - used for structured logging
|
|
35
|
-
* and Datadog dashboard creation.
|
|
36
|
-
*/
|
|
37
|
-
export interface InitializationErrorContext {
|
|
38
|
-
cause?: Error
|
|
39
|
-
[key: string]: unknown
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Custom error for VWR loader initialization failures.
|
|
44
|
-
*
|
|
45
|
-
* Provides structured information for:
|
|
46
|
-
* - Error categorization (reason code)
|
|
47
|
-
* - RUM phase tracking
|
|
48
|
-
* - Datadog dashboard filtering
|
|
49
|
-
* - Original error chain preservation
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```typescript
|
|
53
|
-
* throw new InitializationError(
|
|
54
|
-
* InitializationErrorReason.DEVICE_ID_FAILED,
|
|
55
|
-
* `Failed to retrieve device ID for platform: ${platform}`,
|
|
56
|
-
* {
|
|
57
|
-
* phase: "vwr-loader:device_id",
|
|
58
|
-
* platform,
|
|
59
|
-
* }
|
|
60
|
-
* );
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
export class InitializationError extends Error {
|
|
64
|
-
public readonly name = "InitializationError"
|
|
65
|
-
|
|
66
|
-
constructor(
|
|
67
|
-
/** Structured reason code for categorization */
|
|
68
|
-
public readonly reason: InitializationErrorReason,
|
|
69
|
-
/** Human-readable error message */
|
|
70
|
-
public readonly message: string,
|
|
71
|
-
/** Context for logging and RUM tracking */
|
|
72
|
-
public readonly context: InitializationErrorContext = {}
|
|
73
|
-
) {
|
|
74
|
-
super(message)
|
|
75
|
-
|
|
76
|
-
// Ensure proper prototype chain for instanceof checks
|
|
77
|
-
Object.setPrototypeOf(this, InitializationError.prototype)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Convert to a plain object for structured logging.
|
|
82
|
-
* Useful for Datadog Logs and JSON serialization.
|
|
83
|
-
*/
|
|
84
|
-
toJSON(): Record<string, unknown> {
|
|
85
|
-
return {
|
|
86
|
-
name: this.name,
|
|
87
|
-
reason: this.reason,
|
|
88
|
-
message: this.message,
|
|
89
|
-
...this.context,
|
|
90
|
-
cause: this.context.cause?.message,
|
|
91
|
-
stack: this.stack,
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Get error context.
|
|
97
|
-
* Returns the context object.
|
|
98
|
-
*/
|
|
99
|
-
getContext(): Record<string, unknown> {
|
|
100
|
-
return {
|
|
101
|
-
...this.context,
|
|
102
|
-
reason: this.reason,
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
package/src/errors/index.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export { ensureError } from "./ensureError"
|
|
2
|
-
export type { InitializationErrorContext } from "./InitializationError"
|
|
3
|
-
export {
|
|
4
|
-
InitializationError,
|
|
5
|
-
InitializationErrorReason,
|
|
6
|
-
} from "./InitializationError"
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Type guard for VWR initialization errors.
|
|
10
|
-
* Checks error.name instead of instanceof to avoid runtime dependency on @volley/vwr.
|
|
11
|
-
*/
|
|
12
|
-
export function isVWRInitializationError(
|
|
13
|
-
error: unknown
|
|
14
|
-
): error is Error & { name: "VWRInitializationError"; reason: string } {
|
|
15
|
-
return error instanceof Error && error.name === "VWRInitializationError"
|
|
16
|
-
}
|