-
Notifications
You must be signed in to change notification settings - Fork 59
feat: expose js sdk identity without proxy wrappers #1377
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
Changes from 9 commits
c158739
887dc1a
9fd6125
5b22a3f
cbe0b10
4143071
d8d88c8
c32450a
763eb68
8ba671c
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,15 @@ | ||
| import type { Client } from '@openfeature/web-sdk'; | ||
|
|
||
| type FrameworkMetadataClient = Client & { | ||
| setFrameworkMetadata?: (framework: 'angular') => Client; | ||
| }; | ||
|
|
||
| /** | ||
| * Marks an SDK-owned web client as Angular-backed while preserving instance identity. | ||
| * @param {Client} client client instance to update | ||
| * @returns {Client} the same client instance | ||
| */ | ||
| export function setAngularFrameworkMetadata(client: Client): Client { | ||
| (client as FrameworkMetadataClient).setFrameworkMetadata?.('angular'); | ||
|
Member
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. Not sure I'm particularly a fan of relying on type-casts to enable this |
||
| return client; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import type { Client } from '@openfeature/server-sdk'; | ||
|
|
||
| type FrameworkMetadataClient = Client & { | ||
| setFrameworkMetadata?: (framework: 'nest') => Client; | ||
| }; | ||
|
|
||
| /** | ||
| * Marks an SDK-owned server client as Nest-backed while preserving instance identity. | ||
| * @param {Client} client client instance to update | ||
| * @returns {Client} the same client instance | ||
| */ | ||
| export function setNestFrameworkMetadata(client: Client): Client { | ||
| (client as FrameworkMetadataClient).setFrameworkMetadata?.('nest'); | ||
| return client; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,10 @@ import * as React from 'react'; | |
| import type { ReactFlagEvaluationOptions } from '../options'; | ||
| import { Context } from '../internal'; | ||
|
|
||
| type FrameworkMetadataClient = Client & { | ||
| setFrameworkMetadata?: (framework: 'react') => Client; | ||
| }; | ||
|
|
||
| type ClientOrDomain = | ||
| | { | ||
| /** | ||
|
|
@@ -32,7 +36,22 @@ type ProviderProps = { | |
| * @returns {OpenFeatureProvider} context provider | ||
| */ | ||
| export function OpenFeatureProvider({ client, domain, children, ...options }: ProviderProps) { | ||
| const stableClient = React.useMemo(() => client || OpenFeature.getClient(domain), [client, domain]); | ||
| const stableClient = React.useMemo(() => { | ||
| if (client) { | ||
| return setReactFrameworkMetadata(client); | ||
|
Member
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 mutates a user-provided client that might also be used elsewhere, this seems problematic? |
||
| } | ||
|
|
||
| return setReactFrameworkMetadata(OpenFeature.getClient(domain)); | ||
| }, [client, domain]); | ||
|
|
||
| return <Context.Provider value={{ client: stableClient, options }}>{children}</Context.Provider>; | ||
| } | ||
|
|
||
| function setReactFrameworkMetadata(client: Client): Client { | ||
| // When a caller provides an existing client, preserve that instance but mark it | ||
| // as React-backed so metadata stays aligned with provider-created clients. | ||
| // The cast is needed because `setFrameworkMetadata` is an internal method on the | ||
| // SDK-owned client implementation, not part of the public `Client` interface. | ||
| (client as FrameworkMetadataClient).setFrameworkMetadata?.('react'); | ||
| return client; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.