Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adds support for REPORT. #575

Merged
merged 20 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e180de6
tests now passing
tanderson-ld Sep 6, 2024
2eb9bd9
Merge remote-tracking branch 'origin' into ta/sc-251674/merging-paylo…
tanderson-ld Sep 9, 2024
d35efdc
moving EventSourceMock to __tests__ folder.
tanderson-ld Sep 9, 2024
646f1db
fixing some lint issues
tanderson-ld Sep 9, 2024
338c639
adding StreamingProcessor useReport tests
tanderson-ld Sep 9, 2024
73335ba
lint fixes
tanderson-ld Sep 9, 2024
80af9f5
updating PollingProcessor constructor to be consistent with Streaming…
tanderson-ld Sep 10, 2024
437eedc
Merge remote-tracking branch 'origin' into ta/sc-251674/streaming-report
tanderson-ld Sep 10, 2024
66f418f
readding runAllTimersAsync calls
tanderson-ld Sep 10, 2024
eb73bd6
Merge branch 'main' into ta/sc-251674/streaming-report
tanderson-ld Sep 10, 2024
60c316c
Merge remote-tracking branch 'origin' into ta/sc-251674/streaming-report
tanderson-ld Sep 12, 2024
7bac549
adding log when platform doesn't support REPORT, but config option us…
tanderson-ld Sep 12, 2024
669ae02
adding content header for streaming
tanderson-ld Sep 13, 2024
1936b3f
Merge remote-tracking branch 'origin' into ta/sc-251674/streaming-report
tanderson-ld Sep 13, 2024
610d47a
fixing lint issues
tanderson-ld Sep 13, 2024
1ab46d8
Adding Polling report body support.
tanderson-ld Sep 13, 2024
ee8bdb0
Correcting polling report path
tanderson-ld Sep 13, 2024
a2465e9
more minor tweaks
tanderson-ld Sep 13, 2024
a61bc2d
Fix method default.
kinyoklion Sep 13, 2024
fc54863
Adressing review comments
tanderson-ld Sep 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions packages/sdk/browser/src/BrowserClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {
AutoEnvAttributes,
base64UrlEncode,
LDClient as CommonClient,
DataSourcePaths,
Encoding,
LDClientImpl,
LDContext,
LDOptions,
Expand Down Expand Up @@ -33,11 +35,27 @@ export class BrowserClient extends LDClientImpl {
return base64UrlEncode(JSON.stringify(context), this.platform.encoding!);
}

override createStreamUriPath(context: LDContext) {
return `/eval/${this.clientSideId}/${this.encodeContext(context)}`;
override getStreamingPaths(): DataSourcePaths {
const parentThis = this;
return {
pathGet(encoding: Encoding, _credential: string, _plainContextString: string): string {
tanderson-ld marked this conversation as resolved.
Show resolved Hide resolved
return `/eval/${parentThis.clientSideId}/${base64UrlEncode(_plainContextString, encoding)}`;
},
pathReport(_encoding: Encoding, _credential: string, _plainContextString: string): string {
return `/eval/${parentThis.clientSideId}`;
},
};
}

override createPollUriPath(context: LDContext): string {
return `/sdk/evalx/${this.clientSideId}/contexts/${this.encodeContext(context)}`;
override getPollingPaths(): DataSourcePaths {
const parentThis = this;
return {
pathGet(encoding: Encoding, _credential: string, _plainContextString: string): string {
return `/sdk/evalx/${parentThis.clientSideId}/contexts/${base64UrlEncode(_plainContextString, encoding)}`;
},
pathReport(_encoding: Encoding, _credential: string, _plainContextString: string): string {
return `/sdk/evalx/${parentThis.clientSideId}/context`;
},
};
}
}
2 changes: 1 addition & 1 deletion packages/sdk/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"test": "jest",
"coverage": "yarn test --coverage",
"check": "yarn prettier && yarn lint && yarn build && yarn test",
"android": "yarn && yarn ./example && yarn build && (cd example/ && yarn android-release)",
"android": "yarn && yarn ./example && yarn build && (cd example/ && yarn android)",
tanderson-ld marked this conversation as resolved.
Show resolved Hide resolved
"ios": "yarn && yarn ./example && yarn build && (cd example/ && yarn ios-go)"
},
"peerDependencies": {
Expand Down
24 changes: 20 additions & 4 deletions packages/sdk/react-native/src/ReactNativeLDClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
base64UrlEncode,
BasicLogger,
ConnectionMode,
DataSourcePaths,
Encoding,
internal,
LDClientImpl,
type LDContext,
Expand Down Expand Up @@ -103,12 +105,26 @@ export default class ReactNativeLDClient extends LDClientImpl {
return base64UrlEncode(JSON.stringify(context), this.platform.encoding!);
}

override createStreamUriPath(context: LDContext) {
return `/meval/${this.encodeContext(context)}`;
override getStreamingPaths(): DataSourcePaths {
return {
pathGet(encoding: Encoding, _credential: string, _plainContextString: string): string {
return `/meval/${base64UrlEncode(_plainContextString, encoding)}`;
},
pathReport(_encoding: Encoding, _credential: string, _plainContextString: string): string {
return `/meval`;
},
};
}

override createPollUriPath(context: LDContext): string {
return `/msdk/evalx/contexts/${this.encodeContext(context)}`;
override getPollingPaths(): DataSourcePaths {
return {
pathGet(encoding: Encoding, _credential: string, _plainContextString: string): string {
return `/msdk/evalx/contexts/${base64UrlEncode(_plainContextString, encoding)}`;
},
pathReport(_encoding: Encoding, _credential: string, _plainContextString: string): string {
return `/msdk/evalx/context`;
},
};
}

override async setConnectionMode(mode: ConnectionMode): Promise<void> {
Expand Down
2 changes: 2 additions & 0 deletions packages/sdk/react-native/src/platform/PlatformRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export default class PlatformRequests implements Requests {

createEventSource(url: string, eventSourceInitDict: EventSourceInitDict): EventSource {
return new RNEventSource<EventName>(url, {
method: eventSourceInitDict.method,
headers: eventSourceInitDict.headers,
body: eventSourceInitDict.body,
retryAndHandleError: eventSourceInitDict.errorFilter,
logger: this.logger,
});
Expand Down
4 changes: 3 additions & 1 deletion packages/shared/common/src/api/platform/EventSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ export interface EventSource {
}

export interface EventSourceInitDict {
errorFilter: (err: HttpErrorResponse) => boolean;
method?: string;
headers: { [key: string]: string | string[] };
body?: string;
errorFilter: (err: HttpErrorResponse) => boolean;
initialRetryDelayMillis: number;
readTimeoutMillis: number;
retryResetIntervalMillis: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
AutoEnvAttributes,
ClientContext,
clone,
Encoding,
internal,
LDContext,
subsystem,
Expand All @@ -10,12 +11,12 @@ import {
createBasicPlatform,
createLogger,
MockEventProcessor,
setupMockStreamingProcessor,
} from '@launchdarkly/private-js-mocks';

import LDClientImpl from '../src/LDClientImpl';
import { Flags } from '../src/types';
import * as mockResponseJson from './evaluation/mockResponse.json';
import { MockEventSource } from './streaming/LDClientImpl.mocks';

type InputCustomEvent = internal.InputCustomEvent;
type InputIdentifyEvent = internal.InputIdentifyEvent;
Expand All @@ -36,7 +37,6 @@ jest.mock('@launchdarkly/js-sdk-common', () => {
...{
internal: {
...actual.internal,
StreamingProcessor: m.MockStreamingProcessor,
EventProcessor: m.MockEventProcessor,
},
},
Expand All @@ -45,6 +45,7 @@ jest.mock('@launchdarkly/js-sdk-common', () => {

const testSdkKey = 'test-sdk-key';
let ldc: LDClientImpl;
let mockEventSource: MockEventSource;
let defaultPutResponse: Flags;
const carContext: LDContext = { kind: 'car', key: 'test-car' };

Expand All @@ -66,15 +67,31 @@ describe('sdk-client object', () => {
sendEvent: mockedSendEvent,
}),
);
setupMockStreamingProcessor(false, defaultPutResponse);

const simulatedEvents = [{ data: JSON.stringify(defaultPutResponse) }];
mockPlatform.storage.get.mockImplementation(() => undefined);
mockPlatform.requests.createEventSource.mockImplementation(
(streamUri: string = '', options: any = {}) => {
mockEventSource = new MockEventSource(streamUri, options);
mockEventSource.simulateEvents('put', simulatedEvents);
return mockEventSource;
},
);

mockPlatform.crypto.randomUUID.mockReturnValue('random1');

ldc = new LDClientImpl(testSdkKey, AutoEnvAttributes.Enabled, mockPlatform, {
logger,
});
jest
.spyOn(LDClientImpl.prototype as any, 'createStreamUriPath')
.mockReturnValue('/stream/path');

jest.spyOn(LDClientImpl.prototype as any, 'getStreamingPaths').mockReturnValue({
pathGet(_encoding: Encoding, _credential: string, _plainContextString: string): string {
return '/stream/path';
},
pathReport(_encoding: Encoding, _credential: string, _plainContextString: string): string {
return '/stream/path';
},
});
});

afterEach(() => {
Expand Down
Loading
Loading