@replohq/sdk 1.7.3 → 1.8.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/README.md ADDED
@@ -0,0 +1,165 @@
1
+ # `@replohq/sdk`
2
+
3
+ The Replo SDK provides the React providers, data loaders, cart utilities,
4
+ analytics, consent handling, routing helpers, and Next.js integrations used by
5
+ Replo-powered storefronts.
6
+
7
+ ## Installation
8
+
9
+ Install the SDK and its runtime peers in a Next.js application:
10
+
11
+ ```sh
12
+ pnpm add @replohq/sdk @opennextjs/cloudflare @tanstack/react-query
13
+ ```
14
+
15
+ The application must use Next.js 15 or newer and React 18.2 or newer. React,
16
+ React DOM, and their type packages are peer dependencies and are normally
17
+ already present in a Next.js application.
18
+
19
+ ## Set up the provider
20
+
21
+ Mount `ReploProvider` once around the application. It provides the query
22
+ client, cart state, analytics, and loader error handling used by the rest of
23
+ the SDK. Render managed third-party scripts separately with `ReploScripts` from
24
+ `@replohq/sdk/consent/replo-scripts`.
25
+
26
+ ```tsx
27
+ // app/layout.tsx
28
+ import { ReploProvider } from "@replohq/sdk/providers/replo-provider";
29
+
30
+ export default function RootLayout({ children }: React.PropsWithChildren) {
31
+ return (
32
+ <html lang="en">
33
+ <body>
34
+ <ReploProvider>{children}</ReploProvider>
35
+ </body>
36
+ </html>
37
+ );
38
+ }
39
+ ```
40
+
41
+ `ReploProvider` is an async Server Component. Components that use SDK hooks or
42
+ loaders must render beneath it.
43
+
44
+ ## Data loaders
45
+
46
+ Data loaders retrieve data from integrations configured for the Replo project.
47
+ Use constants from `DATA_LOADER_KEYS` instead of copying loader-key strings.
48
+ The key selects the integration operation and is also the first part of the
49
+ React Query cache key.
50
+
51
+ Loader components are Client Components that pass data to a render function:
52
+
53
+ ```tsx
54
+ // components/product-title.tsx
55
+ "use client";
56
+
57
+ import { ProductLoader } from "@replohq/sdk/loaders/product-loader";
58
+ import { DATA_LOADER_KEYS } from "@replohq/sdk/loaders/loader-keys";
59
+
60
+ export function ProductTitle({ handle }: { handle: string }) {
61
+ return (
62
+ <ProductLoader
63
+ loaderKey={DATA_LOADER_KEYS.SHOPIFY_PRODUCT}
64
+ handle={handle}
65
+ loadingFallback={<p>Loading…</p>}
66
+ fallback={<p>Product unavailable.</p>}
67
+ >
68
+ {(product) => <h1>{product.title}</h1>}
69
+ </ProductLoader>
70
+ );
71
+ }
72
+ ```
73
+
74
+ ### Loader environments and integrations
75
+
76
+ Loaders fetch on the server: directly during SSR, and through a Server Action
77
+ after hydration. The application needs its Replo project configuration in every
78
+ environment:
79
+
80
+ - During local development and builds, `wrangler.jsonc` must provide
81
+ `CANOPY_API_HOST` and `PROJECT_ID` in `vars`.
82
+ - In a deployed OpenNext/Cloudflare environment, provide the same values as
83
+ runtime bindings.
84
+ - Connect each integration in the Replo project; the site holds no provider
85
+ credentials.
86
+
87
+ Use these public loader components and keys for each configured integration:
88
+
89
+ | Integration | Loader component | `DATA_LOADER_KEYS` value |
90
+ | --- | --- | --- |
91
+ | Shopify Storefront | `ProductLoader` | `SHOPIFY_PRODUCT` |
92
+ | Replo product catalog | `ProductLoader` | `REPLO_PRODUCT` |
93
+ | Shopify Storefront | `CollectionLoader` | `SHOPIFY_COLLECTION` |
94
+ | Shopify Storefront | `CollectionProductsLoader` | `SHOPIFY_COLLECTION_PRODUCTS` |
95
+ | Shopify Storefront | `MetaobjectLoader` | `SHOPIFY_METAOBJECT` |
96
+ | Shopify Storefront | `MetaobjectsLoader` | `SHOPIFY_METAOBJECTS` |
97
+ | Okendo | `OkendoReviewsLoader` | `OKENDO_PRODUCT_REVIEWS` |
98
+ | Okendo | `OkendoReviewAggregateLoader` | `OKENDO_PRODUCT_REVIEW_AGGREGATE` |
99
+ | Rebuy | `RebuyRecommendationsLoader` | `REBUY_RECOMMENDATIONS` |
100
+ | Levanta | `LevantaProductLoader` | `LEVANTA_PRODUCT` |
101
+ | Smile.io | `SmileVipTiersLoader` | `SMILE_IO_VIP_TIERS` |
102
+ | Smile.io | `SmileEarningRulesLoader` | `SMILE_IO_EARNING_RULES` |
103
+ | Smile.io | `SmileRewardsLoader` | `SMILE_IO_REWARDS` |
104
+ | Yotpo | `YotpoReviewsLoader` | `YOTPO_PRODUCT_REVIEWS` |
105
+ | Yotpo | `YotpoReviewAggregateLoader` | `YOTPO_PRODUCT_REVIEW_AGGREGATE` |
106
+ | Reviews.io | `ReviewsIoReviewsLoader` | `REVIEWS_IO_PRODUCT_REVIEWS` |
107
+ | Reviews.io | `ReviewsIoReviewAggregateLoader` | `REVIEWS_IO_PRODUCT_REVIEW_AGGREGATE` |
108
+ | Loox | `LooxReviewsLoader` | `LOOX_PRODUCT_REVIEWS` |
109
+ | Loox | `LooxReviewAggregateLoader` | `LOOX_PRODUCT_REVIEW_AGGREGATE` |
110
+ | Judge.me | `JudgemeReviewsLoader` | `JUDGEME_PRODUCT_REVIEWS` |
111
+ | Judge.me | `JudgemeReviewAggregateLoader` | `JUDGEME_PRODUCT_REVIEW_AGGREGATE` |
112
+ | Statsig | `StatsigExperimentLoader` | `STATSIG_EXPERIMENT` |
113
+ | Contentful | `ContentfulEntryLoader` | `CONTENTFUL_ENTRY` |
114
+ | Contentful | `ContentfulEntriesLoader` | `CONTENTFUL_ENTRIES` |
115
+
116
+ Import each component from its kebab-case subpath, for example
117
+ `CollectionLoader` from `@replohq/sdk/loaders/collection-loader`.
118
+
119
+ ### Prefetch on the server
120
+
121
+ `PrefetchedLoaders` is a Server Component that fetches loader data during SSR
122
+ and hydrates the React Query cache. Wrap the matching Client Component to avoid
123
+ a loading state on the first paint:
124
+
125
+ ```tsx
126
+ // app/products/[handle]/page.tsx
127
+ import { PrefetchedLoaders } from "@replohq/sdk/loaders/prefetch-loaders";
128
+ import { DATA_LOADER_KEYS } from "@replohq/sdk/loaders/loader-keys";
129
+
130
+ import { ProductTitle } from "../../../components/product-title";
131
+
132
+ export default async function ProductPage({
133
+ params,
134
+ }: {
135
+ params: Promise<{ handle: string }>;
136
+ }) {
137
+ const { handle } = await params;
138
+
139
+ return (
140
+ <PrefetchedLoaders
141
+ queries={[
142
+ {
143
+ loaderKey: DATA_LOADER_KEYS.SHOPIFY_PRODUCT,
144
+ args: { handle },
145
+ },
146
+ ]}
147
+ >
148
+ <ProductTitle handle={handle} />
149
+ </PrefetchedLoaders>
150
+ );
151
+ }
152
+ ```
153
+
154
+ The `loaderKey` and complete `args` object must exactly match the props used by
155
+ the loader component, including optional locale, pagination, or metafield
156
+ arguments. `PrefetchedLoaders` accepts `revalidateSeconds` per query; it
157
+ defaults to 60 seconds, and `false` enables indefinite tag-based caching.
158
+
159
+ Server-only code that does not hydrate a loader component can call
160
+ `invokeLoaderServer` from `@replohq/sdk/loaders/invoke-loader-server`.
161
+
162
+ ## License
163
+
164
+ This package is proprietary software. See [LICENSE](./LICENSE)
165
+ (`SEE LICENSE IN LICENSE`) and the [Replo Terms of Service](https://replo.app/terms).
@@ -12,14 +12,8 @@ export declare function randomBase64Url(byteLength: number): string;
12
12
  * `crypto.getRandomValues`, which carries no such restriction.
13
13
  */
14
14
  export declare function randomUUID(): string;
15
- /**
16
- * Returns the SHA-256 of `input` as a 64-char lowercase hex string.
17
- *
18
- * Used for storing opaque secrets (e.g. public API tokens) where we want
19
- * constant-length hex output suitable for a `VARCHAR(64)` column with a
20
- * unique index.
21
- */
22
- export declare function sha256Hex(input: string): Promise<string>;
15
+ /** Strings use UTF-8; binary inputs are hashed unchanged. */
16
+ export declare function sha256Hex(input: string | Parameters<typeof crypto.subtle.digest>[1]): Promise<string>;
23
17
  export declare function constantTimeEqual({ left, right, }: {
24
18
  left: Uint8Array;
25
19
  right: Uint8Array;
@@ -70,4 +70,5 @@ export declare function fileExtensionFromUrl(url: string): string;
70
70
  export declare function sanitizePublicHttpUrl(value: string | null, { preserveProtocol }?: {
71
71
  preserveProtocol?: boolean;
72
72
  }): string | null;
73
+ export declare function isPublicHttpsUrl(value: string): boolean;
73
74
  export declare function safeHost(url: string): string | null;
@@ -0,0 +1,19 @@
1
+ import type { AnalyticsCollection, AnalyticsCollectionProduct } from "../utils/collection-analytics";
2
+ interface UseCollectionViewedAnalyticsProps {
3
+ collection: AnalyticsCollection | null | undefined;
4
+ /**
5
+ * The collection's products as the collection-products loader returns them.
6
+ * Pass `undefined` while they are still loading so the event carries the
7
+ * list when it fires.
8
+ */
9
+ products: AnalyticsCollectionProduct[] | null | undefined;
10
+ }
11
+ /**
12
+ * Fires a `viewCollection` analytics event carrying the collection's products
13
+ * once the collection and its product list are both available. Re-renders
14
+ * and product-list updates for the same collection do not fire again; a
15
+ * different collection does, and returning to an earlier one counts as a new
16
+ * view, matching `useProductViewedAnalytics`.
17
+ */
18
+ export declare function useCollectionViewedAnalytics({ collection, products, }: UseCollectionViewedAnalyticsProps): void;
19
+ export {};
@@ -0,0 +1,26 @@
1
+ "use client";
2
+ import { useEffect, useRef } from "react";
3
+ import { useAnalytics } from "../analytics-provider";
4
+ import { buildCollectionViewedAnalyticsData } from "../utils/collection-analytics";
5
+ function useCollectionViewedAnalytics({
6
+ collection,
7
+ products
8
+ }) {
9
+ const analytics = useAnalytics();
10
+ const lastTrackedRef = useRef(null);
11
+ useEffect(() => {
12
+ if (!analytics || !collection || !products) {
13
+ return;
14
+ }
15
+ if (lastTrackedRef.current === collection.id) {
16
+ return;
17
+ }
18
+ lastTrackedRef.current = collection.id;
19
+ void analytics.viewCollection({
20
+ data: buildCollectionViewedAnalyticsData({ collection, products })
21
+ });
22
+ }, [analytics, collection, products]);
23
+ }
24
+ export {
25
+ useCollectionViewedAnalytics
26
+ };
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import { legacyResourceId } from "../utils/analytics-products";
2
3
  const GUEST_USER_PROPERTIES = { visitor_type: "guest" };
3
4
  const FALLBACK_CURRENCY_CODE = "USD";
4
5
  const nonEmptyStringSchema = z.union([z.string().min(1), z.number().finite().transform(String)]).optional().catch(void 0);
@@ -45,9 +46,6 @@ const collectionPayloadSchema = z.object({
45
46
  function formatMoney(amount) {
46
47
  return amount.toFixed(2);
47
48
  }
48
- function legacyResourceId(id) {
49
- return id.replace(/^gid:\/\/shopify\/\w+\//, "");
50
- }
51
49
  function parseCheckoutLine(line) {
52
50
  const parsed = checkoutLineSchema.safeParse(line);
53
51
  if (!parsed.success || !parsed.data.merchandise) {
@@ -1,3 +1,8 @@
1
+ import {
2
+ legacyResourceId,
3
+ splitCollectionProducts,
4
+ withoutUndefined
5
+ } from "../utils/analytics-products";
1
6
  import { createEventQueue } from "../utils/analytics-utils";
2
7
  class GA4Sink {
3
8
  send;
@@ -48,7 +53,24 @@ class GA4Sink {
48
53
  this.send("begin_checkout", data);
49
54
  }
50
55
  async viewCollection({ data }) {
51
- this.send("view_item_list", data);
56
+ const { products, rest } = splitCollectionProducts(data);
57
+ this.send("view_item_list", {
58
+ item_list_id: data.collectionId,
59
+ item_list_name: data.collectionTitle,
60
+ currency: data.currency,
61
+ ...products.length > 0 ? {
62
+ items: products.map((product, index) => {
63
+ return withoutUndefined({
64
+ item_id: legacyResourceId(product.productId),
65
+ item_name: product.productTitle,
66
+ item_variant: product.variantTitle,
67
+ price: product.price,
68
+ index
69
+ });
70
+ })
71
+ } : {},
72
+ ...rest
73
+ });
52
74
  }
53
75
  }
54
76
  export {
@@ -1,3 +1,8 @@
1
+ import {
2
+ legacyResourceId,
3
+ splitCollectionProducts,
4
+ withoutUndefined
5
+ } from "../utils/analytics-products";
1
6
  import { createEventQueue } from "../utils/analytics-utils";
2
7
  class PinterestSink {
3
8
  track;
@@ -61,9 +66,22 @@ class PinterestSink {
61
66
  });
62
67
  }
63
68
  async viewCollection({ data }) {
69
+ const { products, rest } = splitCollectionProducts(data);
64
70
  this.track("viewcategory", {
65
71
  product_category: data.category,
66
- ...data
72
+ currency: data.currency,
73
+ ...products.length > 0 ? {
74
+ line_items: products.map((product) => {
75
+ return withoutUndefined({
76
+ product_id: legacyResourceId(product.productId),
77
+ product_name: product.productTitle,
78
+ product_price: product.price,
79
+ product_variant_id: product.variantId === void 0 ? void 0 : legacyResourceId(product.variantId),
80
+ product_variant: product.variantTitle
81
+ });
82
+ })
83
+ } : {},
84
+ ...rest
67
85
  });
68
86
  }
69
87
  }
@@ -1,3 +1,8 @@
1
+ import {
2
+ legacyResourceId,
3
+ splitCollectionProducts,
4
+ withoutUndefined
5
+ } from "../utils/analytics-products";
1
6
  import { createEventQueue } from "../utils/analytics-utils";
2
7
  class RedditSink {
3
8
  track;
@@ -64,10 +69,20 @@ class RedditSink {
64
69
  });
65
70
  }
66
71
  async viewCollection({ data }) {
72
+ const { products, rest } = splitCollectionProducts(data);
67
73
  this.track("ViewContent", {
68
74
  content_category: data.category,
69
75
  content_type: "category",
70
- ...data
76
+ currency: data.currency,
77
+ ...products.length > 0 ? {
78
+ products: products.map((product) => {
79
+ return withoutUndefined({
80
+ id: legacyResourceId(product.productId),
81
+ name: product.productTitle
82
+ });
83
+ })
84
+ } : {},
85
+ ...rest
71
86
  });
72
87
  }
73
88
  }
@@ -1,3 +1,8 @@
1
+ import {
2
+ legacyResourceId,
3
+ splitCollectionProducts,
4
+ withoutUndefined
5
+ } from "../utils/analytics-products";
1
6
  import { createEventQueue } from "../utils/analytics-utils";
2
7
  class TikTokSink {
3
8
  track;
@@ -63,10 +68,22 @@ class TikTokSink {
63
68
  });
64
69
  }
65
70
  async viewCollection({ data }) {
71
+ const { products, rest } = splitCollectionProducts(data);
66
72
  this.track("ViewContent", {
67
73
  content_type: "product_group",
68
74
  content_category: data.category,
69
- ...data
75
+ currency: data.currency,
76
+ ...products.length > 0 ? {
77
+ contents: products.map((product) => {
78
+ return withoutUndefined({
79
+ content_id: legacyResourceId(product.productId),
80
+ content_type: "product_group",
81
+ content_name: product.productTitle,
82
+ price: product.price
83
+ });
84
+ })
85
+ } : {},
86
+ ...rest
70
87
  });
71
88
  }
72
89
  }
@@ -0,0 +1,36 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * The flat per-product line the cart provider and the viewed hooks emit.
4
+ * Prices are decimal major units.
5
+ */
6
+ declare const analyticsProductLineSchema: z.ZodObject<{
7
+ productId: z.ZodCatch<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodNumber, z.ZodTransform<string, number>>]>>>;
8
+ productTitle: z.ZodCatch<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodNumber, z.ZodTransform<string, number>>]>>>;
9
+ variantId: z.ZodCatch<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodNumber, z.ZodTransform<string, number>>]>>>;
10
+ variantTitle: z.ZodCatch<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodNumber, z.ZodTransform<string, number>>]>>>;
11
+ variantSku: z.ZodCatch<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodNumber, z.ZodTransform<string, number>>]>>>;
12
+ price: z.ZodCatch<z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodNumber>]>>>;
13
+ currency: z.ZodCatch<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodNumber, z.ZodTransform<string, number>>]>>>;
14
+ quantity: z.ZodCatch<z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodNumber>]>>>;
15
+ }, z.core.$strip>;
16
+ export type AnalyticsProductLine = z.infer<typeof analyticsProductLineSchema> & {
17
+ productId: string;
18
+ };
19
+ export declare function parseAnalyticsProductLines(value: unknown): AnalyticsProductLine[];
20
+ /**
21
+ * Separates a collection-view payload's `products` list from the scalar
22
+ * fields, so a sink can map the list into its own item shape and forward the
23
+ * rest untouched.
24
+ */
25
+ export declare function splitCollectionProducts(data: Record<string, unknown>): {
26
+ products: AnalyticsProductLine[];
27
+ rest: Record<string, unknown>;
28
+ };
29
+ /**
30
+ * Shopify catalogs synced into ad platforms key on legacy numeric ids, while
31
+ * the Storefront API hands sites GIDs (`gid://shopify/Product/123`). Pixel
32
+ * catalog matching is an exact string match, so ids are sent bare.
33
+ */
34
+ export declare function legacyResourceId(id: string): string;
35
+ export declare function withoutUndefined<RecordType extends Record<string, unknown>>(record: RecordType): Partial<RecordType>;
36
+ export {};
@@ -0,0 +1,57 @@
1
+ import { z } from "zod";
2
+ const nonEmptyStringSchema = z.union([z.string().min(1), z.number().finite().transform(String)]).optional().catch(void 0);
3
+ const finiteNumberSchema = z.union([
4
+ z.number().finite(),
5
+ z.string().trim().min(1).transform(Number).pipe(z.number().finite())
6
+ ]).optional().catch(void 0);
7
+ const analyticsProductLineSchema = z.object({
8
+ productId: nonEmptyStringSchema,
9
+ productTitle: nonEmptyStringSchema,
10
+ variantId: nonEmptyStringSchema,
11
+ variantTitle: nonEmptyStringSchema,
12
+ variantSku: nonEmptyStringSchema,
13
+ price: finiteNumberSchema,
14
+ currency: nonEmptyStringSchema,
15
+ quantity: finiteNumberSchema
16
+ });
17
+ function parseAnalyticsProductLines(value) {
18
+ if (!Array.isArray(value)) {
19
+ return [];
20
+ }
21
+ return value.flatMap((item) => {
22
+ const parsed = analyticsProductLineSchema.safeParse(item);
23
+ if (!parsed.success || !parsed.data.productId) {
24
+ return [];
25
+ }
26
+ return [{ ...parsed.data, productId: parsed.data.productId }];
27
+ });
28
+ }
29
+ function splitCollectionProducts(data) {
30
+ const { products, ...rest } = data;
31
+ const lines = parseAnalyticsProductLines(products);
32
+ if (Array.isArray(products) && products.length > 0 && lines.length === 0) {
33
+ console.warn(
34
+ "[analytics] collection view products did not match the per-line shape and were dropped",
35
+ { products }
36
+ );
37
+ }
38
+ return { products: lines, rest };
39
+ }
40
+ function legacyResourceId(id) {
41
+ return id.replace(/^gid:\/\/shopify\/\w+\//, "");
42
+ }
43
+ function withoutUndefined(record) {
44
+ const compacted = {};
45
+ for (const key in record) {
46
+ if (record[key] !== void 0) {
47
+ compacted[key] = record[key];
48
+ }
49
+ }
50
+ return compacted;
51
+ }
52
+ export {
53
+ legacyResourceId,
54
+ parseAnalyticsProductLines,
55
+ splitCollectionProducts,
56
+ withoutUndefined
57
+ };
@@ -0,0 +1,44 @@
1
+ export interface AnalyticsMoney {
2
+ amount: number | string;
3
+ currencyCode: string;
4
+ }
5
+ export interface AnalyticsCollection {
6
+ id: string;
7
+ title?: string | null;
8
+ handle?: string | null;
9
+ }
10
+ export interface AnalyticsCollectionProductVariant {
11
+ id: string;
12
+ title?: string | null;
13
+ sku?: string | null;
14
+ price?: AnalyticsMoney | null;
15
+ }
16
+ export interface AnalyticsCollectionProduct {
17
+ id: string;
18
+ title?: string | null;
19
+ variants?: AnalyticsCollectionProductVariant[] | null;
20
+ minPrice?: AnalyticsMoney | null;
21
+ }
22
+ /**
23
+ * The `viewCollection` payload: collection identity plus one line per product
24
+ * in the same shape the cart events use, priced from the first variant (or
25
+ * the product's minimum price) with no quantity.
26
+ */
27
+ export declare function buildCollectionViewedAnalyticsData({ collection, products, }: {
28
+ collection: AnalyticsCollection;
29
+ products: AnalyticsCollectionProduct[];
30
+ }): {
31
+ collectionTitle?: string | undefined;
32
+ collectionHandle?: string | undefined;
33
+ currency?: string | undefined;
34
+ collectionId: string;
35
+ products: {
36
+ productTitle?: string | undefined;
37
+ variantId?: string | undefined;
38
+ variantTitle?: string | undefined;
39
+ variantSku?: string | undefined;
40
+ price?: number | undefined;
41
+ currency?: string | undefined;
42
+ productId: string;
43
+ }[];
44
+ };
@@ -0,0 +1,41 @@
1
+ import { withoutUndefined } from "./analytics-products";
2
+ function parseAmount(money) {
3
+ if (!money) {
4
+ return void 0;
5
+ }
6
+ const amount = Number(money.amount);
7
+ return Number.isFinite(amount) ? amount : void 0;
8
+ }
9
+ function buildCollectionProductLine(product) {
10
+ const variant = product.variants?.[0];
11
+ const money = variant?.price ?? product.minPrice ?? void 0;
12
+ return {
13
+ productId: product.id,
14
+ ...withoutUndefined({
15
+ productTitle: product.title ?? void 0,
16
+ variantId: variant?.id,
17
+ variantTitle: variant?.title ?? void 0,
18
+ variantSku: variant?.sku ?? void 0,
19
+ price: parseAmount(money),
20
+ currency: money?.currencyCode
21
+ })
22
+ };
23
+ }
24
+ function buildCollectionViewedAnalyticsData({
25
+ collection,
26
+ products
27
+ }) {
28
+ const lines = products.map(buildCollectionProductLine);
29
+ return {
30
+ collectionId: collection.id,
31
+ products: lines,
32
+ ...withoutUndefined({
33
+ collectionTitle: collection.title ?? void 0,
34
+ collectionHandle: collection.handle ?? void 0,
35
+ currency: lines.find((line) => line.currency)?.currency
36
+ })
37
+ };
38
+ }
39
+ export {
40
+ buildCollectionViewedAnalyticsData
41
+ };
@@ -1,7 +1,7 @@
1
1
  export const BUILD_METADATA = {
2
2
  "packageName": "@replohq/sdk",
3
- "version": "1.7.3",
3
+ "version": "1.8.1",
4
4
  "branch": "HEAD",
5
- "commit": "d7ee0ec28234216b633c81e1a6d8683591c946f8",
6
- "builtAt": "2026-09-15T17:30:06.396Z"
5
+ "commit": "769a5347144bb3d6c77b6f06b075c8f6ad45a6b3",
6
+ "builtAt": "2026-09-16T18:01:00.137Z"
7
7
  };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@replohq/sdk",
3
- "version": "1.7.3",
3
+ "version": "1.8.1",
4
4
  "reploBuild": {
5
5
  "packageName": "@replohq/sdk",
6
- "version": "1.7.3",
6
+ "version": "1.8.1",
7
7
  "branch": "HEAD",
8
- "commit": "d7ee0ec28234216b633c81e1a6d8683591c946f8",
9
- "builtAt": "2026-09-15T17:30:06.396Z"
8
+ "commit": "769a5347144bb3d6c77b6f06b075c8f6ad45a6b3",
9
+ "builtAt": "2026-09-16T18:01:00.137Z"
10
10
  },
11
11
  "description": "Replo SDK — cart, analytics, and data loaders for agent-built Next.js sites.",
12
12
  "license": "SEE LICENSE IN LICENSE",
@@ -89,6 +89,10 @@
89
89
  "types": "./analytics/hooks/use-product-viewed-analytics.d.ts",
90
90
  "default": "./analytics/hooks/use-product-viewed-analytics.js"
91
91
  },
92
+ "./analytics/hooks/use-collection-viewed-analytics": {
93
+ "types": "./analytics/hooks/use-collection-viewed-analytics.d.ts",
94
+ "default": "./analytics/hooks/use-collection-viewed-analytics.js"
95
+ },
92
96
  "./loaders/collection-loader": {
93
97
  "types": "./loaders/collection-loader.d.ts",
94
98
  "default": "./loaders/collection-loader.js"