# Reference

{% hint style="info" %}
📘 Flagship SDK Reference

Please refer to the [JS SDK Documentation](https://docs.developers.flagship.io/docs/javascript-reference-beta#/) for Flagship classes
{% endhint %}

## ABTastyProvider class

The `ABTastyProvider` implements the OpenFeature Provider interface and is responsible for:

* Initializing the Flagship Client:\
  It starts the Flagship client using the provided environment ID, API key, and correct config.
* Creating a Visitor:\
  It instantiates a visitor with context details (e.g., targetingKey, user context), fetches the associated flags, and updates context (if needed).
* Logging Adaptation:\
  Uses an AdapterLogger to map Flagship logging to the OpenFeature Logger interface.
* Delegating Resolution:\
  Delegates flag resolution tasks to the ABTastyResolver, which performs the resolution based on visitor context.

### Key Methods

#### constructor(envId: string, apiKey: string, config?: IFlagshipConfig, logger?: OpenFeatureLogger)

* Description: Initializes the Flagship client. It:
  * Starts the Flagship client using the provided environment ID and API key.
* Arguments:

| Name   | Type   | Required     | Description                                                                |
| ------ | ------ | ------------ | -------------------------------------------------------------------------- |
| envId  | String | **Required** | Environment ID provided by Flagship.                                       |
| apiKey | String | **Required** | Api authentication key provided by Flagship.                               |
| config | Object | **Optional** | Custom flagship configuration. [see SDK configuration](#sdk-configuration) |
| logger | Object | **Optional** | AdapterLogger instance.                                                    |

Example:

```javascript
const {
    ABTastyProvider,
} = require("@flagship.io/openfeature-provider-js");

// Step 1: Start the OpenFeature SDK by providing the environment ID and API key
let provider = new ABTastyProvider("<ENV_ID>", "<API_KEY>");
```

#### initialize(context?: EvaluationContext)

* Description: Internally called by the OpenFeature class when the provider is set and initializes the visitor. It:
  * Creates a new visitor with the given evaluation context.
  * Fetches feature flags.
  * Instantiates the ABTastyResolver.
  * Emits the provider's Ready event.
* Arguments:
  * context: Optional context (e.g., targeting key and additional user data).
* Returns:
  * A promise that resolves when initialization completes.

Example:

```javascript
const {
    ABTastyProvider,
} = require("@flagship.io/openfeature-provider-js");
const { OpenFeature } = require("@openfeature/server-sdk");

// Step 1: Start the OpenFeature SDK by providing the environment ID and API key
let provider = new ABTastyProvider("<ENV_ID>", "<API_KEY>");

// Step 2: Set Flagship SDK as provider
await OpenFeature.setProviderAndWait(provider);
```

#### getConfig(): IFlagshipConfig

* Description: Retrieves the current configuration settings used by the Flagship client.
* Returns:
  * The configuration object (IFlagshipConfig).

#### close(): Promise\<void>

* Description: Gracefully shuts down the Flagship client connection.
* Returns:
  * A promise that resolves when the client has successfully closed.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.abtasty.com/server-side/integrations/open-feature/open-feature-js/open-feature-js-reference.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
