UNPKG

@klevu/core

Version:

Typescript SDK that simplifies development on Klevu backend. Klevu provides advanced AI-powered search and discovery solutions for online retailers.

37 lines (36 loc) 1.78 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { KlevuResponseObject } from "./responseObject.js"; /** * Returns only JSON from KlevuFetch that can be sent to client in SSR process to hydrate * * @param response Response value of KlevuFetch * @returns JSON only raw response */ export function KlevuPackFetchResult(response) { if (!response.apiResponse) { throw new Error("No result to pack"); } return response.apiResponse; } /** * This function hydrates KlevuFetch response object from raw JSON that was fetched on server side. * It doesn't do request to Klevu API, but it will do requests that are made with logic of queries. * For example all analytical requests are automatically sent from client. * * @param packed Raw JSON from KlevuFetch * @param functions Query functions used to create KlevuFetch query in backend. * @returns KlevuFetch response without making any request to servers */ export function KlevuHydratePackedFetchResult(packed, functions) { return __awaiter(this, void 0, void 0, function* () { return new KlevuResponseObject(packed, yield Promise.all(functions)); }); }