Contentful Personalization & Analytics
    Preparing search index...
    FlagsResolver: {
        resolve(
            changes?: {
                key: string;
                meta: { experienceId: string; variantIndex: number };
                type: "Variable";
                value: null | string | number | boolean | Record<string, JSONType>;
            }[],
        ): Flags;
    } = ...

    Resolves a Flags map from a list of optimization changes.

    Type declaration

    • resolve: function
      • Build a flattened map of flag keys to values from a change list.

        Parameters

        • Optionalchanges: {
              key: string;
              meta: { experienceId: string; variantIndex: number };
              type: "Variable";
              value: null | string | number | boolean | Record<string, JSONType>;
          }[]

          The change list returned by the optimization service.

          • key: string

            Key identifying the subject of the change.

          • meta: { experienceId: string; variantIndex: number }

            Metadata describing the originating experience and variant index.

            • experienceId: string

              Identifier of the personalization or experiment experience.

            • variantIndex: number

              Index of the variant within the experience configuration.

              Typically corresponds to the array index in the experience's distribution.

          • type: "Variable"

            Discriminator for a variable change.

          • value: null | string | number | boolean | Record<string, JSONType>

            New value for the variable identified by ChangeBase.key.

        Returns Flags

        A map of flag keys to their resolved values.

        const flags = FlagsResolver.resolve(data.changes)
        if (flags['theme'] === 'dark') enableDarkMode()

        // Handles wrapped values produced by the API

        const flags = FlagsResolver.resolve([
        { type: 'Variable', key: 'price', value: { value: { amount: 10, currency: 'USD' } } }
        ])
        console.log(flags.price.amount) // 10

    Given an Optimization ChangeArray, this utility flattens the list into a simple key–value object suitable for quick lookups in client code. When changes is undefined, an empty object is returned. If a change value is wrapped in an object like { value: { ... } }, this resolver unwraps it to the underlying object.