Skip to content

Commit

Permalink
Merge branch 'main' into rlamb/SDK-197/implement-secure-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kinyoklion committed Oct 1, 2024
2 parents 1fe9665 + 9ad25bd commit f25836c
Show file tree
Hide file tree
Showing 105 changed files with 1,468 additions and 712 deletions.
25 changes: 0 additions & 25 deletions .github/workflows/mocks.yml

This file was deleted.

1 change: 0 additions & 1 deletion .github/workflows/react-native-detox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ on:
- 'packages/shared/common/**'
- 'packages/shared/sdk-client/**'
- 'packages/sdk/react-native/**'
- 'packages/shared/mocks/**'

jobs:
detox-android:
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "@launchdarkly/js-core",
"workspaces": [
"packages/shared/common",
"packages/shared/mocks",
"packages/shared/sdk-client",
"packages/shared/sdk-server",
"packages/shared/sdk-server-edge",
Expand Down
37 changes: 23 additions & 14 deletions packages/sdk/browser/__tests__/BrowserDataManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ describe('given a BrowserDataManager with mocked dependencies', () => {
};
config = {
logger,
baseUri: 'string',
eventsUri: 'string',
streamUri: 'string',
maxCachedContexts: 5,
capacity: 100,
diagnosticRecordingInterval: 1000,
Expand Down Expand Up @@ -289,20 +286,27 @@ describe('given a BrowserDataManager with mocked dependencies', () => {

it('should load cached flags and continue to poll to complete identify', async () => {
const context = Context.fromLDContext({ kind: 'user', key: 'test-user' });
const identifyOptions: BrowserIdentifyOptions = {};
const identifyResolve = jest.fn();
const identifyReject = jest.fn();

flagManager.loadCached.mockResolvedValue(true);

await dataManager.identify(identifyResolve, identifyReject, context, identifyOptions);
let identifyResolve: () => void;
let identifyReject: (err: Error) => void;
await new Promise<void>((resolve) => {
identifyResolve = jest.fn().mockImplementation(() => {
resolve();
});
identifyReject = jest.fn();

// this is the function under test
dataManager.identify(identifyResolve, identifyReject, context, {});
});

expect(logger.debug).toHaveBeenCalledWith(
'[BrowserDataManager] Identify - Flags loaded from cache. Continuing to initialize via a poll.',
);

expect(flagManager.loadCached).toHaveBeenCalledWith(context);
expect(identifyResolve).toHaveBeenCalled();
expect(identifyResolve!).toHaveBeenCalled();
expect(flagManager.init).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({ flagA: { flag: true, version: undefined } }),
Expand All @@ -312,20 +316,25 @@ describe('given a BrowserDataManager with mocked dependencies', () => {

it('should identify from polling when there are no cached flags', async () => {
const context = Context.fromLDContext({ kind: 'user', key: 'test-user' });
const identifyOptions: BrowserIdentifyOptions = {};
const identifyResolve = jest.fn();
const identifyReject = jest.fn();

flagManager.loadCached.mockResolvedValue(false);
let identifyResolve: () => void;
let identifyReject: (err: Error) => void;
await new Promise<void>((resolve) => {
identifyResolve = jest.fn().mockImplementation(() => {
resolve();
});
identifyReject = jest.fn();

await dataManager.identify(identifyResolve, identifyReject, context, identifyOptions);
// this is the function under test
dataManager.identify(identifyResolve, identifyReject, context, {});
});

expect(logger.debug).not.toHaveBeenCalledWith(
'Identify - Flags loaded from cache. Continuing to initialize via a poll.',
);

expect(flagManager.loadCached).toHaveBeenCalledWith(context);
expect(identifyResolve).toHaveBeenCalled();
expect(identifyResolve!).toHaveBeenCalled();
expect(flagManager.init).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({ flagA: { flag: true, version: undefined } }),
Expand Down
1 change: 0 additions & 1 deletion packages/sdk/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@launchdarkly/private-js-mocks": "0.0.1",
"@rollup/plugin-commonjs": "^25.0.0",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.0.2",
Expand Down
21 changes: 18 additions & 3 deletions packages/sdk/browser/src/BrowserDataManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import {
BaseDataManager,
Configuration,
Context,
DataSourceErrorKind,
DataSourcePaths,
DataSourceState,
FlagManager,
getPollingUri,
internal,
Expand Down Expand Up @@ -91,11 +93,24 @@ export default class BrowserDataManager extends BaseDataManager {
// TODO: Handle wait for network results in a meaningful way. SDK-707

try {
this.dataSourceStatusManager.requestStateUpdate(DataSourceState.Initializing);
const payload = await requestor.requestPayload();
const listeners = this.createStreamListeners(context, identifyResolve);
const putListener = listeners.get('put');
putListener!.processJson(putListener!.deserializeData(payload));
try {
const listeners = this.createStreamListeners(context, identifyResolve);
const putListener = listeners.get('put');
putListener!.processJson(putListener!.deserializeData(payload));
} catch (e: any) {
this.dataSourceStatusManager.reportError(
DataSourceErrorKind.InvalidData,
e.message ?? 'Could not parse poll response',
);
}
} catch (e: any) {
this.dataSourceStatusManager.reportError(
DataSourceErrorKind.NetworkError,
e.message ?? 'unexpected network error',
e.status,
);
identifyReject(e);
}

Expand Down
12 changes: 2 additions & 10 deletions packages/sdk/cloudflare/jsr.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@
"version": "2.5.14",
"exports": "./src/index.ts",
"publish": {
"include": [
"LICENSE",
"README.md",
"package.json",
"jsr.json",
"src/**/*.ts"
],
"exclude": [
"src/**/*.test.ts"
]
"include": ["LICENSE", "README.md", "package.json", "jsr.json", "src/**/*.ts"],
"exclude": ["src/**/*.test.ts"]
}
}
3 changes: 0 additions & 3 deletions packages/sdk/react-native/__tests__/MobileDataManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ describe('given a MobileDataManager with mocked dependencies', () => {
};
config = {
logger,
baseUri: 'string',
eventsUri: 'string',
streamUri: 'string',
maxCachedContexts: 5,
capacity: 100,
diagnosticRecordingInterval: 1000,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { type EventName } from '@launchdarkly/js-client-sdk-common';
import { createLogger } from '@launchdarkly/private-js-mocks';
import { type EventName, LDLogger } from '@launchdarkly/js-client-sdk-common';

import EventSource, {
backoff,
jitter,
} from '../../../src/fromExternal/react-native-sse/EventSource';

let logger: ReturnType<typeof createLogger>;
let logger: LDLogger;

beforeEach(() => {
logger = createLogger();
logger = {
error: jest.fn(),
warn: jest.fn(),
info: jest.fn(),
debug: jest.fn(),
};
});

describe('EventSource', () => {
Expand Down
1 change: 0 additions & 1 deletion packages/sdk/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"base64-js": "^1.5.1"
},
"devDependencies": {
"@launchdarkly/private-js-mocks": "0.0.1",
"@testing-library/react": "^14.1.2",
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
"@types/jest": "^29.5.11",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { integrations } from '@launchdarkly/js-server-sdk-common';
import { createLogger } from '@launchdarkly/private-js-mocks';
import { integrations, LDLogger } from '@launchdarkly/js-server-sdk-common';

import { Context, LDClient } from '../src';
import LDClientNode from '../src/LDClientNode';

let logger: ReturnType<typeof createLogger>;
let logger: LDLogger;

beforeEach(() => {
logger = createLogger();
logger = {
error: jest.fn(),
warn: jest.fn(),
info: jest.fn(),
debug: jest.fn(),
};
});

describe('given an LDClient with test data', () => {
let client: LDClient;
let td: integrations.TestData;
Expand Down
12 changes: 8 additions & 4 deletions packages/sdk/server-node/__tests__/LDClientNode.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { LDContext } from '@launchdarkly/js-server-sdk-common';
import { createLogger } from '@launchdarkly/private-js-mocks';
import { LDContext, LDLogger } from '@launchdarkly/js-server-sdk-common';

import { init } from '../src';

let logger: ReturnType<typeof createLogger>;
let logger: LDLogger;

beforeEach(() => {
logger = createLogger();
logger = {
error: jest.fn(),
warn: jest.fn(),
info: jest.fn(),
debug: jest.fn(),
};
});

it('fires ready event in offline mode', (done) => {
Expand Down
13 changes: 8 additions & 5 deletions packages/sdk/server-node/__tests__/LDClientNode.tls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ import {
TestHttpServer,
} from 'launchdarkly-js-test-helpers';

import { createLogger } from '@launchdarkly/private-js-mocks';

import { LDClient } from '../src';
import { LDClient, LDLogger } from '../src';
import LDClientNode from '../src/LDClientNode';

let logger: ReturnType<typeof createLogger>;
let logger: LDLogger;

beforeEach(() => {
logger = createLogger();
logger = {
error: jest.fn(),
warn: jest.fn(),
info: jest.fn(),
debug: jest.fn(),
};
});

describe('When using a TLS connection', () => {
Expand Down
1 change: 0 additions & 1 deletion packages/sdk/server-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"launchdarkly-eventsource": "2.0.3"
},
"devDependencies": {
"@launchdarkly/private-js-mocks": "0.0.1",
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
"@types/jest": "^29.4.0",
"@typescript-eslint/eslint-plugin": "^6.20.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Context, subsystem } from '@common';
import { subsystem } from '../src/api';
import Context from '../src/Context';

export default class ContextDeduplicator implements subsystem.LDContextDeduplicator {
flushInterval?: number | undefined = 0.1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { PlatformData, SdkData } from '@common';

import { setupCrypto } from './crypto';
import { PlatformData, SdkData } from '../src/api';
import { setupCrypto } from './setupCrypto';

const setupInfo = () => ({
platformData: jest.fn(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createBasicPlatform } from '@launchdarkly/private-js-mocks';

import DiagnosticsManager from './DiagnosticsManager';
import DiagnosticsManager from '../../../src/internal/diagnostics/DiagnosticsManager';
import { createBasicPlatform } from '../../createBasicPlatform';

describe('given a diagnostics manager', () => {
const dateNowString = '2023-08-10';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import {
ContextDeduplicator,
createBasicPlatform,
createLogger,
} from '@launchdarkly/private-js-mocks';

import { LDContextCommon, LDMultiKindContext } from '../../../src/api/context';
import { LDLogger } from '../../../src/api/logging/LDLogger';
import { LDContextDeduplicator, LDDeliveryStatus, LDEventType } from '../../../src/api/subsystem';
import Context from '../../../src/Context';
import { EventProcessor, InputIdentifyEvent } from '../../../src/internal';
Expand All @@ -13,13 +8,20 @@ import shouldSample from '../../../src/internal/events/sampling';
import BasicLogger from '../../../src/logging/BasicLogger';
import format from '../../../src/logging/format';
import ClientContext from '../../../src/options/ClientContext';
import ContextDeduplicator from '../../contextDeduplicator';
import { createBasicPlatform } from '../../createBasicPlatform';

let mockPlatform: ReturnType<typeof createBasicPlatform>;
let clientContext: ClientContext;
let logger: ReturnType<typeof createLogger>;
let logger: LDLogger;

beforeEach(() => {
logger = createLogger();
logger = {
error: jest.fn(),
warn: jest.fn(),
info: jest.fn(),
debug: jest.fn(),
};
mockPlatform = createBasicPlatform();
clientContext = {
basicConfiguration: {
Expand Down
Loading

0 comments on commit f25836c

Please sign in to comment.