wallet-stack 1.0.0-alpha.123 → 1.0.0-alpha.124

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wallet-stack",
3
- "version": "1.0.0-alpha.123",
3
+ "version": "1.0.0-alpha.124",
4
4
  "author": "Valora Inc",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -222,11 +222,17 @@ describe('AppAnalytics', () => {
222
222
  expect(mockCreateSegmentClient).not.toHaveBeenCalled()
223
223
  })
224
224
 
225
- it('creates statsig client on initialization with default statsig user', async () => {
225
+ it('creates statsig client on initialization with Segment anonymous ID when Segment is available', async () => {
226
226
  await AppAnalytics.init()
227
227
  expect(StatsigClientSingleton.initialize).toHaveBeenCalledWith('anonId')
228
228
  })
229
229
 
230
+ it('creates statsig client with device UniqueID when Segment is not available', async () => {
231
+ mockConfig.SEGMENT_API_KEY = undefined
232
+ await AppAnalytics.init()
233
+ expect(StatsigClientSingleton.initialize).toHaveBeenCalledWith('abc-def-123')
234
+ })
235
+
230
236
  it('does not initialize statsig if STATSIG_ENABLED is false', async () => {
231
237
  mockConfig.STATSIG_ENABLED = false
232
238
  await AppAnalytics.init()
@@ -97,6 +97,15 @@ class AppAnalytics {
97
97
 
98
98
  async init() {
99
99
  let uniqueID
100
+ try {
101
+ const deviceInfo = await getDeviceInfo()
102
+ this.deviceInfo = deviceInfo
103
+ uniqueID = deviceInfo.UniqueID
104
+ this.sessionId = sha256(Buffer.from(uniqueID + String(Date.now()))).slice(2)
105
+ } catch (error) {
106
+ Logger.error(TAG, 'getDeviceInfo error', error)
107
+ }
108
+
100
109
  if (SEGMENT_API_KEY) {
101
110
  try {
102
111
  this.segmentClient = createClient({
@@ -114,15 +123,6 @@ class AppAnalytics {
114
123
  this.segmentClient.add({ plugin: new FirebasePlugin() })
115
124
  }
116
125
 
117
- try {
118
- const deviceInfo = await getDeviceInfo()
119
- this.deviceInfo = deviceInfo
120
- uniqueID = deviceInfo.UniqueID
121
- this.sessionId = sha256(Buffer.from(uniqueID + String(Date.now()))).slice(2)
122
- } catch (error) {
123
- Logger.error(TAG, 'getDeviceInfo error', error)
124
- }
125
-
126
126
  Logger.info(TAG, 'Segment Analytics Integration initialized!')
127
127
  } catch (err) {
128
128
  const error = ensureError(err)
@@ -134,11 +134,18 @@ class AppAnalytics {
134
134
 
135
135
  if (STATSIG_ENABLED) {
136
136
  try {
137
- if (!this.segmentClient) {
138
- throw new Error('segmentClient is undefined, cannot get anonymous ID')
137
+ let overrideStableID: string
138
+ if (this.segmentClient) {
139
+ overrideStableID = this.segmentClient.userInfo.get().anonymousId
140
+ Logger.debug(TAG, 'Statsig stable ID from Segment', overrideStableID)
141
+ } else if (uniqueID) {
142
+ overrideStableID = uniqueID
143
+ Logger.debug(TAG, 'Statsig stable ID from device UniqueID', overrideStableID)
144
+ } else {
145
+ throw new Error(
146
+ 'Cannot get stable ID: segmentClient is undefined and device UniqueID is unavailable'
147
+ )
139
148
  }
140
- const overrideStableID = this.segmentClient.userInfo.get().anonymousId
141
- Logger.debug(TAG, 'Statsig stable ID', overrideStableID)
142
149
  await StatsigClientSingleton.initialize(overrideStableID)
143
150
  } catch (error) {
144
151
  Logger.warn(TAG, `Statsig setup error`, error)