Migration to 5.X

Overview

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

The primary changes include:

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

For more details, see the change log

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.

// 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
});
// 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
});

Visitor Creation options

In version 4.X and higher , when creating a visitor, the hasConsented option is now required. In contrast, this option was optional in version 3.X. Additionally, the isNewInstance option has been replaced with shouldSaveInstance, onFetchFlagsStatusChanged has been renamed to onFlagsStatusChanged

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

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

Flagship configuration

In version 4.X and higher, the enableClientCacheoption of IFlagshipConfig has been replaced with reuseVisitorIds and the statusChangedCallback has been replaced with onSdkStatusChanged.

Renamed Types and APIs

Flagship SDK Status

The FlagshipStatus enum has been superseded by FSSdkStatus.

The table below matches the FlagshipStatus enum keys from version 3.X to the corresponding FSSdkStatus keys in version 4.X and higher.

V4.XV3.X
SDK_NOT_INITIALIZEDNOT_READY
SDK_NOT_INITIALIZEDNOT_INITIALIZED
SDK_INITIALIZINGSTARTING
SDK_INITIALIZINGPOLLING
SDK_PANICREADY_PANIC_ON
SDK_INITIALIZEDREADY

Flag status

FetchFlagsStatus has been renamed to FlagsStatus for better clarity

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 method of visitor instance. Instead, it is now set using the getValue of flag instance.

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


...

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

...

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