# Migrate to v4.0.X

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

The primary changes include:

* Visitor Creation options
* Flagship configuration
* Flagship SDK Status

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

## Visitor Creation options

In version 4.X, when creating a visitor, the [hasConsented](/server-side/sdks/js-sdk/archived-versions/archived-js-v40x/archived-js-v40x-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/archived-versions/archived-js-v40x/archived-js-v40x-reference.md#newvisitor-method).

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

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

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

## Flagship configuration

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

## Flagship SDK Status

The `FlagshipStatus` enum has been superseded by [`FSSdkStatus`](doc:javascript-reference#fssdkstatus).

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

| 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, 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/archived-versions/archived-js-v40x/archived-js-v40x-reference.md#getflag-method) method of visitor instance. Instead, it is now set using the [getValue](/server-side/sdks/js-sdk/archived-versions/archived-js-v40x/archived-js-v40x-reference.md#getflag-method) of [flag](/server-side/sdks/js-sdk/archived-versions/archived-js-v40x/archived-js-v40x-reference.md#ifsflag-interface) instance.

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

```typescript

...

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

```typescript

...

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


---

# 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/archived-versions/archived-js-v40x/archived-js-v40x-migration-to-4x.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.
