Skip to content

Web JS Provider#1

Closed
rgrassian-split wants to merge 7 commits intomainfrom
dev
Closed

Web JS Provider#1
rgrassian-split wants to merge 7 commits intomainfrom
dev

Conversation

@rgrassian-split
Copy link
Contributor

No description provided.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems you are using https://splitio.jfrog.io registry for installing dependencies (probably you are using your credentials for the webconsole). So, consider removing the package-lock.json file, running npm install again without any credentials, and submit the change.

This way, package-lock will use the public NPM registry, and if the project is made public, anyone might run npm install on their side.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, but sorry I am new to JS, how can I run npm install without credentials?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the following steps should work:

  1. Open your ~/.npmrc file and comment (# ...) or remove your credentials there.
    The file should look something like:
init-author-name=Your Name

# registry=https://splitio.jfrog.io/artifactory/api/npm/npm-all-virtual/
# //splitio.jfrog.io/artifactory/api/npm/npm-all-virtual/:_auth = XXX
# always-auth = true
  1. Delete the package-lock.file.
  2. Run npm install again.
  3. Revert changes in 1st step.

metadata = {
name: "split",
};
private initialized: Promise<void>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initialized promise should be used somewhere. Maybe inside the onContextChange method part of the Provider interface?
(Definitively not inside the resolve<Boolean|String|...>Evaluation methods, because unlike the server-side OpenFeature Provider, they are synchronous).

That promise should somehow be used to wait for the provider to be ready and support:

await OpenFeature.setProviderAndWait(new OpenFeatureSplitProvider({splitClient}));

as explained here: https://www.npmjs.com/package/@openfeature/web-sdk#awaitable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im actually having trouble figure out where this would be used, or if it is even necessary? I am kind of thinking it might not be, but not confident. How do you think it should be used in the onContextChange method?

Copy link
Contributor

@EmilianoSanchez EmilianoSanchez Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I guess it's not mandatory to use, because users can evaluate anyway (e.g., const boolValue = client.getBooleanValue('boolFlag', false);), and if the client is not ready, the method call will retrieve the provided default value.

But it's nice to have if users can use the await OpenFeature.setProviderAndWait(...); method to start evaluating once the Split client is ready.

Anyway, I also don't know how the promise can be used for that, in which part of the provider should be used :/

import type SplitIO from "@splitsoftware/splitio/types/splitio";

export interface SplitProviderOptions {
splitClient: SplitIO.IClient;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the Web use splitClient: SplitIO.IBrowserClient;
This changes the interface compared to server-side (Node.js SDK), because the getTreatment methods doesn't require a traffic type key as first argument.
In client-side (JS Browser SDK), the key is provided in the SDK configuration, or when calling the factory.client(key) method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the OpenFeature spec we need to be able to implement evaluations with a provided key, it seems like using the IBrowserClient would not allow us to do that right?

Copy link
Contributor

@EmilianoSanchez EmilianoSanchez Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not like Node.js (server-side API, IClient).
In the Web (client-side API, IBrowserClient), you can use the SDK factory instance to retrieve clients for different keys than the default one provided in the config:

const newClient: SplitIO.IBrowserClient = splitFactory.client('new-targeting-key');

That's why I suggest in the README to pass the factory instance to the provider, rather than the default Split client: #2

const splitFactory = SplitFactory({
  core: {
    authorizationKey,
    key: targetingKey
  }
});
const provider = new OpenFeatureSplitProvider({splitFactory});

@ZamoraEmmanuel
Copy link
Contributor

branch migrated to development equivalent pr:
#4

@Israphel Israphel deleted the dev branch September 18, 2025 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants