ChemPal Documentation - v1.6.0
    Preparing search index...

    Function isValidSearchResponse

    • Type guard to validate if a response matches the Wix QueryResponse structure. Performs deep validation of the response object including the nested catalog structure, products metadata, and ensures all products in the list are valid Wix products.

      Parameters

      • response: unknown

        Response object to validate

      Returns response is QueryResponse

      Type predicate indicating if response is a valid QueryResponse

      // Valid search response
      const validResponse = {
      data: {
      catalog: {
      category: {
      productsWithMetaData: {
      totalCount: 1,
      list: [
      {
      price: 29.99,
      formattedPrice: "$29.99",
      name: "Sodium Chloride",
      urlPart: "sodium-chloride",
      productItems: [],
      options: []
      }
      ]
      }
      }
      }
      }
      };

      if (isValidSearchResponse(validResponse)) {
      console.log("Valid search response");
      const firstProduct = validResponse.data.catalog.category.productsWithMetaData.list[0];
      console.log("First product:", firstProduct.name);
      }
      export function isValidSearchResponse(response: unknown): response is QueryResponse {
      return v.safeParse(validSearchResponseSchema, response).success;
      }