-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement common client side support for auto environment attri…
…butes. (#356) This is a follow up to #355. This PR implements client-sdk support for auto env. In addition, the mocks internal api have been updated to work better with crypto and mock resets. Server sdks are impacted by the mocks api changes so these are fixed in this PR as well. ### Note #357 Fixes react-native build and tests. #358 adds application name and versionName to LDOptions.
- Loading branch information
Showing
36 changed files
with
2,020 additions
and
880 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import deepCompact from './deepCompact'; | ||
|
||
describe('deepCompact', () => { | ||
test('if arg is undefined, return it', () => { | ||
const compacted = deepCompact(undefined); | ||
expect(compacted).toBeUndefined(); | ||
}); | ||
|
||
test('should remove all falsy, {} and ignored values', () => { | ||
const data = { | ||
ld_application: { | ||
key: '', | ||
envAttributesVersion: '1.0', | ||
id: 'com.testapp.ld', | ||
name: 'LDApplication.TestApp', | ||
version: '1.1.1', | ||
}, | ||
ld_device: { | ||
key: '', | ||
envAttributesVersion: '1.0', | ||
os: {}, | ||
manufacturer: 'coconut', | ||
model: null, | ||
storageBytes: undefined, | ||
}, | ||
}; | ||
const compacted = deepCompact(data, ['key', 'envAttributesVersion']); | ||
expect(compacted).toEqual({ | ||
ld_application: { | ||
id: 'com.testapp.ld', | ||
name: 'LDApplication.TestApp', | ||
version: '1.1.1', | ||
}, | ||
ld_device: { | ||
manufacturer: 'coconut', | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import isEmptyObject from './isEmptyObject'; | ||
|
||
/** | ||
* Strips all falsy and empty {} from a given object. Returns a new object with only truthy values. | ||
* Sourced from below but modified to include checks for empty object and ignoring keys. | ||
* https://www.w3resource.com/javascript-exercises/javascript-array-exercise-47.php | ||
* | ||
* @param obj | ||
* @param ignoreKeys | ||
*/ | ||
const deepCompact = <T extends Object>(obj?: T, ignoreKeys?: string[]) => { | ||
if (!obj) { | ||
return obj; | ||
} | ||
|
||
return Object.entries(obj).reduce((acc: any, [key, value]) => { | ||
if (Boolean(value) && !isEmptyObject(value) && !ignoreKeys?.includes(key)) { | ||
acc[key] = typeof value === 'object' ? deepCompact(value, ignoreKeys) : value; | ||
} | ||
return acc; | ||
}, {}) as T; | ||
}; | ||
|
||
export default deepCompact; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const isEmptyObject = (obj: any) => JSON.stringify(obj) === '{}'; | ||
|
||
export default isEmptyObject; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
import type { ClientContext } from '@common'; | ||
|
||
import basicPlatform from './platform'; | ||
import { basicPlatform } from './platform'; | ||
|
||
const clientContext: ClientContext = { | ||
basicConfiguration: { | ||
sdkKey: 'testSdkKey', | ||
serviceEndpoints: { | ||
events: '', | ||
polling: '', | ||
streaming: 'https://mockstream.ld.com', | ||
diagnosticEventPath: '/diagnostic', | ||
analyticsEventPath: '/bulk', | ||
includeAuthorizationHeader: true, | ||
// eslint-disable-next-line import/no-mutable-exports | ||
export let clientContext: ClientContext; | ||
export const setupClientContext = () => { | ||
clientContext = { | ||
basicConfiguration: { | ||
sdkKey: 'testSdkKey', | ||
serviceEndpoints: { | ||
events: '', | ||
polling: '', | ||
streaming: 'https://mockstream.ld.com', | ||
diagnosticEventPath: '/diagnostic', | ||
analyticsEventPath: '/bulk', | ||
includeAuthorizationHeader: true, | ||
}, | ||
}, | ||
}, | ||
platform: basicPlatform, | ||
platform: basicPlatform, | ||
}; | ||
}; | ||
|
||
export default clientContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { Hasher } from '@common'; | ||
|
||
// eslint-disable-next-line import/no-mutable-exports | ||
export let hasher: Hasher; | ||
|
||
export const setupCrypto = () => { | ||
let counter = 0; | ||
hasher = { | ||
update: jest.fn(), | ||
digest: jest.fn(() => '1234567890123456'), | ||
}; | ||
|
||
return { | ||
createHash: jest.fn(() => hasher), | ||
createHmac: jest.fn(), | ||
randomUUID: jest.fn(() => { | ||
counter += 1; | ||
// Will provide a unique value for tests. | ||
// Very much not a UUID of course. | ||
return `${counter}`; | ||
}), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.