Contentful Personalization & Analytics
    Preparing search index...
    FlagsResolver: {
        resolve(
            changes?: (
                | {
                    key: string;
                    meta: { experienceId: string; variantIndex: number };
                    type: "Variable";
                    value: string | number | boolean | Record<string, JSONType> | null;
                }
                | {
                    id: string;
                    meta: { optimizationId: string; variantIndex: number };
                    type: "Experience";
                    variantId: string;
                }
                | {
                    id: string;
                    meta: { optimizationId: string; variantIndex: number };
                    type: "Fragment";
                    variantId: string;
                }
            )[],
        ): 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: string | number | boolean | Record<string, JSONType> | null;
              }
              | {
                  id: string;
                  meta: { optimizationId: string; variantIndex: number };
                  type: "Experience";
                  variantId: string;
              }
              | {
                  id: string;
                  meta: { optimizationId: string; variantIndex: number };
                  type: "Fragment";
                  variantId: string;
              }
          )[]

          The change list returned by the optimization service.

          • {
                key: string;
                meta: { experienceId: string; variantIndex: number };
                type: "Variable";
                value: string | number | boolean | Record<string, JSONType> | null;
            }
            • 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: string | number | boolean | Record<string, JSONType> | null

              New value for the variable identified by ChangeBase.key.

          • {
                id: string;
                meta: { optimizationId: string; variantIndex: number };
                type: "Experience";
                variantId: string;
            }
            • id: string

              Identifier of the entity affected by the change.

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

              Metadata describing the originating optimization and variant index.

              • optimizationId: string

                Identifier of the optimization that produced this change.

              • variantIndex: number

                Index of the variant within the optimization's distribution.

            • type: "Experience"

              Discriminator for an experience change.

            • variantId: string

              Identifier of the selected variant.

          • {
                id: string;
                meta: { optimizationId: string; variantIndex: number };
                type: "Fragment";
                variantId: string;
            }
            • id: string

              Identifier of the entity affected by the change.

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

              Metadata describing the originating optimization and variant index.

              • optimizationId: string

                Identifier of the optimization that produced this change.

              • variantIndex: number

                Index of the variant within the optimization's distribution.

            • type: "Fragment"

              Discriminator for a fragment change.

            • variantId: string

              Identifier of the selected variant.

        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 key-value object suitable for 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.