# Migration to v4.X and higher

This guide assists developers in migrating from Flagship 3.X to Flagship 4.X and higher.

The primary changes include:

* Asynchronous Flagship.start
* Visitor Creation options
* Flagship configuration
* Renamed Types and APIs

For more details, see the [change log](https://github.com/flagship-io/flagship-ts-sdk/releases)

## Asynchronous Flagship.start

In version 5.X and higher, The `Flagship.start` method is now asynchronous and returns a Promise. You may need to update your code to properly await initialization before accessing flags or creating visitors.

{% tabs %}
{% tab title="Now" %}

```typescript
// New version - asynchronous
const flagship = await Flagship.start('ENV_ID', 'API_KEY', {
    // config options
  });

  // Now you can safely use the SDK
const visitor = flagship.newVisitor({
    visitorId: 'visitor-id',
    hasConsented: true
});
```

{% endtab %}

{% tab title="Before" %}

```typescript
// Previous version - synchronous
const flagship = Flagship.start('ENV_ID', 'API_KEY', {
  // config options
});

// Immediately use the SDK
const visitor = flagship.newVisitor({
  visitorId: 'visitor-id',
  hasConsented: true
});
```

{% endtab %}
{% endtabs %}

## Visitor Creation options

In version 4.X and higher , when creating a visitor, the [hasConsented](/server-side/sdks/js-sdk/js-reference.md#hasconsented-property) option is now required. In contrast, this option was optional in version 3.X. Additionally, the `isNewInstance` option has been replaced with [shouldSaveInstance](/server-side/sdks/js-sdk/js-reference.md#visitor-class), `onFetchFlagsStatusChanged` has been renamed to [onFlagsStatusChanged](/server-side/sdks/js-sdk/js-reference.md#onflagsstatuschanged)

Below is an example of how consent is used in versions 4.X and 3.X

{% tabs %}
{% tab title="Now" %}

```typescript
const fsVisitor = Flagship.newVisitor({
  hasConsented: true, // This is now mandatory
});
```

{% endtab %}

{% tab title="Before" %}

```typescript
const fsVisitor = Flagship.newVisitor();
```

{% endtab %}
{% endtabs %}

## Flagship configuration

In version 4.X and higher, the `enableClientCache`option of [IFlagshipConfig](/server-side/sdks/js-sdk/js-reference.md#sdk-configuration) has been replaced with [reuseVisitorIds](doc:js-reference#sdk-configuration) and the `statusChangedCallback` has been replaced with [`onSdkStatusChanged`](/server-side/sdks/js-sdk/js-reference.md#onsdkstatuschanged).

## Renamed Types and APIs

### Flag Status

In the version **5.x** and higher, the `FetchFlagsStatus` type has been renamed to `FlagsStatus` for clarity.

### Flagship SDK Status

The `FlagshipStatus` enum has been superseded by [`FSSdkStatus`](/server-side/sdks/js-sdk/js-reference.md#fssdkstatus).

The table below matches the `FlagshipStatus` enum keys from version 3.X to the corresponding [`FSSdkStatus`](/server-side/sdks/js-sdk/js-reference.md#fssdkstatus) keys in version 4.X and higher.

| V4.X                  | V3.X             |
| --------------------- | ---------------- |
| SDK\_NOT\_INITIALIZED | NOT\_READY       |
| SDK\_NOT\_INITIALIZED | NOT\_INITIALIZED |
| SDK\_INITIALIZING     | STARTING         |
| SDK\_INITIALIZING     | POLLING          |
| SDK\_PANIC            | READY\_PANIC\_ON |
| SDK\_INITIALIZED      | READY            |

\\

## `GetFlag` method update

In version 4.X and higher, the approach to setting a flag's default value has been modified. The default value is no longer set using the [getFlag](/server-side/sdks/js-sdk/js-reference.md#getflag-method) method of visitor instance. Instead, it is now set using the [getValue](/server-side/sdks/js-sdk/js-reference.md#getvalue-method) of [flag](/server-side/sdks/js-sdk/js-reference.md#ifsflag-interface) instance.

Here's how you can retrieve the default value of a flag in versions 4.X and 3.X:

{% tabs %}
{% tab title="Now" %}

```typescript

...

const flag = fsVisitor.getFlag("myFlagKey");
const flagValue = flag.getValue("default-value");
```

{% endtab %}

{% tab title="Before" %}

```typescript

...

const flag = fsVisitor.getFlag("myFlagKey", "default-value");
const flagValue = flag.getValue();
```

{% endtab %}
{% endtabs %}


---

# 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/sdks/js-sdk/javascript-migration.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.
