-
Notifications
You must be signed in to change notification settings - Fork 26
feat: Add client-side SDK plugin support. #834
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
Merged
kinyoklion
merged 17 commits into
main
from
rlamb/emsr-311/add-common-types-for-plugins
Apr 29, 2025
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e580cae
feat: Add client-side SDK plugin support.
kinyoklion 6662296
Fix broken browser test.
kinyoklion 9beb0eb
Lint and test fixes.
kinyoklion 34a24ad
Fix shared client tests.
kinyoklion 825ad57
Add tests for hook utility functions.
kinyoklion fd7930d
Add basic tests for browser client plugins.
kinyoklion dff637c
Add plugin tests for RN.
kinyoklion a493997
Fix browser plugin client tests.
kinyoklion 7bfc229
Fix typo.
kinyoklion d68cda8
WIP environment data tests.
kinyoklion fdc1df5
fix: Client SDKs should use wrapper information.
kinyoklion 717c39e
Merge branch 'rlamb/emsr-343/client-wrapper-info' into rlamb/emsr-311…
kinyoklion d54392d
Enhanced testing.
kinyoklion 41106a2
Readonly type annotations.
kinyoklion 56f38dd
Merge branch 'main' into rlamb/emsr-311/add-common-types-for-plugins
kinyoklion ea1ab1b
Add experimental notice for plugins.
kinyoklion b235b38
Minor refactoring.
kinyoklion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,117 @@ | ||
import { | ||
EventSourceCapabilities, | ||
EventSourceInitDict, | ||
Platform, | ||
PlatformData, | ||
Requests, | ||
SdkData, | ||
} from '@launchdarkly/js-client-sdk-common'; | ||
|
||
import { BrowserOptions } from '../src/options'; | ||
import { MockHasher } from './MockHasher'; | ||
|
||
function mockResponse(value: string, statusCode: number) { | ||
const response: Response = { | ||
// @ts-ignore | ||
headers: { | ||
// @ts-ignore | ||
get: jest.fn(), | ||
// @ts-ignore | ||
keys: jest.fn(), | ||
// @ts-ignore | ||
values: jest.fn(), | ||
// @ts-ignore | ||
entries: jest.fn(), | ||
// @ts-ignore | ||
has: jest.fn(), | ||
}, | ||
status: statusCode, | ||
text: () => Promise.resolve(value), | ||
json: () => Promise.resolve(JSON.parse(value)), | ||
}; | ||
return Promise.resolve(response); | ||
} | ||
|
||
function mockFetch(value: string, statusCode: number = 200) { | ||
const f = jest.fn(); | ||
// @ts-ignore | ||
f.mockResolvedValue(mockResponse(value, statusCode)); | ||
return f; | ||
} | ||
|
||
export function makeRequests(): Requests { | ||
return { | ||
// @ts-ignore | ||
fetch: jest.fn((url: string, _options: any) => { | ||
if (url.includes('/sdk/goals/')) { | ||
return mockFetch( | ||
JSON.stringify([ | ||
{ | ||
key: 'pageview', | ||
kind: 'pageview', | ||
urls: [{ kind: 'exact', url: 'http://browserclientintegration.com' }], | ||
}, | ||
{ | ||
key: 'click', | ||
kind: 'click', | ||
selector: '.button', | ||
urls: [{ kind: 'exact', url: 'http://browserclientintegration.com' }], | ||
}, | ||
]), | ||
200, | ||
)(); | ||
} | ||
return mockFetch('{ "flagA": true }', 200)(); | ||
}), | ||
// @ts-ignore | ||
createEventSource(_url: string, _eventSourceInitDict: EventSourceInitDict): EventSource { | ||
throw new Error('Function not implemented.'); | ||
}, | ||
getEventSourceCapabilities(): EventSourceCapabilities { | ||
return { | ||
readTimeout: false, | ||
headers: false, | ||
customMethod: false, | ||
}; | ||
}, | ||
}; | ||
} | ||
|
||
export function makeBasicPlatform(options?: BrowserOptions): Platform { | ||
return { | ||
requests: makeRequests(), | ||
info: { | ||
platformData(): PlatformData { | ||
return { | ||
name: 'browser', | ||
}; | ||
}, | ||
sdkData(): SdkData { | ||
const sdkData: SdkData = { | ||
name: 'browser-sdk', | ||
version: '1.0.0', | ||
userAgentBase: 'MockBrowserSDK', | ||
}; | ||
if (options?.wrapperName) { | ||
sdkData.wrapperName = options.wrapperName; | ||
} | ||
if (options?.wrapperVersion) { | ||
sdkData.wrapperVersion = options.wrapperVersion; | ||
} | ||
return sdkData; | ||
}, | ||
}, | ||
crypto: { | ||
createHash: () => new MockHasher(), | ||
randomUUID: () => '123', | ||
}, | ||
storage: { | ||
get: async (_key: string) => null, | ||
set: async (_key: string, _value: string) => {}, | ||
clear: async (_key: string) => {}, | ||
}, | ||
encoding: { | ||
btoa: (str: string) => str, | ||
}, | ||
} as Platform; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracted from existing client tests to be re-used for plugin tests.