-
Notifications
You must be signed in to change notification settings - Fork 37
feat: common identify now reports identify status #1289
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
base: main
Are you sure you want to change the base?
Changes from all commits
9089e43
4d2cec1
930b7e8
7d7d036
5e0b4cb
ab1a857
b88b805
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { | ||
| LDClient as CommonClient, | ||
| LDContext, | ||
| LDIdentifyOptions, | ||
| } from '@launchdarkly/js-client-sdk-common'; | ||
|
|
||
| /** | ||
| * React Native LDClient type. Overrides `identify()` to return `Promise<void>` and throw on | ||
| * error/timeout to maintain backward compatibility with existing React Native consumers. | ||
| */ | ||
| export type LDClient = Omit<CommonClient, 'identify'> & { | ||
| /** | ||
| * Identifies a context to LaunchDarkly. | ||
| * | ||
| * Unlike the server-side SDKs, the client-side JavaScript SDKs maintain a current context state, | ||
| * which is set when you call `identify()`. | ||
| * | ||
| * Changing the current context also causes all feature flag values to be reloaded. Until that has | ||
| * finished, calls to {@link variation} will still return flag values for the previous context. You can | ||
| * await the Promise to determine when the new flag values are available. | ||
| * | ||
| * @param context | ||
| * The LDContext object. | ||
| * @param identifyOptions | ||
| * Optional configuration. Please see {@link LDIdentifyOptions}. | ||
| * @returns | ||
| * A Promise which resolves when the flag values for the specified | ||
| * context are available. It rejects when: | ||
| * | ||
| * 1. The context is unspecified or has no key. | ||
| * | ||
| * 2. The identify timeout is exceeded. In client SDKs this defaults to 5s. | ||
| * You can customize this timeout with {@link LDIdentifyOptions | identifyOptions}. | ||
| * | ||
| * 3. A network error is encountered during initialization. | ||
| */ | ||
| identify(context: LDContext, identifyOptions?: LDIdentifyOptions): Promise<void>; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,9 +13,14 @@ import { | |
| type LDClientDataSystemOptions, | ||
| LDClientImpl, | ||
| LDClientInternalOptions, | ||
| type LDContext, | ||
| LDEmitter, | ||
| LDHeaders, | ||
| type LDIdentifyOptions, | ||
| type LDIdentifyResult, | ||
| LDPluginEnvironmentMetadata, | ||
| LDTimeoutError, | ||
| type LDWaitForInitializationResult, | ||
| MOBILE_DATA_SYSTEM_DEFAULTS, | ||
| MOBILE_TRANSITION_TABLE, | ||
| mobileFdv1Endpoints, | ||
|
|
@@ -227,6 +232,33 @@ export default class ReactNativeLDClient extends LDClientImpl { | |
| ); | ||
| } | ||
|
|
||
| override async identify( | ||
| context: LDContext, | ||
| identifyOptions?: LDIdentifyOptions, | ||
| ): Promise<LDIdentifyResult> { | ||
| const result = await super.identify(context, identifyOptions); | ||
| if (result.status === 'error') { | ||
| throw result.error; | ||
| } else if (result.status === 'timeout') { | ||
| const timeoutError = new LDTimeoutError( | ||
| `identify timed out after ${result.timeout} seconds.`, | ||
| ); | ||
| this.logger.error(timeoutError.message); | ||
| throw timeoutError; | ||
| } | ||
| return result; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RN identify rejects despite interface promising no rejectionMedium Severity
Additional Locations (1)Reviewed by Cursor Bugbot for commit b88b805. Configure here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is intentional |
||
| } | ||
|
|
||
| /** | ||
| * Protect against trying to use start() in RN. | ||
| * | ||
| * @internal | ||
| **/ | ||
|
|
||
| override start(): Promise<LDWaitForInitializationResult> { | ||
| throw new Error('start() is not supported in the React Native SDK. Use identify() directly.'); | ||
| } | ||
|
|
||
| override async close(): Promise<void> { | ||
| this._stateDetector?.stopListening(); | ||
| this._connectionManager?.close(); | ||
|
|
||


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.
I think should be okay because I don't think anyone is checking for
voidreturns?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.
It doesn't make me particularly comfortable to actually be returning something.
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.
yea, I don't think we could really do this step comfortably until we major version RN... which is fine... I'll move this back to draft or close, otherwise the changes seem fairly trivial.