@replohq/canopy-sdk 0.10.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_vendor/schemas/agentTools/customIntegrations/loaders/yotpo.d.ts +37 -0
- package/_vendor/schemas/agentTools/customIntegrations/loaders/yotpo.mjs +37 -0
- package/_vendor/schemas/loaderKeys.d.ts +4 -0
- package/_vendor/schemas/loaderKeys.mjs +3 -1
- package/cart/utils/cart-utils.d.ts +6 -0
- package/cart/utils/cart-utils.js +11 -10
- package/cart/utils/cart-utils.js.map +2 -2
- package/cart/utils/cookie-cart-persistence.js +16 -3
- package/cart/utils/cookie-cart-persistence.js.map +2 -2
- package/loaders/yotpo-review-aggregate-loader.d.ts +12 -0
- package/loaders/yotpo-review-aggregate-loader.js +50 -0
- package/loaders/yotpo-review-aggregate-loader.js.map +7 -0
- package/loaders/yotpo-reviews-loader.d.ts +14 -0
- package/loaders/yotpo-reviews-loader.js +65 -0
- package/loaders/yotpo-reviews-loader.js.map +7 -0
- package/package.json +1 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const yotpoNangoConnectionConfigSchema: z.ZodObject<{
|
|
3
|
+
storeId: z.ZodString;
|
|
4
|
+
}, z.core.$strip>;
|
|
5
|
+
export declare const yotpoProductReviewsLoaderInputSchema: z.ZodObject<{
|
|
6
|
+
productId: z.ZodString;
|
|
7
|
+
perPage: z.ZodOptional<z.ZodNumber>;
|
|
8
|
+
page: z.ZodOptional<z.ZodNumber>;
|
|
9
|
+
}, z.core.$strip>;
|
|
10
|
+
export declare const yotpoReviewLoaderItemSchema: z.ZodObject<{
|
|
11
|
+
id: z.ZodString;
|
|
12
|
+
title: z.ZodNullable<z.ZodString>;
|
|
13
|
+
content: z.ZodNullable<z.ZodString>;
|
|
14
|
+
score: z.ZodNullable<z.ZodNumber>;
|
|
15
|
+
createdAt: z.ZodNullable<z.ZodString>;
|
|
16
|
+
verifiedBuyer: z.ZodBoolean;
|
|
17
|
+
reviewerName: z.ZodNullable<z.ZodString>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
export declare const yotpoProductReviewsLoaderOutputSchema: z.ZodObject<{
|
|
20
|
+
reviews: z.ZodArray<z.ZodObject<{
|
|
21
|
+
id: z.ZodString;
|
|
22
|
+
title: z.ZodNullable<z.ZodString>;
|
|
23
|
+
content: z.ZodNullable<z.ZodString>;
|
|
24
|
+
score: z.ZodNullable<z.ZodNumber>;
|
|
25
|
+
createdAt: z.ZodNullable<z.ZodString>;
|
|
26
|
+
verifiedBuyer: z.ZodBoolean;
|
|
27
|
+
reviewerName: z.ZodNullable<z.ZodString>;
|
|
28
|
+
}, z.core.$strip>>;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
export declare const yotpoProductReviewAggregateLoaderInputSchema: z.ZodObject<{
|
|
31
|
+
productId: z.ZodString;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
export declare const yotpoProductReviewAggregateLoaderOutputSchema: z.ZodObject<{
|
|
34
|
+
averageScore: z.ZodNumber;
|
|
35
|
+
totalReviews: z.ZodNumber;
|
|
36
|
+
starDistribution: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
37
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// ../schemas/agentTools/customIntegrations/loaders/yotpo.ts
|
|
4
|
+
var yotpoNangoConnectionConfigSchema = z.object({
|
|
5
|
+
storeId: z.string().min(1)
|
|
6
|
+
});
|
|
7
|
+
var yotpoProductReviewsLoaderInputSchema = z.object({
|
|
8
|
+
productId: z.string().describe(
|
|
9
|
+
"Yotpo external product ID for the product (typically the numeric Shopify product ID)."
|
|
10
|
+
),
|
|
11
|
+
perPage: z.number().int().min(1).max(150).optional().describe("Reviews to return (default 10, max 150)."),
|
|
12
|
+
page: z.number().int().min(1).optional().describe("Page number (1-indexed, default 1).")
|
|
13
|
+
});
|
|
14
|
+
var yotpoReviewLoaderItemSchema = z.object({
|
|
15
|
+
id: z.string(),
|
|
16
|
+
title: z.string().nullable(),
|
|
17
|
+
content: z.string().nullable(),
|
|
18
|
+
score: z.number().nullable(),
|
|
19
|
+
createdAt: z.string().nullable(),
|
|
20
|
+
verifiedBuyer: z.boolean(),
|
|
21
|
+
reviewerName: z.string().nullable()
|
|
22
|
+
});
|
|
23
|
+
var yotpoProductReviewsLoaderOutputSchema = z.object({
|
|
24
|
+
reviews: z.array(yotpoReviewLoaderItemSchema)
|
|
25
|
+
});
|
|
26
|
+
var yotpoProductReviewAggregateLoaderInputSchema = z.object({
|
|
27
|
+
productId: z.string().describe(
|
|
28
|
+
"Yotpo external product ID for the product (typically the numeric Shopify product ID)."
|
|
29
|
+
)
|
|
30
|
+
});
|
|
31
|
+
var yotpoProductReviewAggregateLoaderOutputSchema = z.object({
|
|
32
|
+
averageScore: z.number(),
|
|
33
|
+
totalReviews: z.number(),
|
|
34
|
+
starDistribution: z.record(z.string(), z.number())
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export { yotpoNangoConnectionConfigSchema, yotpoProductReviewAggregateLoaderInputSchema, yotpoProductReviewAggregateLoaderOutputSchema, yotpoProductReviewsLoaderInputSchema, yotpoProductReviewsLoaderOutputSchema, yotpoReviewLoaderItemSchema };
|
|
@@ -22,6 +22,8 @@ export declare const DATA_LOADER_KEYS: {
|
|
|
22
22
|
readonly SMILE_IO_VIP_TIERS: "smile_io.vip_tiers";
|
|
23
23
|
readonly SMILE_IO_EARNING_RULES: "smile_io.earning_rules";
|
|
24
24
|
readonly SMILE_IO_REWARDS: "smile_io.rewards";
|
|
25
|
+
readonly YOTPO_PRODUCT_REVIEWS: "yotpo.product_reviews";
|
|
26
|
+
readonly YOTPO_PRODUCT_REVIEW_AGGREGATE: "yotpo.product_review_aggregate";
|
|
25
27
|
};
|
|
26
28
|
export type DataLoaderKey = (typeof DATA_LOADER_KEYS)[keyof typeof DATA_LOADER_KEYS];
|
|
27
29
|
export declare const dataLoaderKeySchema: z.ZodEnum<{
|
|
@@ -36,4 +38,6 @@ export declare const dataLoaderKeySchema: z.ZodEnum<{
|
|
|
36
38
|
"smile_io.vip_tiers": "smile_io.vip_tiers";
|
|
37
39
|
"smile_io.earning_rules": "smile_io.earning_rules";
|
|
38
40
|
"smile_io.rewards": "smile_io.rewards";
|
|
41
|
+
"yotpo.product_reviews": "yotpo.product_reviews";
|
|
42
|
+
"yotpo.product_review_aggregate": "yotpo.product_review_aggregate";
|
|
39
43
|
}>;
|
|
@@ -12,7 +12,9 @@ var DATA_LOADER_KEYS = {
|
|
|
12
12
|
LEVANTA_PRODUCT: "levanta_products.product",
|
|
13
13
|
SMILE_IO_VIP_TIERS: "smile_io.vip_tiers",
|
|
14
14
|
SMILE_IO_EARNING_RULES: "smile_io.earning_rules",
|
|
15
|
-
SMILE_IO_REWARDS: "smile_io.rewards"
|
|
15
|
+
SMILE_IO_REWARDS: "smile_io.rewards",
|
|
16
|
+
YOTPO_PRODUCT_REVIEWS: "yotpo.product_reviews",
|
|
17
|
+
YOTPO_PRODUCT_REVIEW_AGGREGATE: "yotpo.product_review_aggregate"
|
|
16
18
|
};
|
|
17
19
|
var dataLoaderKeySchema = z.enum(Object.values(DATA_LOADER_KEYS));
|
|
18
20
|
|
|
@@ -5,6 +5,12 @@ export interface CartTotals {
|
|
|
5
5
|
totalSavings: number;
|
|
6
6
|
total: number;
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Sum the final (post selling-plan) price of every line item in the cart.
|
|
10
|
+
* This is the authoritative subtotal for cookie-based carts, which have no
|
|
11
|
+
* server-computed cost to rely on.
|
|
12
|
+
*/
|
|
13
|
+
export declare function calculateLineItemsSubtotal(lineItems: CartLine[]): number;
|
|
8
14
|
/**
|
|
9
15
|
* Calculate cart totals including subtotal, discounts, and final total.
|
|
10
16
|
* When cart cost data is provided (from Shopify), uses the actual totalAmount
|
package/cart/utils/cart-utils.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { getCartLinePricing } from "./variant-to-cart-line";
|
|
2
|
+
function calculateLineItemsSubtotal(lineItems) {
|
|
3
|
+
return lineItems.reduce(
|
|
4
|
+
(sum, item) => sum + getCartLinePricing(item).finalPrice * item.quantity,
|
|
5
|
+
0
|
|
6
|
+
);
|
|
7
|
+
}
|
|
2
8
|
function calculateCartTotals({
|
|
3
9
|
lineItems,
|
|
4
10
|
cart
|
|
5
11
|
}) {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
compareAtSubtotal: sum.compareAtSubtotal + pricing.compareAtPrice * item.quantity,
|
|
11
|
-
lineItemSubtotal: sum.lineItemSubtotal + pricing.finalPrice * item.quantity
|
|
12
|
-
};
|
|
13
|
-
},
|
|
14
|
-
{ compareAtSubtotal: 0, lineItemSubtotal: 0 }
|
|
15
|
-
);
|
|
12
|
+
const lineItemSubtotal = calculateLineItemsSubtotal(lineItems);
|
|
13
|
+
const compareAtSubtotal = lineItems.reduce((sum, item) => {
|
|
14
|
+
return sum + getCartLinePricing(item).compareAtPrice * item.quantity;
|
|
15
|
+
}, 0);
|
|
16
16
|
const total = cart?.cost.totalAmount ?? lineItemSubtotal;
|
|
17
17
|
const actualSubtotal = cart?.cost.subtotalAmount ?? lineItemSubtotal;
|
|
18
18
|
const discountAmount = actualSubtotal - total;
|
|
@@ -42,6 +42,7 @@ function formatSellingPlanId(sellingPlanId) {
|
|
|
42
42
|
}
|
|
43
43
|
export {
|
|
44
44
|
calculateCartTotals,
|
|
45
|
+
calculateLineItemsSubtotal,
|
|
45
46
|
formatPrice,
|
|
46
47
|
formatSellingPlanId
|
|
47
48
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../cart/utils/cart-utils.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Cart, CartLine } from \"../cart-types\";\n\nimport { getCartLinePricing } from \"./variant-to-cart-line\";\n\nexport interface CartTotals {\n subtotal: number;\n discountAmount: number;\n totalSavings: number;\n total: number;\n}\n\n/**\n * Calculate cart totals including subtotal, discounts, and final total.\n * When cart cost data is provided (from Shopify), uses the actual totalAmount\n * which includes cart-level discounts from discount codes.\n *\n * @param options - Object containing lineItems and cart\n * @param options.lineItems - Array of cart line items\n * @param options.cart - Optional cart data from Shopify (includes discount codes)\n */\nexport function calculateCartTotals({\n lineItems,\n cart,\n}: {\n lineItems: CartLine[];\n cart: Cart | null;\n}): CartTotals {\n const
|
|
5
|
-
"mappings": "AAEA,SAAS,0BAA0B;
|
|
4
|
+
"sourcesContent": ["import type { Cart, CartLine } from \"../cart-types\";\n\nimport { getCartLinePricing } from \"./variant-to-cart-line\";\n\nexport interface CartTotals {\n subtotal: number;\n discountAmount: number;\n totalSavings: number;\n total: number;\n}\n\n/**\n * Sum the final (post selling-plan) price of every line item in the cart.\n * This is the authoritative subtotal for cookie-based carts, which have no\n * server-computed cost to rely on.\n */\nexport function calculateLineItemsSubtotal(lineItems: CartLine[]): number {\n return lineItems.reduce(\n (sum, item) => sum + getCartLinePricing(item).finalPrice * item.quantity,\n 0,\n );\n}\n\n/**\n * Calculate cart totals including subtotal, discounts, and final total.\n * When cart cost data is provided (from Shopify), uses the actual totalAmount\n * which includes cart-level discounts from discount codes.\n *\n * @param options - Object containing lineItems and cart\n * @param options.lineItems - Array of cart line items\n * @param options.cart - Optional cart data from Shopify (includes discount codes)\n */\nexport function calculateCartTotals({\n lineItems,\n cart,\n}: {\n lineItems: CartLine[];\n cart: Cart | null;\n}): CartTotals {\n const lineItemSubtotal = calculateLineItemsSubtotal(lineItems);\n const compareAtSubtotal = lineItems.reduce((sum, item) => {\n return sum + getCartLinePricing(item).compareAtPrice * item.quantity;\n }, 0);\n\n // NOTE (Jasmine, 2026-07-22): Trust the provider's authoritative cost when\n // present. For Shopify this is the server-computed cart cost (including a\n // legitimate $0 when items aren't purchasable), which we must not\n // second-guess; cookie carts keep their cost truthful via\n // cookie-cart-persistence.ts.\n const total = cart?.cost.totalAmount ?? lineItemSubtotal;\n\n // If we have provider cost data, use subtotalAmount which doesn't include discounts\n const actualSubtotal = cart?.cost.subtotalAmount ?? lineItemSubtotal;\n const discountAmount = actualSubtotal - total;\n\n const totalSavings = compareAtSubtotal - total;\n\n return {\n subtotal: lineItemSubtotal,\n discountAmount,\n totalSavings,\n total,\n };\n}\n\n/**\n * Format price as currency string\n */\nexport function formatPrice(price: number, currency: string = \"USD\"): string {\n const formatter = new Intl.NumberFormat(\"en-US\", {\n style: \"currency\",\n currency: currency,\n });\n return formatter.format(price);\n}\n\n/**\n * Validates and formats a Shopify selling plan ID to ensure it has the correct GID format.\n *\n * @param sellingPlanId - The selling plan ID to validate and format\n * @returns The formatted selling plan ID with GID prefix, or null if no ID provided\n */\nexport function formatSellingPlanId(\n sellingPlanId: string | null | undefined,\n): string | null {\n if (!sellingPlanId) {\n return null;\n }\n\n // Check if it already has the gid format\n if (sellingPlanId.startsWith(\"gid://shopify/SellingPlan/\")) {\n return sellingPlanId;\n }\n\n // If it doesn't have the gid format, prepend it\n return `gid://shopify/SellingPlan/${sellingPlanId}`;\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,0BAA0B;AAc5B,SAAS,2BAA2B,WAA+B;AACxE,SAAO,UAAU;AAAA,IACf,CAAC,KAAK,SAAS,MAAM,mBAAmB,IAAI,EAAE,aAAa,KAAK;AAAA,IAChE;AAAA,EACF;AACF;AAWO,SAAS,oBAAoB;AAAA,EAClC;AAAA,EACA;AACF,GAGe;AACb,QAAM,mBAAmB,2BAA2B,SAAS;AAC7D,QAAM,oBAAoB,UAAU,OAAO,CAAC,KAAK,SAAS;AACxD,WAAO,MAAM,mBAAmB,IAAI,EAAE,iBAAiB,KAAK;AAAA,EAC9D,GAAG,CAAC;AAOJ,QAAM,QAAQ,MAAM,KAAK,eAAe;AAGxC,QAAM,iBAAiB,MAAM,KAAK,kBAAkB;AACpD,QAAM,iBAAiB,iBAAiB;AAExC,QAAM,eAAe,oBAAoB;AAEzC,SAAO;AAAA,IACL,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAKO,SAAS,YAAY,OAAe,WAAmB,OAAe;AAC3E,QAAM,YAAY,IAAI,KAAK,aAAa,SAAS;AAAA,IAC/C,OAAO;AAAA,IACP;AAAA,EACF,CAAC;AACD,SAAO,UAAU,OAAO,KAAK;AAC/B;AAQO,SAAS,oBACd,eACe;AACf,MAAI,CAAC,eAAe;AAClB,WAAO;AAAA,EACT;AAGA,MAAI,cAAc,WAAW,4BAA4B,GAAG;AAC1D,WAAO;AAAA,EACT;AAGA,SAAO,6BAA6B,aAAa;AACnD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
import { cookies } from "next/headers";
|
|
3
|
+
import { calculateLineItemsSubtotal } from "./cart-utils";
|
|
3
4
|
const CART_COOKIE_MAX_AGE = 60 * 60 * 24 * 30;
|
|
5
|
+
function recalculateCartCost(cart) {
|
|
6
|
+
const subtotal = calculateLineItemsSubtotal(cart.lines);
|
|
7
|
+
return {
|
|
8
|
+
...cart,
|
|
9
|
+
cost: {
|
|
10
|
+
...cart.cost,
|
|
11
|
+
subtotalAmount: subtotal,
|
|
12
|
+
totalAmount: subtotal
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
4
16
|
async function saveCartToCookie(cart, cookieName) {
|
|
5
17
|
const cookieStore = await cookies();
|
|
6
18
|
cookieStore.set(cookieName, JSON.stringify(cart), {
|
|
@@ -34,7 +46,7 @@ async function updateCartInCookie(cartId, cookieName, updater) {
|
|
|
34
46
|
if (!existingCart || existingCart.id !== cartId) {
|
|
35
47
|
return null;
|
|
36
48
|
}
|
|
37
|
-
const updatedCart = updater(existingCart);
|
|
49
|
+
const updatedCart = recalculateCartCost(updater(existingCart));
|
|
38
50
|
await saveCartToCookie(updatedCart, cookieName);
|
|
39
51
|
return updatedCart;
|
|
40
52
|
}
|
|
@@ -55,8 +67,9 @@ async function createCartWithPersistence(options) {
|
|
|
55
67
|
convertCartLinePayloadToCartLine(line, options.lineIdGenerator)
|
|
56
68
|
);
|
|
57
69
|
}
|
|
58
|
-
|
|
59
|
-
|
|
70
|
+
const cartWithCost = recalculateCartCost(cart);
|
|
71
|
+
await saveCartToCookie(cartWithCost, options.cookieName);
|
|
72
|
+
return cartWithCost;
|
|
60
73
|
}
|
|
61
74
|
async function addToCartWithPersistence(payload, options) {
|
|
62
75
|
return await updateCartInCookie(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../cart/utils/cookie-cart-persistence.ts"],
|
|
4
|
-
"sourcesContent": ["\"use server\";\n\nimport type {\n AddToCartPayload,\n Cart,\n CartLine,\n CartLinePayload,\n RemoveFromCartPayload,\n UpdateCartLineItemPayload,\n} from \"../cart-types\";\n\nimport { cookies } from \"next/headers\";\n\nconst CART_COOKIE_MAX_AGE = 60 * 60 * 24 * 30; // 30 days\n\n/**\n * Line merge function type - returns index of existing line to merge with, or -1 to add as new line\n */\nexport type LineMergeFn = (\n existingLines: CartLine[],\n newLine: CartLinePayload,\n) => number;\n\n/**\n * Options for creating a cart with persistence\n */\ninterface CreateCartOptions {\n cookieName: string;\n lines?: CartLinePayload[];\n lineIdGenerator: () => string;\n cartIdGenerator: () => string;\n}\n\n/**\n * Options for adding to cart with persistence\n */\ninterface AddToCartOptions {\n cookieName: string;\n mergeFn: LineMergeFn;\n lineIdGenerator: () => string;\n}\n\n/**\n * Save cart to cookie\n */\nexport async function saveCartToCookie(cart: Cart, cookieName: string) {\n const cookieStore = await cookies();\n cookieStore.set(cookieName, JSON.stringify(cart), {\n maxAge: CART_COOKIE_MAX_AGE,\n httpOnly: true,\n secure: process.env.NODE_ENV === \"production\",\n sameSite: \"lax\",\n path: \"/\",\n });\n}\n\n/**\n * Load cart from cookie\n */\nexport async function loadCartFromCookie(\n cookieName: string,\n): Promise<Cart | null> {\n const cookieStore = await cookies();\n const cartCookie = cookieStore.get(cookieName);\n\n if (!cartCookie?.value) {\n return null;\n }\n\n try {\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n return JSON.parse(cartCookie.value) as Cart;\n } catch (error) {\n console.warn(\"Failed to parse cart cookie:\", error);\n await clearCartCookie(cookieName);\n return null;\n }\n}\n\n/**\n * Clear cart cookie\n */\nexport async function clearCartCookie(cookieName: string) {\n const cookieStore = await cookies();\n cookieStore.delete(cookieName);\n}\n\n/**\n * Update cart in cookie atomically (load-transform-save pattern)\n */\nexport async function updateCartInCookie(\n cartId: string,\n cookieName: string,\n updater: (cart: Cart) => Cart,\n): Promise<Cart | null> {\n const existingCart = await loadCartFromCookie(cookieName);\n\n if (!existingCart || existingCart.id !== cartId) {\n return null;\n }\n\n const updatedCart = updater(existingCart);\n\n await saveCartToCookie(updatedCart, cookieName);\n\n return updatedCart;\n}\n\n/**\n * Create a new cart with persistence\n */\nexport async function createCartWithPersistence(\n options: CreateCartOptions,\n): Promise<Cart | null> {\n const cartId = options.cartIdGenerator();\n\n const cart: Cart = {\n id: cartId,\n lines: [],\n cost: {\n subtotalAmount: 0,\n totalAmount: 0,\n currencyCode: \"USD\",\n },\n checkoutUrl: \"/checkout\",\n };\n\n for (const line of options.lines ?? []) {\n cart.lines.push(\n convertCartLinePayloadToCartLine(line, options.lineIdGenerator),\n );\n }\n\n await saveCartToCookie(
|
|
5
|
-
"mappings": ";AAWA,SAAS,eAAe;AAExB,MAAM,sBAAsB,KAAK,KAAK,KAAK;
|
|
4
|
+
"sourcesContent": ["\"use server\";\n\nimport type {\n AddToCartPayload,\n Cart,\n CartLine,\n CartLinePayload,\n RemoveFromCartPayload,\n UpdateCartLineItemPayload,\n} from \"../cart-types\";\n\nimport { cookies } from \"next/headers\";\n\nimport { calculateLineItemsSubtotal } from \"./cart-utils\";\n\nconst CART_COOKIE_MAX_AGE = 60 * 60 * 24 * 30; // 30 days\n\n// NOTE (Jasmine, 2026-07-22): Cookie carts are their own source of truth (no\n// server roundtrip), so recompute cost from line items on every mutation.\n// Without this the persisted cost stays at its initial 0 and every consumer\n// that trusts it (cart total, checkout analytics) reports $0 for a priced cart.\n// Cookie carts apply no cart-level discounts, so subtotal equals total.\nfunction recalculateCartCost(cart: Cart): Cart {\n const subtotal = calculateLineItemsSubtotal(cart.lines);\n return {\n ...cart,\n cost: {\n ...cart.cost,\n subtotalAmount: subtotal,\n totalAmount: subtotal,\n },\n };\n}\n\n/**\n * Line merge function type - returns index of existing line to merge with, or -1 to add as new line\n */\nexport type LineMergeFn = (\n existingLines: CartLine[],\n newLine: CartLinePayload,\n) => number;\n\n/**\n * Options for creating a cart with persistence\n */\ninterface CreateCartOptions {\n cookieName: string;\n lines?: CartLinePayload[];\n lineIdGenerator: () => string;\n cartIdGenerator: () => string;\n}\n\n/**\n * Options for adding to cart with persistence\n */\ninterface AddToCartOptions {\n cookieName: string;\n mergeFn: LineMergeFn;\n lineIdGenerator: () => string;\n}\n\n/**\n * Save cart to cookie\n */\nexport async function saveCartToCookie(cart: Cart, cookieName: string) {\n const cookieStore = await cookies();\n cookieStore.set(cookieName, JSON.stringify(cart), {\n maxAge: CART_COOKIE_MAX_AGE,\n httpOnly: true,\n secure: process.env.NODE_ENV === \"production\",\n sameSite: \"lax\",\n path: \"/\",\n });\n}\n\n/**\n * Load cart from cookie\n */\nexport async function loadCartFromCookie(\n cookieName: string,\n): Promise<Cart | null> {\n const cookieStore = await cookies();\n const cartCookie = cookieStore.get(cookieName);\n\n if (!cartCookie?.value) {\n return null;\n }\n\n try {\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n return JSON.parse(cartCookie.value) as Cart;\n } catch (error) {\n console.warn(\"Failed to parse cart cookie:\", error);\n await clearCartCookie(cookieName);\n return null;\n }\n}\n\n/**\n * Clear cart cookie\n */\nexport async function clearCartCookie(cookieName: string) {\n const cookieStore = await cookies();\n cookieStore.delete(cookieName);\n}\n\n/**\n * Update cart in cookie atomically (load-transform-save pattern)\n */\nexport async function updateCartInCookie(\n cartId: string,\n cookieName: string,\n updater: (cart: Cart) => Cart,\n): Promise<Cart | null> {\n const existingCart = await loadCartFromCookie(cookieName);\n\n if (!existingCart || existingCart.id !== cartId) {\n return null;\n }\n\n const updatedCart = recalculateCartCost(updater(existingCart));\n\n await saveCartToCookie(updatedCart, cookieName);\n\n return updatedCart;\n}\n\n/**\n * Create a new cart with persistence\n */\nexport async function createCartWithPersistence(\n options: CreateCartOptions,\n): Promise<Cart | null> {\n const cartId = options.cartIdGenerator();\n\n const cart: Cart = {\n id: cartId,\n lines: [],\n cost: {\n subtotalAmount: 0,\n totalAmount: 0,\n currencyCode: \"USD\",\n },\n checkoutUrl: \"/checkout\",\n };\n\n for (const line of options.lines ?? []) {\n cart.lines.push(\n convertCartLinePayloadToCartLine(line, options.lineIdGenerator),\n );\n }\n\n const cartWithCost = recalculateCartCost(cart);\n await saveCartToCookie(cartWithCost, options.cookieName);\n return cartWithCost;\n}\n\n/**\n * Add lines to cart with configurable line merging strategy\n */\nexport async function addToCartWithPersistence(\n payload: AddToCartPayload,\n options: AddToCartOptions,\n): Promise<Cart | null> {\n return await updateCartInCookie(\n payload.cartId,\n options.cookieName,\n (cart) => {\n for (const linePayload of payload.lines) {\n const existingLineIndex = options.mergeFn(cart.lines, linePayload);\n\n if (existingLineIndex >= 0) {\n cart.lines[existingLineIndex]!.quantity += linePayload.quantity;\n } else {\n const newLine: CartLine = convertCartLinePayloadToCartLine(\n linePayload,\n options.lineIdGenerator,\n );\n cart.lines.push(newLine);\n }\n }\n\n return cart;\n },\n );\n}\n\n/**\n * Update cart line item\n */\nexport async function updateCartLineItemWithPersistence(\n payload: UpdateCartLineItemPayload,\n cookieName: string,\n): Promise<Cart | null> {\n return await updateCartInCookie(payload.cartId, cookieName, (cart) => {\n const lineIndex = cart.lines.findIndex(\n (line) => line.id === payload.line.id,\n );\n\n if (lineIndex >= 0) {\n if (payload.line.quantity <= 0) {\n cart.lines.splice(lineIndex, 1);\n } else {\n cart.lines[lineIndex]!.quantity = payload.line.quantity;\n if (payload.line.properties) {\n cart.lines[lineIndex]!.attributes = payload.line.properties;\n }\n if (payload.line.merchandise) {\n cart.lines[lineIndex]!.merchandise = payload.line.merchandise;\n }\n }\n }\n\n return cart;\n });\n}\n\n/**\n * Remove cart line items\n */\nexport async function removeCartLineItemsWithPersistence(\n payload: RemoveFromCartPayload,\n cookieName: string,\n): Promise<Cart | null> {\n return await updateCartInCookie(payload.cartId, cookieName, (cart) => {\n const removeSet = new Set(payload.lineIds);\n cart.lines = cart.lines.filter((line) => !removeSet.has(line.id));\n return cart;\n });\n}\n\n/**\n * Convert CartLinePayload to CartLine with custom ID generator\n */\nfunction convertCartLinePayloadToCartLine(\n linePayload: CartLinePayload,\n lineIdGenerator: () => string,\n): CartLine {\n // Cookie-persisted carts (Stripe/default) are their own source of truth \u2014\n // there's no server roundtrip to backfill merchandise later. Fall back to a\n // placeholder when the caller didn't pass merchandise so the persisted line\n // is renderable; otherwise an unresolvable line would render as a skeleton\n // forever. Shopify carts hit a different code path and use the skeleton\n // treatment in cart-provider.tsx.\n const fallbackMerchandise = {\n id: linePayload.id,\n product: {\n id: linePayload.merchandise?.product.id ?? linePayload.id,\n title: linePayload.merchandise?.product.title ?? \"Product\",\n },\n title: linePayload.merchandise?.title ?? \"Product Variant\",\n price: linePayload.merchandise?.price ?? 0,\n compareAtPrice: linePayload.merchandise?.compareAtPrice ?? null,\n image: linePayload.merchandise?.image\n ? {\n url: linePayload.merchandise.image.url,\n altText: linePayload.merchandise.image.altText,\n }\n : null,\n selectedOptions: linePayload.merchandise?.selectedOptions ?? [],\n };\n\n return {\n id: lineIdGenerator(),\n quantity: linePayload.quantity,\n merchandise: linePayload.merchandise ?? fallbackMerchandise,\n attributes: linePayload.properties ?? [],\n sellingPlanAllocation: linePayload.sellingPlanId\n ? {\n sellingPlan: {\n id: linePayload.sellingPlanId,\n name: \"Subscription Plan\",\n description: null,\n },\n priceAdjustments: [],\n checkoutChargeAmount: { amount: 0, currencyCode: \"USD\" },\n remainingBalanceChargeAmount: { amount: 0, currencyCode: \"USD\" },\n }\n : null,\n };\n}\n"],
|
|
5
|
+
"mappings": ";AAWA,SAAS,eAAe;AAExB,SAAS,kCAAkC;AAE3C,MAAM,sBAAsB,KAAK,KAAK,KAAK;AAO3C,SAAS,oBAAoB,MAAkB;AAC7C,QAAM,WAAW,2BAA2B,KAAK,KAAK;AACtD,SAAO;AAAA,IACL,GAAG;AAAA,IACH,MAAM;AAAA,MACJ,GAAG,KAAK;AAAA,MACR,gBAAgB;AAAA,MAChB,aAAa;AAAA,IACf;AAAA,EACF;AACF;AAgCA,eAAsB,iBAAiB,MAAY,YAAoB;AACrE,QAAM,cAAc,MAAM,QAAQ;AAClC,cAAY,IAAI,YAAY,KAAK,UAAU,IAAI,GAAG;AAAA,IAChD,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,QAAQ,QAAQ,IAAI,aAAa;AAAA,IACjC,UAAU;AAAA,IACV,MAAM;AAAA,EACR,CAAC;AACH;AAKA,eAAsB,mBACpB,YACsB;AACtB,QAAM,cAAc,MAAM,QAAQ;AAClC,QAAM,aAAa,YAAY,IAAI,UAAU;AAE7C,MAAI,CAAC,YAAY,OAAO;AACtB,WAAO;AAAA,EACT;AAEA,MAAI;AAGF,WAAO,KAAK,MAAM,WAAW,KAAK;AAAA,EACpC,SAAS,OAAO;AACd,YAAQ,KAAK,gCAAgC,KAAK;AAClD,UAAM,gBAAgB,UAAU;AAChC,WAAO;AAAA,EACT;AACF;AAKA,eAAsB,gBAAgB,YAAoB;AACxD,QAAM,cAAc,MAAM,QAAQ;AAClC,cAAY,OAAO,UAAU;AAC/B;AAKA,eAAsB,mBACpB,QACA,YACA,SACsB;AACtB,QAAM,eAAe,MAAM,mBAAmB,UAAU;A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YAAY,eAAe;AAAA,IACxC,YAAY,YAAY,cAAc,CAAC;AAAA,IACvC,uBAAuB,YAAY,gBAC/B;AAAA,MACE,aAAa;AAAA,QACX,IAAI,YAAY;AAAA,QAChB,MAAM;AAAA,QACN,aAAa;AAAA,MACf;AAAA,MACA,kBAAkB,CAAC;AAAA,MACnB,sBAAsB,EAAE,QAAQ,GAAG,cAAc,MAAM;AAAA,MACvD,8BAA8B,EAAE,QAAQ,GAAG,cAAc,MAAM;AAAA,IACjE,IACA;AAAA,EACN;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { yotpoProductReviewAggregateLoaderOutputSchema } from "../_vendor/schemas/agentTools/customIntegrations/loaders/yotpo";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
type YotpoReviewAggregateData = z.infer<typeof yotpoProductReviewAggregateLoaderOutputSchema>;
|
|
5
|
+
type YotpoReviewAggregateLoaderProps = {
|
|
6
|
+
loaderKey: string;
|
|
7
|
+
productId: string;
|
|
8
|
+
children: (data: YotpoReviewAggregateData) => ReactNode;
|
|
9
|
+
fallback?: ReactNode;
|
|
10
|
+
};
|
|
11
|
+
export declare function YotpoReviewAggregateLoader({ loaderKey, productId, children, fallback, }: YotpoReviewAggregateLoaderProps): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Suspense } from "react";
|
|
4
|
+
import { useSuspenseQuery } from "@tanstack/react-query";
|
|
5
|
+
import { yotpoProductReviewAggregateLoaderOutputSchema } from "../_vendor/schemas/agentTools/customIntegrations/loaders/yotpo.mjs";
|
|
6
|
+
import { invokeLoader } from "./invoke-loader";
|
|
7
|
+
import { LoaderErrorBoundary } from "./loader-error-boundary";
|
|
8
|
+
function YotpoReviewAggregateLoaderInner({
|
|
9
|
+
loaderKey,
|
|
10
|
+
productId,
|
|
11
|
+
children
|
|
12
|
+
}) {
|
|
13
|
+
const queryResult = useSuspenseQuery({
|
|
14
|
+
queryKey: [loaderKey, { productId }],
|
|
15
|
+
queryFn: async () => {
|
|
16
|
+
const loadedData = await invokeLoader({
|
|
17
|
+
loaderKey,
|
|
18
|
+
args: { productId }
|
|
19
|
+
});
|
|
20
|
+
return yotpoProductReviewAggregateLoaderOutputSchema.parse(loadedData);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return /* @__PURE__ */ jsx(Fragment, { children: children(queryResult.data) });
|
|
24
|
+
}
|
|
25
|
+
function YotpoReviewAggregateLoader({
|
|
26
|
+
loaderKey,
|
|
27
|
+
productId,
|
|
28
|
+
children,
|
|
29
|
+
fallback
|
|
30
|
+
}) {
|
|
31
|
+
return /* @__PURE__ */ jsx(
|
|
32
|
+
LoaderErrorBoundary,
|
|
33
|
+
{
|
|
34
|
+
fallback: fallback ?? null,
|
|
35
|
+
resetKey: `${loaderKey}:${productId}`,
|
|
36
|
+
children: /* @__PURE__ */ jsx(Suspense, { fallback: fallback ?? null, children: /* @__PURE__ */ jsx(
|
|
37
|
+
YotpoReviewAggregateLoaderInner,
|
|
38
|
+
{
|
|
39
|
+
loaderKey,
|
|
40
|
+
productId,
|
|
41
|
+
children
|
|
42
|
+
}
|
|
43
|
+
) })
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
YotpoReviewAggregateLoader
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=yotpo-review-aggregate-loader.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../loaders/yotpo-review-aggregate-loader.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\";\n\nimport type { ReactNode } from \"react\";\n\nimport { Suspense } from \"react\";\n\nimport { useSuspenseQuery } from \"@tanstack/react-query\";\nimport { yotpoProductReviewAggregateLoaderOutputSchema } from \"schemas/agentTools/customIntegrations/loaders/yotpo\";\nimport { z } from \"zod\";\n\nimport { invokeLoader } from \"./invoke-loader\";\nimport { LoaderErrorBoundary } from \"./loader-error-boundary\";\n\ntype YotpoReviewAggregateData = z.infer<\n typeof yotpoProductReviewAggregateLoaderOutputSchema\n>;\n\ntype YotpoReviewAggregateLoaderProps = {\n loaderKey: string;\n productId: string;\n children: (data: YotpoReviewAggregateData) => ReactNode;\n fallback?: ReactNode;\n};\n\nfunction YotpoReviewAggregateLoaderInner({\n loaderKey,\n productId,\n children,\n}: Omit<YotpoReviewAggregateLoaderProps, \"fallback\">) {\n const queryResult = useSuspenseQuery({\n queryKey: [loaderKey, { productId }],\n queryFn: async () => {\n const loadedData = await invokeLoader({\n loaderKey,\n args: { productId },\n });\n return yotpoProductReviewAggregateLoaderOutputSchema.parse(loadedData);\n },\n });\n\n return <>{children(queryResult.data)}</>;\n}\n\nexport function YotpoReviewAggregateLoader({\n loaderKey,\n productId,\n children,\n fallback,\n}: YotpoReviewAggregateLoaderProps) {\n return (\n <LoaderErrorBoundary\n fallback={fallback ?? null}\n resetKey={`${loaderKey}:${productId}`}\n >\n <Suspense fallback={fallback ?? null}>\n <YotpoReviewAggregateLoaderInner\n loaderKey={loaderKey}\n productId={productId}\n >\n {children}\n </YotpoReviewAggregateLoaderInner>\n </Suspense>\n </LoaderErrorBoundary>\n );\n}\n"],
|
|
5
|
+
"mappings": ";AAwCS;AApCT,SAAS,gBAAgB;AAEzB,SAAS,wBAAwB;AACjC,SAAS,qDAAqD;AAG9D,SAAS,oBAAoB;AAC7B,SAAS,2BAA2B;AAapC,SAAS,gCAAgC;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AACF,GAAsD;AACpD,QAAM,cAAc,iBAAiB;AAAA,IACnC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC;AAAA,IACnC,SAAS,YAAY;AACnB,YAAM,aAAa,MAAM,aAAa;AAAA,QACpC;AAAA,QACA,MAAM,EAAE,UAAU;AAAA,MACpB,CAAC;AACD,aAAO,8CAA8C,MAAM,UAAU;AAAA,IACvE;AAAA,EACF,CAAC;AAED,SAAO,gCAAG,mBAAS,YAAY,IAAI,GAAE;AACvC;AAEO,SAAS,2BAA2B;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAoC;AAClC,SACE;AAAA,IAAC;AAAA;AAAA,MACC,UAAU,YAAY;AAAA,MACtB,UAAU,GAAG,SAAS,IAAI,SAAS;AAAA,MAEnC,8BAAC,YAAS,UAAU,YAAY,MAC9B;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA;AAAA,UAEC;AAAA;AAAA,MACH,GACF;AAAA;AAAA,EACF;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { yotpoProductReviewsLoaderOutputSchema } from "../_vendor/schemas/agentTools/customIntegrations/loaders/yotpo";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
type YotpoReviewsData = z.infer<typeof yotpoProductReviewsLoaderOutputSchema>;
|
|
5
|
+
type YotpoReviewsLoaderProps = {
|
|
6
|
+
loaderKey: string;
|
|
7
|
+
productId: string;
|
|
8
|
+
perPage?: number;
|
|
9
|
+
page?: number;
|
|
10
|
+
children: (data: YotpoReviewsData) => ReactNode;
|
|
11
|
+
fallback?: ReactNode;
|
|
12
|
+
};
|
|
13
|
+
export declare function YotpoReviewsLoader({ loaderKey, productId, perPage, page, children, fallback, }: YotpoReviewsLoaderProps): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Suspense } from "react";
|
|
4
|
+
import { useSuspenseQuery } from "@tanstack/react-query";
|
|
5
|
+
import { yotpoProductReviewsLoaderOutputSchema } from "../_vendor/schemas/agentTools/customIntegrations/loaders/yotpo.mjs";
|
|
6
|
+
import { invokeLoader } from "./invoke-loader";
|
|
7
|
+
import { LoaderErrorBoundary } from "./loader-error-boundary";
|
|
8
|
+
function buildReviewsArgs({
|
|
9
|
+
productId,
|
|
10
|
+
perPage,
|
|
11
|
+
page
|
|
12
|
+
}) {
|
|
13
|
+
return {
|
|
14
|
+
productId,
|
|
15
|
+
...perPage !== void 0 ? { perPage } : {},
|
|
16
|
+
...page !== void 0 ? { page } : {}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function YotpoReviewsLoaderInner({
|
|
20
|
+
loaderKey,
|
|
21
|
+
productId,
|
|
22
|
+
perPage,
|
|
23
|
+
page,
|
|
24
|
+
children
|
|
25
|
+
}) {
|
|
26
|
+
const args = buildReviewsArgs({ productId, perPage, page });
|
|
27
|
+
const queryResult = useSuspenseQuery({
|
|
28
|
+
queryKey: [loaderKey, args],
|
|
29
|
+
queryFn: async () => {
|
|
30
|
+
const loadedData = await invokeLoader({ loaderKey, args });
|
|
31
|
+
return yotpoProductReviewsLoaderOutputSchema.parse(loadedData);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return /* @__PURE__ */ jsx(Fragment, { children: children(queryResult.data) });
|
|
35
|
+
}
|
|
36
|
+
function YotpoReviewsLoader({
|
|
37
|
+
loaderKey,
|
|
38
|
+
productId,
|
|
39
|
+
perPage,
|
|
40
|
+
page,
|
|
41
|
+
children,
|
|
42
|
+
fallback
|
|
43
|
+
}) {
|
|
44
|
+
return /* @__PURE__ */ jsx(
|
|
45
|
+
LoaderErrorBoundary,
|
|
46
|
+
{
|
|
47
|
+
fallback: fallback ?? null,
|
|
48
|
+
resetKey: `${loaderKey}:${productId}:${perPage ?? ""}:${page ?? ""}`,
|
|
49
|
+
children: /* @__PURE__ */ jsx(Suspense, { fallback: fallback ?? null, children: /* @__PURE__ */ jsx(
|
|
50
|
+
YotpoReviewsLoaderInner,
|
|
51
|
+
{
|
|
52
|
+
loaderKey,
|
|
53
|
+
productId,
|
|
54
|
+
perPage,
|
|
55
|
+
page,
|
|
56
|
+
children
|
|
57
|
+
}
|
|
58
|
+
) })
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
export {
|
|
63
|
+
YotpoReviewsLoader
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=yotpo-reviews-loader.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../loaders/yotpo-reviews-loader.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\";\n\nimport type { ReactNode } from \"react\";\n\nimport { Suspense } from \"react\";\n\nimport { useSuspenseQuery } from \"@tanstack/react-query\";\nimport { yotpoProductReviewsLoaderOutputSchema } from \"schemas/agentTools/customIntegrations/loaders/yotpo\";\nimport { z } from \"zod\";\n\nimport { invokeLoader } from \"./invoke-loader\";\nimport { LoaderErrorBoundary } from \"./loader-error-boundary\";\n\ntype YotpoReviewsData = z.infer<typeof yotpoProductReviewsLoaderOutputSchema>;\n\ntype YotpoReviewsLoaderProps = {\n loaderKey: string;\n productId: string;\n perPage?: number;\n page?: number;\n children: (data: YotpoReviewsData) => ReactNode;\n fallback?: ReactNode;\n};\n\n// NOTE (Noah, 2026-07-21): Only forward pagination args when set so the queryKey\n// and prefetch args match (a prefetch that omits page/perPage must hydrate a\n// component that also omits them). React Query keys are structural, so undefined\n// entries would break the prefetch \u2192 client cache handoff.\nfunction buildReviewsArgs({\n productId,\n perPage,\n page,\n}: {\n productId: string;\n perPage?: number;\n page?: number;\n}) {\n return {\n productId,\n ...(perPage !== undefined ? { perPage } : {}),\n ...(page !== undefined ? { page } : {}),\n };\n}\n\nfunction YotpoReviewsLoaderInner({\n loaderKey,\n productId,\n perPage,\n page,\n children,\n}: Omit<YotpoReviewsLoaderProps, \"fallback\">) {\n const args = buildReviewsArgs({ productId, perPage, page });\n const queryResult = useSuspenseQuery({\n queryKey: [loaderKey, args],\n queryFn: async () => {\n const loadedData = await invokeLoader({ loaderKey, args });\n return yotpoProductReviewsLoaderOutputSchema.parse(loadedData);\n },\n });\n\n return <>{children(queryResult.data)}</>;\n}\n\nexport function YotpoReviewsLoader({\n loaderKey,\n productId,\n perPage,\n page,\n children,\n fallback,\n}: YotpoReviewsLoaderProps) {\n return (\n <LoaderErrorBoundary\n fallback={fallback ?? null}\n resetKey={`${loaderKey}:${productId}:${perPage ?? \"\"}:${page ?? \"\"}`}\n >\n <Suspense fallback={fallback ?? null}>\n <YotpoReviewsLoaderInner\n loaderKey={loaderKey}\n productId={productId}\n perPage={perPage}\n page={page}\n >\n {children}\n </YotpoReviewsLoaderInner>\n </Suspense>\n </LoaderErrorBoundary>\n );\n}\n"],
|
|
5
|
+
"mappings": ";AA4DS;AAxDT,SAAS,gBAAgB;AAEzB,SAAS,wBAAwB;AACjC,SAAS,6CAA6C;AAGtD,SAAS,oBAAoB;AAC7B,SAAS,2BAA2B;AAiBpC,SAAS,iBAAiB;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AACF,GAIG;AACD,SAAO;AAAA,IACL;AAAA,IACA,GAAI,YAAY,SAAY,EAAE,QAAQ,IAAI,CAAC;AAAA,IAC3C,GAAI,SAAS,SAAY,EAAE,KAAK,IAAI,CAAC;AAAA,EACvC;AACF;AAEA,SAAS,wBAAwB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA8C;AAC5C,QAAM,OAAO,iBAAiB,EAAE,WAAW,SAAS,KAAK,CAAC;AAC1D,QAAM,cAAc,iBAAiB;AAAA,IACnC,UAAU,CAAC,WAAW,IAAI;AAAA,IAC1B,SAAS,YAAY;AACnB,YAAM,aAAa,MAAM,aAAa,EAAE,WAAW,KAAK,CAAC;AACzD,aAAO,sCAAsC,MAAM,UAAU;AAAA,IAC/D;AAAA,EACF,CAAC;AAED,SAAO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