@replohq/canopy-sdk 0.1.0
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/replo-utils/lib/errors.d.ts +83 -0
- package/_vendor/replo-utils/lib/json.d.ts +6 -0
- package/_vendor/replo-utils/lib/misc.d.ts +128 -0
- package/_vendor/replo-utils/lib/misc.mjs +1 -0
- package/_vendor/replo-utils/lib/object.d.ts +31 -0
- package/_vendor/replo-utils/lib/parse.d.ts +15 -0
- package/_vendor/schemas/agentTools/customIntegrations/loaders/levanta.d.ts +49 -0
- package/_vendor/schemas/agentTools/customIntegrations/loaders/levanta.mjs +36 -0
- package/_vendor/schemas/agentTools/customIntegrations/loaders/product.d.ts +334 -0
- package/_vendor/schemas/agentTools/customIntegrations/loaders/product.mjs +50 -0
- package/_vendor/schemas/cart.d.ts +198 -0
- package/_vendor/schemas/cart.mjs +83 -0
- package/_vendor/schemas/errors.d.ts +428 -0
- package/_vendor/schemas/errors.mjs +955 -0
- package/_vendor/schemas/generated/errors.d.ts +61 -0
- package/_vendor/schemas/generated/selectMode.d.ts +95 -0
- package/_vendor/schemas/generated/selectMode.mjs +1 -0
- package/_vendor/schemas/loaderKeys.d.ts +39 -0
- package/_vendor/schemas/loaderKeys.mjs +23 -0
- package/_vendor/schemas/objectType.d.ts +895 -0
- package/_vendor/schemas/objectType.mjs +2 -0
- package/_vendor/schemas/registry.d.ts +243 -0
- package/_vendor/schemas/sandboxFiles.d.ts +35 -0
- package/_vendor/schemas/selectMode.d.ts +507 -0
- package/_vendor/schemas/selectMode.mjs +194 -0
- package/_vendor/schemas/sellingPlan.d.ts +60 -0
- package/_vendor/schemas/sellingPlan.mjs +1 -0
- package/analytics/analytics-provider.d.ts +13 -0
- package/analytics/analytics-provider.js +104 -0
- package/analytics/analytics-provider.js.map +7 -0
- package/analytics/analytics-sink.d.ts +20 -0
- package/analytics/analytics-sink.js +1 -0
- package/analytics/analytics-sink.js.map +7 -0
- package/analytics/hooks/use-product-viewed-analytics.d.ts +23 -0
- package/analytics/hooks/use-product-viewed-analytics.js +34 -0
- package/analytics/hooks/use-product-viewed-analytics.js.map +7 -0
- package/analytics/sinks/ga4-sink.d.ts +15 -0
- package/analytics/sinks/ga4-sink.js +52 -0
- package/analytics/sinks/ga4-sink.js.map +7 -0
- package/analytics/sinks/meta-sink.d.ts +14 -0
- package/analytics/sinks/meta-sink.js +44 -0
- package/analytics/sinks/meta-sink.js.map +7 -0
- package/analytics/sinks/pinterest-sink.d.ts +14 -0
- package/analytics/sinks/pinterest-sink.js +76 -0
- package/analytics/sinks/pinterest-sink.js.map +7 -0
- package/analytics/sinks/reddit-sink.d.ts +14 -0
- package/analytics/sinks/reddit-sink.js +80 -0
- package/analytics/sinks/reddit-sink.js.map +7 -0
- package/analytics/sinks/replo-sink.d.ts +14 -0
- package/analytics/sinks/replo-sink.js +57 -0
- package/analytics/sinks/replo-sink.js.map +7 -0
- package/analytics/sinks/snapchat-sink.d.ts +14 -0
- package/analytics/sinks/snapchat-sink.js +67 -0
- package/analytics/sinks/snapchat-sink.js.map +7 -0
- package/analytics/sinks/tiktok-sink.d.ts +14 -0
- package/analytics/sinks/tiktok-sink.js +79 -0
- package/analytics/sinks/tiktok-sink.js.map +7 -0
- package/analytics/sinks/window-sink.d.ts +18 -0
- package/analytics/sinks/window-sink.js +46 -0
- package/analytics/sinks/window-sink.js.map +7 -0
- package/analytics/utils/analytics-utils.d.ts +7 -0
- package/analytics/utils/analytics-utils.js +130 -0
- package/analytics/utils/analytics-utils.js.map +7 -0
- package/analytics/utils/navigation-tracker.d.ts +16 -0
- package/analytics/utils/navigation-tracker.js +44 -0
- package/analytics/utils/navigation-tracker.js.map +7 -0
- package/cart/buy-now-action.d.ts +21 -0
- package/cart/buy-now-action.js +104 -0
- package/cart/buy-now-action.js.map +7 -0
- package/cart/cart-actions.d.ts +63 -0
- package/cart/cart-actions.js +90 -0
- package/cart/cart-actions.js.map +7 -0
- package/cart/cart-loader.d.ts +9 -0
- package/cart/cart-loader.js +11 -0
- package/cart/cart-loader.js.map +7 -0
- package/cart/cart-provider.d.ts +85 -0
- package/cart/cart-provider.js +358 -0
- package/cart/cart-provider.js.map +7 -0
- package/cart/cart-types.d.ts +154 -0
- package/cart/cart-types.js +16 -0
- package/cart/cart-types.js.map +7 -0
- package/cart/gateways/cart-gateway.d.ts +10 -0
- package/cart/gateways/cart-gateway.js +19 -0
- package/cart/gateways/cart-gateway.js.map +7 -0
- package/cart/gateways/cookie-cart-gateway.d.ts +28 -0
- package/cart/gateways/cookie-cart-gateway.js +109 -0
- package/cart/gateways/cookie-cart-gateway.js.map +7 -0
- package/cart/gateways/default-cart-gateway.d.ts +19 -0
- package/cart/gateways/default-cart-gateway.js +30 -0
- package/cart/gateways/default-cart-gateway.js.map +7 -0
- package/cart/gateways/resolver-cart-gateway.d.ts +2 -0
- package/cart/gateways/resolver-cart-gateway.js +106 -0
- package/cart/gateways/resolver-cart-gateway.js.map +7 -0
- package/cart/gateways/stripe-cart-gateway.d.ts +19 -0
- package/cart/gateways/stripe-cart-gateway.js +28 -0
- package/cart/gateways/stripe-cart-gateway.js.map +7 -0
- package/cart/gateways/stripe-constants.d.ts +1 -0
- package/cart/gateways/stripe-constants.js +5 -0
- package/cart/gateways/stripe-constants.js.map +7 -0
- package/cart/hooks/use-add-to-cart.d.ts +63 -0
- package/cart/hooks/use-add-to-cart.js +120 -0
- package/cart/hooks/use-add-to-cart.js.map +7 -0
- package/cart/hooks/use-buy-now.d.ts +49 -0
- package/cart/hooks/use-buy-now.js +62 -0
- package/cart/hooks/use-buy-now.js.map +7 -0
- package/cart/utils/cart-utils.d.ts +31 -0
- package/cart/utils/cart-utils.js +48 -0
- package/cart/utils/cart-utils.js.map +7 -0
- package/cart/utils/cookie-cart-persistence.d.ts +55 -0
- package/cart/utils/cookie-cart-persistence.js +153 -0
- package/cart/utils/cookie-cart-persistence.js.map +7 -0
- package/cart/utils/variant-to-cart-line.d.ts +124 -0
- package/cart/utils/variant-to-cart-line.js +202 -0
- package/cart/utils/variant-to-cart-line.js.map +7 -0
- package/chunk-46YU2W6T.mjs +538 -0
- package/chunk-4TZVNC3W.mjs +33 -0
- package/chunk-INHK6MYI.mjs +1598 -0
- package/editor/ClientErrorBoundary.d.ts +7 -0
- package/editor/ClientErrorBoundary.js +48 -0
- package/editor/ClientErrorBoundary.js.map +7 -0
- package/editor/LinkInterceptor.d.ts +1 -0
- package/editor/LinkInterceptor.js +124 -0
- package/editor/LinkInterceptor.js.map +7 -0
- package/editor/posthog-relay.d.ts +10 -0
- package/editor/posthog-relay.js +60 -0
- package/editor/posthog-relay.js.map +7 -0
- package/editor/select-mode/EditorSelection.d.ts +24 -0
- package/editor/select-mode/EditorSelection.js +34 -0
- package/editor/select-mode/EditorSelection.js.map +7 -0
- package/editor/select-mode/descriptor/elementDescriptor.d.ts +15 -0
- package/editor/select-mode/descriptor/elementDescriptor.js +213 -0
- package/editor/select-mode/descriptor/elementDescriptor.js.map +7 -0
- package/editor/select-mode/fiber.d.ts +52 -0
- package/editor/select-mode/fiber.js +269 -0
- package/editor/select-mode/fiber.js.map +7 -0
- package/editor/select-mode/hooks/useCrosshairCursor.d.ts +12 -0
- package/editor/select-mode/hooks/useCrosshairCursor.js +20 -0
- package/editor/select-mode/hooks/useCrosshairCursor.js.map +7 -0
- package/editor/select-mode/hooks/useParentMessaging.d.ts +24 -0
- package/editor/select-mode/hooks/useParentMessaging.js +33 -0
- package/editor/select-mode/hooks/useParentMessaging.js.map +7 -0
- package/editor/select-mode/hooks/useSelectModeController.d.ts +8 -0
- package/editor/select-mode/hooks/useSelectModeController.js +49 -0
- package/editor/select-mode/hooks/useSelectModeController.js.map +7 -0
- package/editor/select-mode/hooks/useSelectionHover.d.ts +22 -0
- package/editor/select-mode/hooks/useSelectionHover.js +98 -0
- package/editor/select-mode/hooks/useSelectionHover.js.map +7 -0
- package/editor/select-mode/hooks/useSelectionInteractions.d.ts +32 -0
- package/editor/select-mode/hooks/useSelectionInteractions.js +293 -0
- package/editor/select-mode/hooks/useSelectionInteractions.js.map +7 -0
- package/editor/select-mode/hooks/useSelectionScrollSync.d.ts +28 -0
- package/editor/select-mode/hooks/useSelectionScrollSync.js +77 -0
- package/editor/select-mode/hooks/useSelectionScrollSync.js.map +7 -0
- package/editor/select-mode/interactions/selectionGeometry.d.ts +80 -0
- package/editor/select-mode/interactions/selectionGeometry.js +160 -0
- package/editor/select-mode/interactions/selectionGeometry.js.map +7 -0
- package/editor/select-mode/selectModeSession.d.ts +21 -0
- package/editor/select-mode/selectModeSession.js +7 -0
- package/editor/select-mode/selectModeSession.js.map +7 -0
- package/editor/select-mode/selectionFrame.d.ts +48 -0
- package/editor/select-mode/selectionFrame.js +74 -0
- package/editor/select-mode/selectionFrame.js.map +7 -0
- package/editor/select-mode/symbolicate.d.ts +3 -0
- package/editor/select-mode/symbolicate.js +139 -0
- package/editor/select-mode/symbolicate.js.map +7 -0
- package/env.d.ts +13 -0
- package/env.js +20 -0
- package/env.js.map +7 -0
- package/gateways/canopy-api.d.ts +84 -0
- package/gateways/canopy-api.js +203 -0
- package/gateways/canopy-api.js.map +7 -0
- package/hooks/use-client-value.d.ts +10 -0
- package/hooks/use-client-value.js +12 -0
- package/hooks/use-client-value.js.map +7 -0
- package/hooks/use-formatted-price.d.ts +15 -0
- package/hooks/use-formatted-price.js +19 -0
- package/hooks/use-formatted-price.js.map +7 -0
- package/lib/get-query-client.d.ts +2 -0
- package/lib/get-query-client.js +34 -0
- package/lib/get-query-client.js.map +7 -0
- package/lib/integration-utils.d.ts +2 -0
- package/lib/integration-utils.js +9 -0
- package/lib/integration-utils.js.map +7 -0
- package/lib/shopify-utils.d.ts +16 -0
- package/lib/shopify-utils.js +11 -0
- package/lib/shopify-utils.js.map +7 -0
- package/lib/url-utils.d.ts +4 -0
- package/lib/url-utils.js +8 -0
- package/lib/url-utils.js.map +7 -0
- package/loaders/collection-loader.d.ts +11 -0
- package/loaders/collection-loader.js +53 -0
- package/loaders/collection-loader.js.map +7 -0
- package/loaders/collection-products-loader.d.ts +12 -0
- package/loaders/collection-products-loader.js +56 -0
- package/loaders/collection-products-loader.js.map +7 -0
- package/loaders/invoke-loader-action.d.ts +11 -0
- package/loaders/invoke-loader-action.js +14 -0
- package/loaders/invoke-loader-action.js.map +7 -0
- package/loaders/invoke-loader-server.d.ts +18 -0
- package/loaders/invoke-loader-server.js +35 -0
- package/loaders/invoke-loader-server.js.map +7 -0
- package/loaders/invoke-loader.d.ts +14 -0
- package/loaders/invoke-loader.js +36 -0
- package/loaders/invoke-loader.js.map +7 -0
- package/loaders/levanta-product-loader.d.ts +11 -0
- package/loaders/levanta-product-loader.js +53 -0
- package/loaders/levanta-product-loader.js.map +7 -0
- package/loaders/loader-error-boundary.d.ts +25 -0
- package/loaders/loader-error-boundary.js +24 -0
- package/loaders/loader-error-boundary.js.map +7 -0
- package/loaders/okendo-review-aggregate-loader.d.ts +17 -0
- package/loaders/okendo-review-aggregate-loader.js +56 -0
- package/loaders/okendo-review-aggregate-loader.js.map +7 -0
- package/loaders/okendo-reviews-loader.d.ts +23 -0
- package/loaders/okendo-reviews-loader.js +54 -0
- package/loaders/okendo-reviews-loader.js.map +7 -0
- package/loaders/prefetch-loaders.d.ts +33 -0
- package/loaders/prefetch-loaders.js +46 -0
- package/loaders/prefetch-loaders.js.map +7 -0
- package/loaders/product-loader.d.ts +11 -0
- package/loaders/product-loader.js +53 -0
- package/loaders/product-loader.js.map +7 -0
- package/loaders/rebuy-recommendations-loader.d.ts +159 -0
- package/loaders/rebuy-recommendations-loader.js +57 -0
- package/loaders/rebuy-recommendations-loader.js.map +7 -0
- package/loaders/smile-earning-rules-loader.d.ts +19 -0
- package/loaders/smile-earning-rules-loader.js +44 -0
- package/loaders/smile-earning-rules-loader.js.map +7 -0
- package/loaders/smile-rewards-loader.d.ts +19 -0
- package/loaders/smile-rewards-loader.js +44 -0
- package/loaders/smile-rewards-loader.js.map +7 -0
- package/loaders/smile-vip-tiers-loader.d.ts +18 -0
- package/loaders/smile-vip-tiers-loader.js +43 -0
- package/loaders/smile-vip-tiers-loader.js.map +7 -0
- package/package.json +29 -0
- package/providers/query-provider.d.ts +1 -0
- package/providers/query-provider.js +12 -0
- package/providers/query-provider.js.map +7 -0
- package/providers/replo-provider.d.ts +1 -0
- package/providers/replo-provider.js +20 -0
- package/providers/replo-provider.js.map +7 -0
|
@@ -0,0 +1,56 @@
|
|
|
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 { paginatedProductsSchema } from "../_vendor/schemas/agentTools/customIntegrations/loaders/product.mjs";
|
|
6
|
+
import { invokeLoader } from "./invoke-loader";
|
|
7
|
+
import { LoaderErrorBoundary } from "./loader-error-boundary";
|
|
8
|
+
function CollectionProductsLoaderInner({
|
|
9
|
+
loaderKey,
|
|
10
|
+
collectionGid,
|
|
11
|
+
first,
|
|
12
|
+
after,
|
|
13
|
+
children
|
|
14
|
+
}) {
|
|
15
|
+
const queryResult = useSuspenseQuery({
|
|
16
|
+
queryKey: [loaderKey, { collectionGid, first, after }],
|
|
17
|
+
queryFn: async () => {
|
|
18
|
+
const loadedData = await invokeLoader({
|
|
19
|
+
loaderKey,
|
|
20
|
+
args: { collectionGid, first, after }
|
|
21
|
+
});
|
|
22
|
+
return paginatedProductsSchema.parse(loadedData);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return /* @__PURE__ */ jsx(Fragment, { children: children(queryResult.data) });
|
|
26
|
+
}
|
|
27
|
+
function CollectionProductsLoader({
|
|
28
|
+
loaderKey,
|
|
29
|
+
collectionGid,
|
|
30
|
+
first,
|
|
31
|
+
after,
|
|
32
|
+
children,
|
|
33
|
+
fallback
|
|
34
|
+
}) {
|
|
35
|
+
return /* @__PURE__ */ jsx(
|
|
36
|
+
LoaderErrorBoundary,
|
|
37
|
+
{
|
|
38
|
+
fallback: fallback ?? null,
|
|
39
|
+
resetKey: `${loaderKey}:${collectionGid}:${first ?? ""}:${after ?? ""}`,
|
|
40
|
+
children: /* @__PURE__ */ jsx(Suspense, { fallback: fallback ?? null, children: /* @__PURE__ */ jsx(
|
|
41
|
+
CollectionProductsLoaderInner,
|
|
42
|
+
{
|
|
43
|
+
loaderKey,
|
|
44
|
+
collectionGid,
|
|
45
|
+
first,
|
|
46
|
+
after,
|
|
47
|
+
children
|
|
48
|
+
}
|
|
49
|
+
) })
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
CollectionProductsLoader
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=collection-products-loader.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../loaders/collection-products-loader.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\";\n\nimport type { ReactNode } from \"react\";\nimport type { PaginatedProducts } from \"schemas/agentTools/customIntegrations/loaders/product\";\n\nimport { Suspense } from \"react\";\n\nimport { useSuspenseQuery } from \"@tanstack/react-query\";\nimport { paginatedProductsSchema } from \"schemas/agentTools/customIntegrations/loaders/product\";\n\nimport { invokeLoader } from \"./invoke-loader\";\nimport { LoaderErrorBoundary } from \"./loader-error-boundary\";\n\ntype CollectionProductsLoaderProps = {\n loaderKey: string;\n collectionGid: string;\n first?: number;\n after?: string;\n children: (data: PaginatedProducts) => ReactNode;\n fallback?: ReactNode;\n};\n\nfunction CollectionProductsLoaderInner({\n loaderKey,\n collectionGid,\n first,\n after,\n children,\n}: Omit<CollectionProductsLoaderProps, \"fallback\">) {\n const queryResult = useSuspenseQuery({\n queryKey: [loaderKey, { collectionGid, first, after }],\n queryFn: async () => {\n const loadedData = await invokeLoader({\n loaderKey,\n args: { collectionGid, first, after },\n });\n return paginatedProductsSchema.parse(loadedData);\n },\n });\n\n return <>{children(queryResult.data)}</>;\n}\n\nexport function CollectionProductsLoader({\n loaderKey,\n collectionGid,\n first,\n after,\n children,\n fallback,\n}: CollectionProductsLoaderProps) {\n return (\n <LoaderErrorBoundary\n fallback={fallback ?? null}\n resetKey={`${loaderKey}:${collectionGid}:${first ?? \"\"}:${after ?? \"\"}`}\n >\n <Suspense fallback={fallback ?? null}>\n <CollectionProductsLoaderInner\n loaderKey={loaderKey}\n collectionGid={collectionGid}\n first={first}\n after={after}\n >\n {children}\n </CollectionProductsLoaderInner>\n </Suspense>\n </LoaderErrorBoundary>\n );\n}\n"],
|
|
5
|
+
"mappings": ";AAwCS;AAnCT,SAAS,gBAAgB;AAEzB,SAAS,wBAAwB;AACjC,SAAS,+BAA+B;AAExC,SAAS,oBAAoB;AAC7B,SAAS,2BAA2B;AAWpC,SAAS,8BAA8B;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAoD;AAClD,QAAM,cAAc,iBAAiB;AAAA,IACnC,UAAU,CAAC,WAAW,EAAE,eAAe,OAAO,MAAM,CAAC;AAAA,IACrD,SAAS,YAAY;AACnB,YAAM,aAAa,MAAM,aAAa;AAAA,QACpC;AAAA,QACA,MAAM,EAAE,eAAe,OAAO,MAAM;AAAA,MACtC,CAAC;AACD,aAAO,wBAAwB,MAAM,UAAU;AAAA,IACjD;AAAA,EACF,CAAC;AAED,SAAO,gCAAG,mBAAS,YAAY,IAAI,GAAE;AACvC;AAEO,SAAS,yBAAyB;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAkC;AAChC,SACE;AAAA,IAAC;AAAA;AAAA,MACC,UAAU,YAAY;AAAA,MACtB,UAAU,GAAG,SAAS,IAAI,aAAa,IAAI,SAAS,EAAE,IAAI,SAAS,EAAE;AAAA,MAErE,8BAAC,YAAS,UAAU,YAAY,MAC9B;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UAEC;AAAA;AAAA,MACH,GACF;AAAA;AAAA,EACF;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server action that invokes a data loader via the canopy-api gateway.
|
|
3
|
+
* Called from client-side loader components when React Query needs to
|
|
4
|
+
* fetch data in the browser (e.g., client-side navigation, cache miss).
|
|
5
|
+
* This runs on the server — Next.js handles the client/server boundary
|
|
6
|
+
* automatically.
|
|
7
|
+
*/
|
|
8
|
+
export declare function invokeLoaderAction({ loaderKey, args, }: {
|
|
9
|
+
loaderKey: string;
|
|
10
|
+
args: Record<string, unknown>;
|
|
11
|
+
}): Promise<unknown>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
import { getCanopyApiGateway } from "../gateways/canopy-api";
|
|
3
|
+
async function invokeLoaderAction({
|
|
4
|
+
loaderKey,
|
|
5
|
+
args
|
|
6
|
+
}) {
|
|
7
|
+
const gateway = await getCanopyApiGateway();
|
|
8
|
+
const response = await gateway.invokeLoader({ loaderKey, args });
|
|
9
|
+
return response.data;
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
invokeLoaderAction
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=invoke-loader-action.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../loaders/invoke-loader-action.ts"],
|
|
4
|
+
"sourcesContent": ["\"use server\";\n\nimport { getCanopyApiGateway } from \"../gateways/canopy-api\";\n\n/**\n * Server action that invokes a data loader via the canopy-api gateway.\n * Called from client-side loader components when React Query needs to\n * fetch data in the browser (e.g., client-side navigation, cache miss).\n * This runs on the server \u2014 Next.js handles the client/server boundary\n * automatically.\n */\nexport async function invokeLoaderAction({\n loaderKey,\n args,\n}: {\n loaderKey: string;\n args: Record<string, unknown>;\n}) {\n const gateway = await getCanopyApiGateway();\n const response = await gateway.invokeLoader({ loaderKey, args });\n return response.data;\n}\n"],
|
|
5
|
+
"mappings": ";AAEA,SAAS,2BAA2B;AASpC,eAAsB,mBAAmB;AAAA,EACvC;AAAA,EACA;AACF,GAGG;AACD,QAAM,UAAU,MAAM,oBAAoB;AAC1C,QAAM,WAAW,MAAM,QAAQ,aAAa,EAAE,WAAW,KAAK,CAAC;AAC/D,SAAO,SAAS;AAClB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-only loader invocation that calls the canopy-api gateway directly.
|
|
3
|
+
* Used by PrefetchedLoaders to seed the React Query cache during SSR.
|
|
4
|
+
*
|
|
5
|
+
* Results are cached via Next.js `unstable_cache` so repeated SSR renders
|
|
6
|
+
* for the same loader+args return instantly without a network round-trip
|
|
7
|
+
* to canopy-api. The canopy-api's own in-memory cache still acts as a second
|
|
8
|
+
* layer for cold starts and cross-instance sharing.
|
|
9
|
+
*
|
|
10
|
+
* @param revalidateSeconds - How long (in seconds) the cached result is
|
|
11
|
+
* considered fresh. Defaults to 60. Set to `false` to cache indefinitely
|
|
12
|
+
* (use tag-based invalidation via `revalidateTag` to purge).
|
|
13
|
+
*/
|
|
14
|
+
export declare function invokeLoaderServer({ loaderKey, args, revalidateSeconds, }: {
|
|
15
|
+
loaderKey: string;
|
|
16
|
+
args: Record<string, unknown>;
|
|
17
|
+
revalidateSeconds?: number | false;
|
|
18
|
+
}): Promise<unknown>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { unstable_cache } from "next/cache";
|
|
2
|
+
import { getCanopyApiGateway } from "../gateways/canopy-api";
|
|
3
|
+
const DEFAULT_REVALIDATE_SECONDS = 60;
|
|
4
|
+
function buildStableCacheKeyParts({
|
|
5
|
+
loaderKey,
|
|
6
|
+
args
|
|
7
|
+
}) {
|
|
8
|
+
const sortedArgsJson = JSON.stringify(
|
|
9
|
+
Object.entries(args).sort(([keyA], [keyB]) => keyA.localeCompare(keyB)).map(([key, value]) => [key, value])
|
|
10
|
+
);
|
|
11
|
+
return ["loader", loaderKey, sortedArgsJson];
|
|
12
|
+
}
|
|
13
|
+
async function invokeLoaderServer({
|
|
14
|
+
loaderKey,
|
|
15
|
+
args,
|
|
16
|
+
revalidateSeconds = DEFAULT_REVALIDATE_SECONDS
|
|
17
|
+
}) {
|
|
18
|
+
const cacheKeyParts = buildStableCacheKeyParts({ loaderKey, args });
|
|
19
|
+
return unstable_cache(
|
|
20
|
+
async () => {
|
|
21
|
+
const gateway = await getCanopyApiGateway();
|
|
22
|
+
const response = await gateway.invokeLoader({ loaderKey, args });
|
|
23
|
+
return response.data;
|
|
24
|
+
},
|
|
25
|
+
cacheKeyParts,
|
|
26
|
+
{
|
|
27
|
+
revalidate: revalidateSeconds,
|
|
28
|
+
tags: [`loader:${loaderKey}`, ...cacheKeyParts]
|
|
29
|
+
}
|
|
30
|
+
)();
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
invokeLoaderServer
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=invoke-loader-server.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../loaders/invoke-loader-server.ts"],
|
|
4
|
+
"sourcesContent": ["import { unstable_cache } from \"next/cache\";\n\nimport { getCanopyApiGateway } from \"../gateways/canopy-api\";\n\nconst DEFAULT_REVALIDATE_SECONDS = 60;\n\nfunction buildStableCacheKeyParts({\n loaderKey,\n args,\n}: {\n loaderKey: string;\n args: Record<string, unknown>;\n}): string[] {\n const sortedArgsJson = JSON.stringify(\n Object.entries(args)\n .sort(([keyA], [keyB]) => keyA.localeCompare(keyB))\n .map(([key, value]) => [key, value]),\n );\n return [\"loader\", loaderKey, sortedArgsJson];\n}\n\n/**\n * Server-only loader invocation that calls the canopy-api gateway directly.\n * Used by PrefetchedLoaders to seed the React Query cache during SSR.\n *\n * Results are cached via Next.js `unstable_cache` so repeated SSR renders\n * for the same loader+args return instantly without a network round-trip\n * to canopy-api. The canopy-api's own in-memory cache still acts as a second\n * layer for cold starts and cross-instance sharing.\n *\n * @param revalidateSeconds - How long (in seconds) the cached result is\n * considered fresh. Defaults to 60. Set to `false` to cache indefinitely\n * (use tag-based invalidation via `revalidateTag` to purge).\n */\nexport async function invokeLoaderServer({\n loaderKey,\n args,\n revalidateSeconds = DEFAULT_REVALIDATE_SECONDS,\n}: {\n loaderKey: string;\n args: Record<string, unknown>;\n revalidateSeconds?: number | false;\n}) {\n const cacheKeyParts = buildStableCacheKeyParts({ loaderKey, args });\n\n return unstable_cache(\n async () => {\n const gateway = await getCanopyApiGateway();\n const response = await gateway.invokeLoader({ loaderKey, args });\n return response.data;\n },\n cacheKeyParts,\n {\n revalidate: revalidateSeconds,\n tags: [`loader:${loaderKey}`, ...cacheKeyParts],\n },\n )();\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,sBAAsB;AAE/B,SAAS,2BAA2B;AAEpC,MAAM,6BAA6B;AAEnC,SAAS,yBAAyB;AAAA,EAChC;AAAA,EACA;AACF,GAGa;AACX,QAAM,iBAAiB,KAAK;AAAA,IAC1B,OAAO,QAAQ,IAAI,EAChB,KAAK,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,MAAM,KAAK,cAAc,IAAI,CAAC,EACjD,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,KAAK,KAAK,CAAC;AAAA,EACvC;AACA,SAAO,CAAC,UAAU,WAAW,cAAc;AAC7C;AAeA,eAAsB,mBAAmB;AAAA,EACvC;AAAA,EACA;AAAA,EACA,oBAAoB;AACtB,GAIG;AACD,QAAM,gBAAgB,yBAAyB,EAAE,WAAW,KAAK,CAAC;AAElE,SAAO;AAAA,IACL,YAAY;AACV,YAAM,UAAU,MAAM,oBAAoB;AAC1C,YAAM,WAAW,MAAM,QAAQ,aAAa,EAAE,WAAW,KAAK,CAAC;AAC/D,aAAO,SAAS;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,MACE,YAAY;AAAA,MACZ,MAAM,CAAC,UAAU,SAAS,IAAI,GAAG,aAAa;AAAA,IAChD;AAAA,EACF,EAAE;AACJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ReploError } from "../_vendor/schemas/errors";
|
|
2
|
+
/** Scoped error for loader invocation failures. */
|
|
3
|
+
export declare class LoaderInvokeError extends ReploError {
|
|
4
|
+
}
|
|
5
|
+
export declare function isLoaderInvokeError(error: unknown): error is LoaderInvokeError;
|
|
6
|
+
/**
|
|
7
|
+
* Invokes a data loader. During SSR, calls the canopy-api gateway directly.
|
|
8
|
+
* In the browser, dynamically imports a server action so React 19 never sees
|
|
9
|
+
* the "use server" reference during render.
|
|
10
|
+
*/
|
|
11
|
+
export declare function invokeLoader({ loaderKey, args, }: {
|
|
12
|
+
loaderKey: string;
|
|
13
|
+
args: Record<string, unknown>;
|
|
14
|
+
}): Promise<unknown>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ReploError } from "../_vendor/schemas/errors.mjs";
|
|
2
|
+
class LoaderInvokeError extends ReploError {
|
|
3
|
+
}
|
|
4
|
+
function isLoaderInvokeError(error) {
|
|
5
|
+
return error instanceof LoaderInvokeError;
|
|
6
|
+
}
|
|
7
|
+
async function invokeLoader({
|
|
8
|
+
loaderKey,
|
|
9
|
+
args
|
|
10
|
+
}) {
|
|
11
|
+
try {
|
|
12
|
+
if (typeof window === "undefined") {
|
|
13
|
+
const { getCanopyApiGateway } = await import("../gateways/canopy-api");
|
|
14
|
+
const gateway = await getCanopyApiGateway();
|
|
15
|
+
const response = await gateway.invokeLoader({ loaderKey, args });
|
|
16
|
+
return response.data;
|
|
17
|
+
}
|
|
18
|
+
const { invokeLoaderAction } = await import("./invoke-loader-action");
|
|
19
|
+
return await invokeLoaderAction({ loaderKey, args });
|
|
20
|
+
} catch (error) {
|
|
21
|
+
if (error instanceof LoaderInvokeError) {
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
throw new LoaderInvokeError({
|
|
25
|
+
message: `Loader ${loaderKey} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
26
|
+
cause: error,
|
|
27
|
+
additionalData: { loaderKey }
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
LoaderInvokeError,
|
|
33
|
+
invokeLoader,
|
|
34
|
+
isLoaderInvokeError
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=invoke-loader.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../loaders/invoke-loader.ts"],
|
|
4
|
+
"sourcesContent": ["import { ReploError } from \"schemas/errors\";\n\n/** Scoped error for loader invocation failures. */\nexport class LoaderInvokeError extends ReploError {}\n\nexport function isLoaderInvokeError(\n error: unknown,\n): error is LoaderInvokeError {\n return error instanceof LoaderInvokeError;\n}\n\n/**\n * Invokes a data loader. During SSR, calls the canopy-api gateway directly.\n * In the browser, dynamically imports a server action so React 19 never sees\n * the \"use server\" reference during render.\n */\nexport async function invokeLoader({\n loaderKey,\n args,\n}: {\n loaderKey: string;\n args: Record<string, unknown>;\n}) {\n try {\n if (typeof window === \"undefined\") {\n const { getCanopyApiGateway } = await import(\"../gateways/canopy-api\");\n const gateway = await getCanopyApiGateway();\n const response = await gateway.invokeLoader({ loaderKey, args });\n return response.data;\n }\n\n const { invokeLoaderAction } = await import(\"./invoke-loader-action\");\n return await invokeLoaderAction({ loaderKey, args });\n } catch (error) {\n if (error instanceof LoaderInvokeError) {\n throw error;\n }\n throw new LoaderInvokeError({\n message: `Loader ${loaderKey} failed: ${error instanceof Error ? error.message : String(error)}`,\n cause: error,\n additionalData: { loaderKey },\n });\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,kBAAkB;AAGpB,MAAM,0BAA0B,WAAW;AAAC;AAE5C,SAAS,oBACd,OAC4B;AAC5B,SAAO,iBAAiB;AAC1B;AAOA,eAAsB,aAAa;AAAA,EACjC;AAAA,EACA;AACF,GAGG;AACD,MAAI;AACF,QAAI,OAAO,WAAW,aAAa;AACjC,YAAM,EAAE,oBAAoB,IAAI,MAAM,OAAO,wBAAwB;AACrE,YAAM,UAAU,MAAM,oBAAoB;AAC1C,YAAM,WAAW,MAAM,QAAQ,aAAa,EAAE,WAAW,KAAK,CAAC;AAC/D,aAAO,SAAS;AAAA,IAClB;AAEA,UAAM,EAAE,mBAAmB,IAAI,MAAM,OAAO,wBAAwB;AACpE,WAAO,MAAM,mBAAmB,EAAE,WAAW,KAAK,CAAC;AAAA,EACrD,SAAS,OAAO;AACd,QAAI,iBAAiB,mBAAmB;AACtC,YAAM;AAAA,IACR;AACA,UAAM,IAAI,kBAAkB;AAAA,MAC1B,SAAS,UAAU,SAAS,YAAY,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,MAC9F,OAAO;AAAA,MACP,gBAAgB,EAAE,UAAU;AAAA,IAC9B,CAAC;AAAA,EACH;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { LevantaProductFull } from "../_vendor/schemas/agentTools/customIntegrations/loaders/levanta";
|
|
3
|
+
type LevantaProductLoaderProps = {
|
|
4
|
+
loaderKey: string;
|
|
5
|
+
asin: string;
|
|
6
|
+
marketplace?: string;
|
|
7
|
+
children: (data: LevantaProductFull) => ReactNode;
|
|
8
|
+
fallback?: ReactNode;
|
|
9
|
+
};
|
|
10
|
+
export declare function LevantaProductLoader({ loaderKey, asin, marketplace, children, fallback, }: LevantaProductLoaderProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
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 { levantaProductFullSchema } from "../_vendor/schemas/agentTools/customIntegrations/loaders/levanta.mjs";
|
|
6
|
+
import { invokeLoader } from "./invoke-loader";
|
|
7
|
+
import { LoaderErrorBoundary } from "./loader-error-boundary";
|
|
8
|
+
function LevantaProductLoaderInner({
|
|
9
|
+
loaderKey,
|
|
10
|
+
asin,
|
|
11
|
+
marketplace,
|
|
12
|
+
children
|
|
13
|
+
}) {
|
|
14
|
+
const queryResult = useSuspenseQuery({
|
|
15
|
+
queryKey: [loaderKey, { asin, marketplace }],
|
|
16
|
+
queryFn: async () => {
|
|
17
|
+
const loadedData = await invokeLoader({
|
|
18
|
+
loaderKey,
|
|
19
|
+
args: { asin, marketplace }
|
|
20
|
+
});
|
|
21
|
+
return levantaProductFullSchema.parse(loadedData);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return /* @__PURE__ */ jsx(Fragment, { children: children(queryResult.data) });
|
|
25
|
+
}
|
|
26
|
+
function LevantaProductLoader({
|
|
27
|
+
loaderKey,
|
|
28
|
+
asin,
|
|
29
|
+
marketplace,
|
|
30
|
+
children,
|
|
31
|
+
fallback
|
|
32
|
+
}) {
|
|
33
|
+
return /* @__PURE__ */ jsx(
|
|
34
|
+
LoaderErrorBoundary,
|
|
35
|
+
{
|
|
36
|
+
fallback: fallback ?? null,
|
|
37
|
+
resetKey: `${loaderKey}:${asin}:${marketplace ?? ""}`,
|
|
38
|
+
children: /* @__PURE__ */ jsx(Suspense, { fallback: fallback ?? null, children: /* @__PURE__ */ jsx(
|
|
39
|
+
LevantaProductLoaderInner,
|
|
40
|
+
{
|
|
41
|
+
loaderKey,
|
|
42
|
+
asin,
|
|
43
|
+
marketplace,
|
|
44
|
+
children
|
|
45
|
+
}
|
|
46
|
+
) })
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
LevantaProductLoader
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=levanta-product-loader.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../loaders/levanta-product-loader.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\";\n\nimport type { ReactNode } from \"react\";\nimport type { LevantaProductFull } from \"schemas/agentTools/customIntegrations/loaders/levanta\";\n\nimport { Suspense } from \"react\";\n\nimport { useSuspenseQuery } from \"@tanstack/react-query\";\nimport { levantaProductFullSchema } from \"schemas/agentTools/customIntegrations/loaders/levanta\";\n\nimport { invokeLoader } from \"./invoke-loader\";\nimport { LoaderErrorBoundary } from \"./loader-error-boundary\";\n\ntype LevantaProductLoaderProps = {\n loaderKey: string;\n asin: string;\n marketplace?: string;\n children: (data: LevantaProductFull) => ReactNode;\n fallback?: ReactNode;\n};\n\nfunction LevantaProductLoaderInner({\n loaderKey,\n asin,\n marketplace,\n children,\n}: Omit<LevantaProductLoaderProps, \"fallback\">) {\n const queryResult = useSuspenseQuery({\n queryKey: [loaderKey, { asin, marketplace }],\n queryFn: async () => {\n const loadedData = await invokeLoader({\n loaderKey,\n args: { asin, marketplace },\n });\n return levantaProductFullSchema.parse(loadedData);\n },\n });\n\n return <>{children(queryResult.data)}</>;\n}\n\nexport function LevantaProductLoader({\n loaderKey,\n asin,\n marketplace,\n children,\n fallback,\n}: LevantaProductLoaderProps) {\n return (\n <LoaderErrorBoundary\n fallback={fallback ?? null}\n resetKey={`${loaderKey}:${asin}:${marketplace ?? \"\"}`}\n >\n <Suspense fallback={fallback ?? null}>\n <LevantaProductLoaderInner\n loaderKey={loaderKey}\n asin={asin}\n marketplace={marketplace}\n >\n {children}\n </LevantaProductLoaderInner>\n </Suspense>\n </LoaderErrorBoundary>\n );\n}\n"],
|
|
5
|
+
"mappings": ";AAsCS;AAjCT,SAAS,gBAAgB;AAEzB,SAAS,wBAAwB;AACjC,SAAS,gCAAgC;AAEzC,SAAS,oBAAoB;AAC7B,SAAS,2BAA2B;AAUpC,SAAS,0BAA0B;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAgD;AAC9C,QAAM,cAAc,iBAAiB;AAAA,IACnC,UAAU,CAAC,WAAW,EAAE,MAAM,YAAY,CAAC;AAAA,IAC3C,SAAS,YAAY;AACnB,YAAM,aAAa,MAAM,aAAa;AAAA,QACpC;AAAA,QACA,MAAM,EAAE,MAAM,YAAY;AAAA,MAC5B,CAAC;AACD,aAAO,yBAAyB,MAAM,UAAU;AAAA,IAClD;AAAA,EACF,CAAC;AAED,SAAO,gCAAG,mBAAS,YAAY,IAAI,GAAE;AACvC;AAEO,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA8B;AAC5B,SACE;AAAA,IAAC;AAAA;AAAA,MACC,UAAU,YAAY;AAAA,MACtB,UAAU,GAAG,SAAS,IAAI,IAAI,IAAI,eAAe,EAAE;AAAA,MAEnD,8BAAC,YAAS,UAAU,YAAY,MAC9B;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA;AAAA,UAEC;AAAA;AAAA,MACH,GACF;AAAA;AAAA,EACF;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
interface LoaderErrorBoundaryState {
|
|
4
|
+
hasError: boolean;
|
|
5
|
+
resetKey: string;
|
|
6
|
+
}
|
|
7
|
+
type LoaderErrorBoundaryProps = React.PropsWithChildren<{
|
|
8
|
+
fallback: ReactNode;
|
|
9
|
+
resetKey: string;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* Error boundary for loader components that renders the fallback instead of
|
|
13
|
+
* crashing the page when a loader fails (e.g. product not published to the
|
|
14
|
+
* Online Store sales channel, deleted collection, etc.).
|
|
15
|
+
*
|
|
16
|
+
* When resetKey changes (e.g. navigating to a different product), the error
|
|
17
|
+
* state is cleared so the new loader gets a chance to render.
|
|
18
|
+
*/
|
|
19
|
+
export declare class LoaderErrorBoundary extends React.Component<LoaderErrorBoundaryProps, LoaderErrorBoundaryState> {
|
|
20
|
+
state: LoaderErrorBoundaryState;
|
|
21
|
+
static getDerivedStateFromError(): Partial<LoaderErrorBoundaryState>;
|
|
22
|
+
static getDerivedStateFromProps(props: LoaderErrorBoundaryProps, state: LoaderErrorBoundaryState): Partial<LoaderErrorBoundaryState> | null;
|
|
23
|
+
render(): ReactNode;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
class LoaderErrorBoundary extends React.Component {
|
|
4
|
+
state = { hasError: false, resetKey: "" };
|
|
5
|
+
static getDerivedStateFromError() {
|
|
6
|
+
return { hasError: true };
|
|
7
|
+
}
|
|
8
|
+
static getDerivedStateFromProps(props, state) {
|
|
9
|
+
if (props.resetKey !== state.resetKey) {
|
|
10
|
+
return { hasError: false, resetKey: props.resetKey };
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
render() {
|
|
15
|
+
if (this.state.hasError) {
|
|
16
|
+
return this.props.fallback;
|
|
17
|
+
}
|
|
18
|
+
return this.props.children;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
LoaderErrorBoundary
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=loader-error-boundary.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../loaders/loader-error-boundary.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\";\n\nimport type { ReactNode } from \"react\";\n\nimport * as React from \"react\";\n\ninterface LoaderErrorBoundaryState {\n hasError: boolean;\n resetKey: string;\n}\n\ntype LoaderErrorBoundaryProps = React.PropsWithChildren<{\n fallback: ReactNode;\n resetKey: string;\n}>;\n\n/**\n * Error boundary for loader components that renders the fallback instead of\n * crashing the page when a loader fails (e.g. product not published to the\n * Online Store sales channel, deleted collection, etc.).\n *\n * When resetKey changes (e.g. navigating to a different product), the error\n * state is cleared so the new loader gets a chance to render.\n */\nexport class LoaderErrorBoundary extends React.Component<\n LoaderErrorBoundaryProps,\n LoaderErrorBoundaryState\n> {\n state: LoaderErrorBoundaryState = { hasError: false, resetKey: \"\" };\n\n static getDerivedStateFromError(): Partial<LoaderErrorBoundaryState> {\n return { hasError: true };\n }\n\n static getDerivedStateFromProps(\n props: LoaderErrorBoundaryProps,\n state: LoaderErrorBoundaryState,\n ): Partial<LoaderErrorBoundaryState> | null {\n if (props.resetKey !== state.resetKey) {\n return { hasError: false, resetKey: props.resetKey };\n }\n return null;\n }\n\n render() {\n if (this.state.hasError) {\n return this.props.fallback;\n }\n return this.props.children;\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAIA,YAAY,WAAW;AAoBhB,MAAM,4BAA4B,MAAM,UAG7C;AAAA,EACA,QAAkC,EAAE,UAAU,OAAO,UAAU,GAAG;AAAA,EAElE,OAAO,2BAA8D;AACnE,WAAO,EAAE,UAAU,KAAK;AAAA,EAC1B;AAAA,EAEA,OAAO,yBACL,OACA,OAC0C;AAC1C,QAAI,MAAM,aAAa,MAAM,UAAU;AACrC,aAAO,EAAE,UAAU,OAAO,UAAU,MAAM,SAAS;AAAA,IACrD;AACA,WAAO;AAAA,EACT;AAAA,EAEA,SAAS;AACP,QAAI,KAAK,MAAM,UAAU;AACvB,aAAO,KAAK,MAAM;AAAA,IACpB;AACA,WAAO,KAAK,MAAM;AAAA,EACpB;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
declare const okendoReviewAggregateOutputSchema: z.ZodObject<{
|
|
4
|
+
reviewCount: z.ZodNumber;
|
|
5
|
+
reviewAverageValue: z.ZodNumber;
|
|
6
|
+
reviewStarDistribution: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
7
|
+
recommendedPercentage: z.ZodNumber;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
type OkendoReviewAggregateData = z.infer<typeof okendoReviewAggregateOutputSchema>;
|
|
10
|
+
type OkendoReviewAggregateLoaderProps = {
|
|
11
|
+
loaderKey: string;
|
|
12
|
+
shopifyProductId: string;
|
|
13
|
+
children: (data: OkendoReviewAggregateData) => ReactNode;
|
|
14
|
+
fallback?: ReactNode;
|
|
15
|
+
};
|
|
16
|
+
export declare function OkendoReviewAggregateLoader({ loaderKey, shopifyProductId, children, fallback, }: OkendoReviewAggregateLoaderProps): import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
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 { z } from "zod";
|
|
6
|
+
import { invokeLoader } from "./invoke-loader";
|
|
7
|
+
import { LoaderErrorBoundary } from "./loader-error-boundary";
|
|
8
|
+
const okendoReviewAggregateOutputSchema = z.object({
|
|
9
|
+
reviewCount: z.number(),
|
|
10
|
+
reviewAverageValue: z.number(),
|
|
11
|
+
reviewStarDistribution: z.record(z.string(), z.number()),
|
|
12
|
+
recommendedPercentage: z.number()
|
|
13
|
+
});
|
|
14
|
+
function OkendoReviewAggregateLoaderInner({
|
|
15
|
+
loaderKey,
|
|
16
|
+
shopifyProductId,
|
|
17
|
+
children
|
|
18
|
+
}) {
|
|
19
|
+
const queryResult = useSuspenseQuery({
|
|
20
|
+
queryKey: [loaderKey, { shopifyProductId }],
|
|
21
|
+
queryFn: async () => {
|
|
22
|
+
const loadedData = await invokeLoader({
|
|
23
|
+
loaderKey,
|
|
24
|
+
args: { shopifyProductId }
|
|
25
|
+
});
|
|
26
|
+
return okendoReviewAggregateOutputSchema.parse(loadedData);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return /* @__PURE__ */ jsx(Fragment, { children: children(queryResult.data) });
|
|
30
|
+
}
|
|
31
|
+
function OkendoReviewAggregateLoader({
|
|
32
|
+
loaderKey,
|
|
33
|
+
shopifyProductId,
|
|
34
|
+
children,
|
|
35
|
+
fallback
|
|
36
|
+
}) {
|
|
37
|
+
return /* @__PURE__ */ jsx(
|
|
38
|
+
LoaderErrorBoundary,
|
|
39
|
+
{
|
|
40
|
+
fallback: fallback ?? null,
|
|
41
|
+
resetKey: `${loaderKey}:${shopifyProductId}`,
|
|
42
|
+
children: /* @__PURE__ */ jsx(Suspense, { fallback: fallback ?? null, children: /* @__PURE__ */ jsx(
|
|
43
|
+
OkendoReviewAggregateLoaderInner,
|
|
44
|
+
{
|
|
45
|
+
loaderKey,
|
|
46
|
+
shopifyProductId,
|
|
47
|
+
children
|
|
48
|
+
}
|
|
49
|
+
) })
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
OkendoReviewAggregateLoader
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=okendo-review-aggregate-loader.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../loaders/okendo-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 { z } from \"zod\";\n\nimport { invokeLoader } from \"./invoke-loader\";\nimport { LoaderErrorBoundary } from \"./loader-error-boundary\";\n\nconst okendoReviewAggregateOutputSchema = z.object({\n reviewCount: z.number(),\n reviewAverageValue: z.number(),\n reviewStarDistribution: z.record(z.string(), z.number()),\n recommendedPercentage: z.number(),\n});\n\ntype OkendoReviewAggregateData = z.infer<\n typeof okendoReviewAggregateOutputSchema\n>;\n\ntype OkendoReviewAggregateLoaderProps = {\n loaderKey: string;\n shopifyProductId: string;\n children: (data: OkendoReviewAggregateData) => ReactNode;\n fallback?: ReactNode;\n};\n\nfunction OkendoReviewAggregateLoaderInner({\n loaderKey,\n shopifyProductId,\n children,\n}: Omit<OkendoReviewAggregateLoaderProps, \"fallback\">) {\n const queryResult = useSuspenseQuery({\n queryKey: [loaderKey, { shopifyProductId }],\n queryFn: async () => {\n const loadedData = await invokeLoader({\n loaderKey,\n args: { shopifyProductId },\n });\n return okendoReviewAggregateOutputSchema.parse(loadedData);\n },\n });\n\n return <>{children(queryResult.data)}</>;\n}\n\nexport function OkendoReviewAggregateLoader({\n loaderKey,\n shopifyProductId,\n children,\n fallback,\n}: OkendoReviewAggregateLoaderProps) {\n return (\n <LoaderErrorBoundary\n fallback={fallback ?? null}\n resetKey={`${loaderKey}:${shopifyProductId}`}\n >\n <Suspense fallback={fallback ?? null}>\n <OkendoReviewAggregateLoaderInner\n loaderKey={loaderKey}\n shopifyProductId={shopifyProductId}\n >\n {children}\n </OkendoReviewAggregateLoaderInner>\n </Suspense>\n </LoaderErrorBoundary>\n );\n}\n"],
|
|
5
|
+
"mappings": ";AA8CS;AA1CT,SAAS,gBAAgB;AAEzB,SAAS,wBAAwB;AACjC,SAAS,SAAS;AAElB,SAAS,oBAAoB;AAC7B,SAAS,2BAA2B;AAEpC,MAAM,oCAAoC,EAAE,OAAO;AAAA,EACjD,aAAa,EAAE,OAAO;AAAA,EACtB,oBAAoB,EAAE,OAAO;AAAA,EAC7B,wBAAwB,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC;AAAA,EACvD,uBAAuB,EAAE,OAAO;AAClC,CAAC;AAaD,SAAS,iCAAiC;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AACF,GAAuD;AACrD,QAAM,cAAc,iBAAiB;AAAA,IACnC,UAAU,CAAC,WAAW,EAAE,iBAAiB,CAAC;AAAA,IAC1C,SAAS,YAAY;AACnB,YAAM,aAAa,MAAM,aAAa;AAAA,QACpC;AAAA,QACA,MAAM,EAAE,iBAAiB;AAAA,MAC3B,CAAC;AACD,aAAO,kCAAkC,MAAM,UAAU;AAAA,IAC3D;AAAA,EACF,CAAC;AAED,SAAO,gCAAG,mBAAS,YAAY,IAAI,GAAE;AACvC;AAEO,SAAS,4BAA4B;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAqC;AACnC,SACE;AAAA,IAAC;AAAA;AAAA,MACC,UAAU,YAAY;AAAA,MACtB,UAAU,GAAG,SAAS,IAAI,gBAAgB;AAAA,MAE1C,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,23 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
declare const okendoReviewsOutputSchema: z.ZodObject<{
|
|
4
|
+
reviews: z.ZodArray<z.ZodObject<{
|
|
5
|
+
id: z.ZodString;
|
|
6
|
+
title: z.ZodOptional<z.ZodString>;
|
|
7
|
+
body: z.ZodOptional<z.ZodString>;
|
|
8
|
+
rating: z.ZodOptional<z.ZodNumber>;
|
|
9
|
+
productName: z.ZodOptional<z.ZodString>;
|
|
10
|
+
reviewerName: z.ZodOptional<z.ZodString>;
|
|
11
|
+
dateCreated: z.ZodOptional<z.ZodString>;
|
|
12
|
+
status: z.ZodOptional<z.ZodString>;
|
|
13
|
+
}, z.core.$strip>>;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
type OkendoReviewsData = z.infer<typeof okendoReviewsOutputSchema>;
|
|
16
|
+
type OkendoReviewsLoaderProps = {
|
|
17
|
+
loaderKey: string;
|
|
18
|
+
shopifyProductId: string;
|
|
19
|
+
children: (data: OkendoReviewsData) => ReactNode;
|
|
20
|
+
fallback?: ReactNode;
|
|
21
|
+
};
|
|
22
|
+
export declare function OkendoReviewsLoader({ loaderKey, shopifyProductId, children, fallback, }: OkendoReviewsLoaderProps): import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
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 { okendoReviewSchema } from "../_vendor/schemas/objectType.mjs";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { invokeLoader } from "./invoke-loader";
|
|
8
|
+
import { LoaderErrorBoundary } from "./loader-error-boundary";
|
|
9
|
+
const okendoReviewsOutputSchema = z.object({
|
|
10
|
+
reviews: z.array(okendoReviewSchema)
|
|
11
|
+
});
|
|
12
|
+
function OkendoReviewsLoaderInner({
|
|
13
|
+
loaderKey,
|
|
14
|
+
shopifyProductId,
|
|
15
|
+
children
|
|
16
|
+
}) {
|
|
17
|
+
const queryResult = useSuspenseQuery({
|
|
18
|
+
queryKey: [loaderKey, { shopifyProductId }],
|
|
19
|
+
queryFn: async () => {
|
|
20
|
+
const loadedData = await invokeLoader({
|
|
21
|
+
loaderKey,
|
|
22
|
+
args: { shopifyProductId }
|
|
23
|
+
});
|
|
24
|
+
return okendoReviewsOutputSchema.parse(loadedData);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return /* @__PURE__ */ jsx(Fragment, { children: children(queryResult.data) });
|
|
28
|
+
}
|
|
29
|
+
function OkendoReviewsLoader({
|
|
30
|
+
loaderKey,
|
|
31
|
+
shopifyProductId,
|
|
32
|
+
children,
|
|
33
|
+
fallback
|
|
34
|
+
}) {
|
|
35
|
+
return /* @__PURE__ */ jsx(
|
|
36
|
+
LoaderErrorBoundary,
|
|
37
|
+
{
|
|
38
|
+
fallback: fallback ?? null,
|
|
39
|
+
resetKey: `${loaderKey}:${shopifyProductId}`,
|
|
40
|
+
children: /* @__PURE__ */ jsx(Suspense, { fallback: fallback ?? null, children: /* @__PURE__ */ jsx(
|
|
41
|
+
OkendoReviewsLoaderInner,
|
|
42
|
+
{
|
|
43
|
+
loaderKey,
|
|
44
|
+
shopifyProductId,
|
|
45
|
+
children
|
|
46
|
+
}
|
|
47
|
+
) })
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
OkendoReviewsLoader
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=okendo-reviews-loader.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../loaders/okendo-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 { okendoReviewSchema } from \"schemas/objectType\";\nimport { z } from \"zod\";\n\nimport { invokeLoader } from \"./invoke-loader\";\nimport { LoaderErrorBoundary } from \"./loader-error-boundary\";\n\nconst okendoReviewsOutputSchema = z.object({\n reviews: z.array(okendoReviewSchema),\n});\n\ntype OkendoReviewsData = z.infer<typeof okendoReviewsOutputSchema>;\n\ntype OkendoReviewsLoaderProps = {\n loaderKey: string;\n shopifyProductId: string;\n children: (data: OkendoReviewsData) => ReactNode;\n fallback?: ReactNode;\n};\n\nfunction OkendoReviewsLoaderInner({\n loaderKey,\n shopifyProductId,\n children,\n}: Omit<OkendoReviewsLoaderProps, \"fallback\">) {\n const queryResult = useSuspenseQuery({\n queryKey: [loaderKey, { shopifyProductId }],\n queryFn: async () => {\n const loadedData = await invokeLoader({\n loaderKey,\n args: { shopifyProductId },\n });\n return okendoReviewsOutputSchema.parse(loadedData);\n },\n });\n\n return <>{children(queryResult.data)}</>;\n}\n\nexport function OkendoReviewsLoader({\n loaderKey,\n shopifyProductId,\n children,\n fallback,\n}: OkendoReviewsLoaderProps) {\n return (\n <LoaderErrorBoundary\n fallback={fallback ?? null}\n resetKey={`${loaderKey}:${shopifyProductId}`}\n >\n <Suspense fallback={fallback ?? null}>\n <OkendoReviewsLoaderInner\n loaderKey={loaderKey}\n shopifyProductId={shopifyProductId}\n >\n {children}\n </OkendoReviewsLoaderInner>\n </Suspense>\n </LoaderErrorBoundary>\n );\n}\n"],
|
|
5
|
+
"mappings": ";AA0CS;AAtCT,SAAS,gBAAgB;AAEzB,SAAS,wBAAwB;AACjC,SAAS,0BAA0B;AACnC,SAAS,SAAS;AAElB,SAAS,oBAAoB;AAC7B,SAAS,2BAA2B;AAEpC,MAAM,4BAA4B,EAAE,OAAO;AAAA,EACzC,SAAS,EAAE,MAAM,kBAAkB;AACrC,CAAC;AAWD,SAAS,yBAAyB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AACF,GAA+C;AAC7C,QAAM,cAAc,iBAAiB;AAAA,IACnC,UAAU,CAAC,WAAW,EAAE,iBAAiB,CAAC;AAAA,IAC1C,SAAS,YAAY;AACnB,YAAM,aAAa,MAAM,aAAa;AAAA,QACpC;AAAA,QACA,MAAM,EAAE,iBAAiB;AAAA,MAC3B,CAAC;AACD,aAAO,0BAA0B,MAAM,UAAU;AAAA,IACnD;AAAA,EACF,CAAC;AAED,SAAO,gCAAG,mBAAS,YAAY,IAAI,GAAE;AACvC;AAEO,SAAS,oBAAoB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA6B;AAC3B,SACE;AAAA,IAAC;AAAA;AAAA,MACC,UAAU,YAAY;AAAA,MACtB,UAAU,GAAG,SAAS,IAAI,gBAAgB;AAAA,MAE1C,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,33 @@
|
|
|
1
|
+
type PrefetchLoaderConfig = {
|
|
2
|
+
loaderKey: string;
|
|
3
|
+
args: Record<string, unknown>;
|
|
4
|
+
/** How long the server-side cache entry is fresh. Defaults to 60s. Use `false` for indefinite (tag-based invalidation only). */
|
|
5
|
+
revalidateSeconds?: number | false;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Server component that prefetches one or more loader queries and seeds the
|
|
9
|
+
* React Query cache via HydrationBoundary. Client components that use
|
|
10
|
+
* useSuspenseQuery with the same queryKey will get the data immediately
|
|
11
|
+
* in the initial HTML — no loading state on first paint.
|
|
12
|
+
*
|
|
13
|
+
* The queryKey is derived internally as `[loaderKey, args]`, matching the
|
|
14
|
+
* convention used by all loader components.
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
* import { DATA_LOADER_KEYS } from "../_vendor/schemas/loaderKeys";
|
|
18
|
+
*
|
|
19
|
+
* <PrefetchedLoaders
|
|
20
|
+
* queries={[
|
|
21
|
+
* {
|
|
22
|
+
* loaderKey: DATA_LOADER_KEYS.SHOPIFY_PRODUCT,
|
|
23
|
+
* args: { productId: "gid://shopify/Product/123" },
|
|
24
|
+
* },
|
|
25
|
+
* ]}
|
|
26
|
+
* >
|
|
27
|
+
* <ProductPreview productId="gid://shopify/Product/123" />
|
|
28
|
+
* </PrefetchedLoaders>
|
|
29
|
+
*/
|
|
30
|
+
export declare function PrefetchedLoaders({ queries, children, }: React.PropsWithChildren<{
|
|
31
|
+
queries: PrefetchLoaderConfig[];
|
|
32
|
+
}>): Promise<import("react/jsx-runtime").JSX.Element>;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
dehydrate,
|
|
4
|
+
HydrationBoundary,
|
|
5
|
+
QueryClient
|
|
6
|
+
} from "@tanstack/react-query";
|
|
7
|
+
import { invokeLoaderServer } from "./invoke-loader-server";
|
|
8
|
+
async function PrefetchedLoaders({
|
|
9
|
+
queries,
|
|
10
|
+
children
|
|
11
|
+
}) {
|
|
12
|
+
const queryClient = new QueryClient({
|
|
13
|
+
defaultOptions: {
|
|
14
|
+
queries: { staleTime: 60 * 1e3 }
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
await Promise.all(
|
|
18
|
+
queries.map((query) => {
|
|
19
|
+
return queryClient.prefetchQuery({
|
|
20
|
+
queryKey: [query.loaderKey, query.args],
|
|
21
|
+
queryFn: () => {
|
|
22
|
+
return invokeLoaderServer({
|
|
23
|
+
loaderKey: query.loaderKey,
|
|
24
|
+
args: query.args,
|
|
25
|
+
revalidateSeconds: query.revalidateSeconds
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
})
|
|
30
|
+
);
|
|
31
|
+
return /* @__PURE__ */ jsx(
|
|
32
|
+
HydrationBoundary,
|
|
33
|
+
{
|
|
34
|
+
state: dehydrate(queryClient, {
|
|
35
|
+
shouldDehydrateQuery: (query) => {
|
|
36
|
+
return query.state.status === "success" || query.state.status === "pending";
|
|
37
|
+
}
|
|
38
|
+
}),
|
|
39
|
+
children
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
PrefetchedLoaders
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=prefetch-loaders.js.map
|