Skip to content

Commit 9f562e5

Browse files
authored
feat: Implement common support for auto environment attributes. (#355)
This PR adds support for auto env attributes for the common library. This was originally part of #354. That big PR is being broken down into smaller PRs for the benefit of better changelog through conventional commits. Note I have intentionally omitted the `common/jest.config.js` change because that is part of a larger change to the mocks api. This change is in #356.
1 parent 308100d commit 9f562e5

File tree

5 files changed

+67
-8
lines changed

5 files changed

+67
-8
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
interface AutoEnvCommon {
2+
/**
3+
* Unique key for the context kind.
4+
*/
5+
key: string;
6+
7+
/**
8+
* Version of the environment attributes schema being used.
9+
*/
10+
envAttributesVersion: string;
11+
}
12+
13+
export interface LDApplication extends AutoEnvCommon {
14+
/**
15+
* Unique identifier of the application.
16+
*/
17+
id?: string;
18+
name?: string;
19+
version?: string;
20+
versionName?: string;
21+
locale?: string;
22+
}
23+
24+
export interface LDDevice extends AutoEnvCommon {
25+
manufacturer?: string;
26+
model?: string;
27+
storageBytes?: string;
28+
memoryBytes?: string;
29+
os?: {
30+
/**
31+
* The family of operating system.
32+
*/
33+
family: string;
34+
name: string;
35+
version: string;
36+
};
37+
}

packages/shared/common/src/api/platform/Info.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { LDApplication, LDDevice } from './AutoEnv';
2+
13
/**
24
* Information about the platform of the SDK and the environment it is executing.
35
*/
@@ -31,6 +33,18 @@ export interface PlatformData {
3133
* Any additional attributes associated with the platform.
3234
*/
3335
additional?: Record<string, string>;
36+
37+
/**
38+
* Additional information about the executing environment. Should be populated
39+
* when available. Not all platforms will have this data.
40+
*/
41+
ld_application?: LDApplication;
42+
43+
/**
44+
* Device hardware information. Should be populated when available. Not all
45+
* platforms will have this data.
46+
*/
47+
ld_device?: LDDevice;
3448
}
3549

3650
export interface SdkData {
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
export * from './Encoding';
1+
export * from './AutoEnv';
22
export * from './Crypto';
3+
export * from './Encoding';
4+
export * from './EventSource';
35
export * from './Filesystem';
46
export * from './Info';
57
export * from './Platform';
68
export * from './Requests';
7-
export * from './EventSource';
89
export * from './Storage';

packages/shared/common/src/internal/stream/StreamingProcessor.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
import { basicPlatform, clientContext, logger } from '@launchdarkly/private-js-mocks';
22

3-
import { EventName, ProcessStreamResponse } from '../../api';
3+
import { EventName, Info, ProcessStreamResponse } from '../../api';
44
import { LDStreamProcessor } from '../../api/subsystem';
55
import { LDStreamingError } from '../../errors';
6+
import { ApplicationTags, ServiceEndpoints } from '../../options';
67
import { defaultHeaders } from '../../utils';
78
import { DiagnosticsManager } from '../diagnostics';
89
import StreamingProcessor from './StreamingProcessor';
910

1011
const dateNowString = '2023-08-10';
1112
const sdkKey = 'my-sdk-key';
12-
const {
13-
basicConfiguration: { serviceEndpoints, tags },
14-
platform: { info },
15-
} = clientContext;
1613
const event = {
1714
data: {
1815
flags: {
@@ -33,6 +30,9 @@ const createMockEventSource = (streamUri: string = '', options: any = {}) => ({
3330
});
3431

3532
describe('given a stream processor with mock event source', () => {
33+
let serviceEndpoints: ServiceEndpoints;
34+
let tags: ApplicationTags;
35+
let info: Info;
3636
let streamingProcessor: LDStreamProcessor;
3737
let diagnosticsManager: DiagnosticsManager;
3838
let listeners: Map<EventName, ProcessStreamResponse>;
@@ -53,8 +53,11 @@ describe('given a stream processor with mock event source', () => {
5353

5454
beforeEach(() => {
5555
mockErrorHandler = jest.fn();
56+
({
57+
basicConfiguration: { serviceEndpoints, tags },
58+
platform: { info },
59+
} = clientContext);
5660
clientContext.basicConfiguration.logger = logger;
57-
5861
basicPlatform.requests = {
5962
createEventSource: jest.fn((streamUri: string, options: any) => {
6063
mockEventSource = createMockEventSource(streamUri, options);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
export default function clone<T>(obj: any) {
2+
if (obj === undefined || obj === null) {
3+
return obj;
4+
}
5+
26
return JSON.parse(JSON.stringify(obj)) as T;
37
}

0 commit comments

Comments
 (0)