@replohq/canopy-sdk 0.8.4 → 0.9.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.
@@ -176,6 +176,12 @@ export declare const fullCollectionSchema: z.ZodObject<{
176
176
  width: z.ZodNullable<z.ZodNumber>;
177
177
  height: z.ZodNullable<z.ZodNumber>;
178
178
  }, z.core.$strip>>;
179
+ metafields: z.ZodOptional<z.ZodArray<z.ZodObject<{
180
+ key: z.ZodString;
181
+ namespace: z.ZodString;
182
+ type: z.ZodString;
183
+ value: z.ZodString;
184
+ }, z.core.$strip>>>;
179
185
  }, z.core.$strip>;
180
186
  export declare const paginatedProductsSchema: z.ZodObject<{
181
187
  products: z.ZodArray<z.ZodObject<{
@@ -37,7 +37,8 @@ var fullCollectionSchema = z.object({
37
37
  handle: z.string(),
38
38
  title: z.string(),
39
39
  descriptionHtml: z.string().nullable(),
40
- image: imageSchema.nullable()
40
+ image: imageSchema.nullable(),
41
+ metafields: z.array(metafieldSchema).optional()
41
42
  });
42
43
  var paginatedProductsSchema = z.object({
43
44
  products: z.array(productSchema),
@@ -0,0 +1,21 @@
1
+ export type MetafieldIdentifier = {
2
+ namespace: string;
3
+ key: string;
4
+ };
5
+ export type ProductLoaderArgs = {
6
+ handle?: string;
7
+ productId?: string;
8
+ productMetafieldIdentifiers?: MetafieldIdentifier[];
9
+ variantMetafieldIdentifiers?: MetafieldIdentifier[];
10
+ };
11
+ /**
12
+ * Builds the single object used as BOTH the React Query key and the loader
13
+ * payload. They must stay identical: `PrefetchedLoaders` seeds the cache under
14
+ * `[loaderKey, args]`, so an arg sent to the loader but missing from the key
15
+ * (or vice versa) silently misses the prefetch — the client refetches without
16
+ * it and the page renders incomplete data instead of erroring.
17
+ *
18
+ * Keys left `undefined` drop out of React Query's key hash, so omitting a field
19
+ * here hashes the same as a prefetch that never passed it.
20
+ */
21
+ export declare function buildProductLoaderArgs({ handle, productId, productMetafieldIdentifiers, variantMetafieldIdentifiers, }: ProductLoaderArgs): ProductLoaderArgs;
@@ -0,0 +1,17 @@
1
+ function buildProductLoaderArgs({
2
+ handle,
3
+ productId,
4
+ productMetafieldIdentifiers,
5
+ variantMetafieldIdentifiers
6
+ }) {
7
+ return {
8
+ handle,
9
+ productId,
10
+ productMetafieldIdentifiers,
11
+ variantMetafieldIdentifiers
12
+ };
13
+ }
14
+ export {
15
+ buildProductLoaderArgs
16
+ };
17
+ //# sourceMappingURL=product-loader-args.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../loaders/product-loader-args.ts"],
4
+ "sourcesContent": ["export type MetafieldIdentifier = {\n namespace: string;\n key: string;\n};\n\nexport type ProductLoaderArgs = {\n handle?: string;\n productId?: string;\n productMetafieldIdentifiers?: MetafieldIdentifier[];\n variantMetafieldIdentifiers?: MetafieldIdentifier[];\n};\n\n/**\n * Builds the single object used as BOTH the React Query key and the loader\n * payload. They must stay identical: `PrefetchedLoaders` seeds the cache under\n * `[loaderKey, args]`, so an arg sent to the loader but missing from the key\n * (or vice versa) silently misses the prefetch \u2014 the client refetches without\n * it and the page renders incomplete data instead of erroring.\n *\n * Keys left `undefined` drop out of React Query's key hash, so omitting a field\n * here hashes the same as a prefetch that never passed it.\n */\nexport function buildProductLoaderArgs({\n handle,\n productId,\n productMetafieldIdentifiers,\n variantMetafieldIdentifiers,\n}: ProductLoaderArgs): ProductLoaderArgs {\n return {\n handle,\n productId,\n productMetafieldIdentifiers,\n variantMetafieldIdentifiers,\n };\n}\n"],
5
+ "mappings": "AAsBO,SAAS,uBAAuB;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyC;AACvC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -1,11 +1,10 @@
1
1
  import type { ReactNode } from "react";
2
2
  import type { FullProduct } from "../_vendor/schemas/agentTools/customIntegrations/loaders/product";
3
- type ProductLoaderProps = {
3
+ import type { ProductLoaderArgs } from "./product-loader-args";
4
+ type ProductLoaderProps = ProductLoaderArgs & {
4
5
  loaderKey: string;
5
- handle?: string;
6
- productId?: string;
7
6
  children: (data: FullProduct) => ReactNode;
8
7
  fallback?: ReactNode;
9
8
  };
10
- export declare function ProductLoader({ loaderKey, handle, productId, children, fallback, }: ProductLoaderProps): import("react/jsx-runtime").JSX.Element;
9
+ export declare function ProductLoader({ loaderKey, handle, productId, productMetafieldIdentifiers, variantMetafieldIdentifiers, children, fallback, }: ProductLoaderProps): import("react/jsx-runtime").JSX.Element;
11
10
  export {};
@@ -5,19 +5,16 @@ import { useSuspenseQuery } from "@tanstack/react-query";
5
5
  import { fullProductSchema } from "../_vendor/schemas/agentTools/customIntegrations/loaders/product.mjs";
6
6
  import { invokeLoader } from "./invoke-loader";
7
7
  import { LoaderErrorBoundary } from "./loader-error-boundary";
8
+ import { buildProductLoaderArgs } from "./product-loader-args";
8
9
  function ProductLoaderInner({
9
10
  loaderKey,
10
- handle,
11
- productId,
11
+ args,
12
12
  children
13
13
  }) {
14
14
  const queryResult = useSuspenseQuery({
15
- queryKey: [loaderKey, { handle, productId }],
15
+ queryKey: [loaderKey, args],
16
16
  queryFn: async () => {
17
- const loadedData = await invokeLoader({
18
- loaderKey,
19
- args: { handle, productId }
20
- });
17
+ const loadedData = await invokeLoader({ loaderKey, args });
21
18
  return fullProductSchema.parse(loadedData);
22
19
  }
23
20
  });
@@ -27,23 +24,23 @@ function ProductLoader({
27
24
  loaderKey,
28
25
  handle,
29
26
  productId,
27
+ productMetafieldIdentifiers,
28
+ variantMetafieldIdentifiers,
30
29
  children,
31
30
  fallback
32
31
  }) {
32
+ const args = buildProductLoaderArgs({
33
+ handle,
34
+ productId,
35
+ productMetafieldIdentifiers,
36
+ variantMetafieldIdentifiers
37
+ });
33
38
  return /* @__PURE__ */ jsx(
34
39
  LoaderErrorBoundary,
35
40
  {
36
41
  fallback: fallback ?? null,
37
- resetKey: `${loaderKey}:${handle ?? ""}:${productId ?? ""}`,
38
- children: /* @__PURE__ */ jsx(Suspense, { fallback: fallback ?? null, children: /* @__PURE__ */ jsx(
39
- ProductLoaderInner,
40
- {
41
- loaderKey,
42
- handle,
43
- productId,
44
- children
45
- }
46
- ) })
42
+ resetKey: `${loaderKey}:${JSON.stringify(args)}`,
43
+ children: /* @__PURE__ */ jsx(Suspense, { fallback: fallback ?? null, children: /* @__PURE__ */ jsx(ProductLoaderInner, { loaderKey, args, children }) })
47
44
  }
48
45
  );
49
46
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../loaders/product-loader.tsx"],
4
- "sourcesContent": ["\"use client\";\n\nimport type { ReactNode } from \"react\";\nimport type { FullProduct } from \"schemas/agentTools/customIntegrations/loaders/product\";\n\nimport { Suspense } from \"react\";\n\nimport { useSuspenseQuery } from \"@tanstack/react-query\";\nimport { fullProductSchema } from \"schemas/agentTools/customIntegrations/loaders/product\";\n\nimport { invokeLoader } from \"./invoke-loader\";\nimport { LoaderErrorBoundary } from \"./loader-error-boundary\";\n\ntype ProductLoaderProps = {\n loaderKey: string;\n handle?: string;\n productId?: string;\n children: (data: FullProduct) => ReactNode;\n fallback?: ReactNode;\n};\n\nfunction ProductLoaderInner({\n loaderKey,\n handle,\n productId,\n children,\n}: Omit<ProductLoaderProps, \"fallback\">) {\n const queryResult = useSuspenseQuery({\n queryKey: [loaderKey, { handle, productId }],\n queryFn: async () => {\n const loadedData = await invokeLoader({\n loaderKey,\n args: { handle, productId },\n });\n return fullProductSchema.parse(loadedData);\n },\n });\n\n return <>{children(queryResult.data)}</>;\n}\n\nexport function ProductLoader({\n loaderKey,\n handle,\n productId,\n children,\n fallback,\n}: ProductLoaderProps) {\n return (\n <LoaderErrorBoundary\n fallback={fallback ?? null}\n resetKey={`${loaderKey}:${handle ?? \"\"}:${productId ?? \"\"}`}\n >\n <Suspense fallback={fallback ?? null}>\n <ProductLoaderInner\n loaderKey={loaderKey}\n handle={handle}\n productId={productId}\n >\n {children}\n </ProductLoaderInner>\n </Suspense>\n </LoaderErrorBoundary>\n );\n}\n"],
5
- "mappings": ";AAsCS;AAjCT,SAAS,gBAAgB;AAEzB,SAAS,wBAAwB;AACjC,SAAS,yBAAyB;AAElC,SAAS,oBAAoB;AAC7B,SAAS,2BAA2B;AAUpC,SAAS,mBAAmB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyC;AACvC,QAAM,cAAc,iBAAiB;AAAA,IACnC,UAAU,CAAC,WAAW,EAAE,QAAQ,UAAU,CAAC;AAAA,IAC3C,SAAS,YAAY;AACnB,YAAM,aAAa,MAAM,aAAa;AAAA,QACpC;AAAA,QACA,MAAM,EAAE,QAAQ,UAAU;AAAA,MAC5B,CAAC;AACD,aAAO,kBAAkB,MAAM,UAAU;AAAA,IAC3C;AAAA,EACF,CAAC;AAED,SAAO,gCAAG,mBAAS,YAAY,IAAI,GAAE;AACvC;AAEO,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAuB;AACrB,SACE;AAAA,IAAC;AAAA;AAAA,MACC,UAAU,YAAY;AAAA,MACtB,UAAU,GAAG,SAAS,IAAI,UAAU,EAAE,IAAI,aAAa,EAAE;AAAA,MAEzD,8BAAC,YAAS,UAAU,YAAY,MAC9B;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA;AAAA,UAEC;AAAA;AAAA,MACH,GACF;AAAA;AAAA,EACF;AAEJ;",
4
+ "sourcesContent": ["\"use client\";\n\nimport type { ReactNode } from \"react\";\nimport type { FullProduct } from \"schemas/agentTools/customIntegrations/loaders/product\";\nimport type { ProductLoaderArgs } from \"./product-loader-args\";\n\nimport { Suspense } from \"react\";\n\nimport { useSuspenseQuery } from \"@tanstack/react-query\";\nimport { fullProductSchema } from \"schemas/agentTools/customIntegrations/loaders/product\";\n\nimport { invokeLoader } from \"./invoke-loader\";\nimport { LoaderErrorBoundary } from \"./loader-error-boundary\";\nimport { buildProductLoaderArgs } from \"./product-loader-args\";\n\ntype ProductLoaderProps = ProductLoaderArgs & {\n loaderKey: string;\n children: (data: FullProduct) => ReactNode;\n fallback?: ReactNode;\n};\n\nfunction ProductLoaderInner({\n loaderKey,\n args,\n children,\n}: {\n loaderKey: string;\n args: ProductLoaderArgs;\n children: (data: FullProduct) => ReactNode;\n}) {\n const queryResult = useSuspenseQuery({\n queryKey: [loaderKey, args],\n queryFn: async () => {\n const loadedData = await invokeLoader({ loaderKey, args });\n return fullProductSchema.parse(loadedData);\n },\n });\n\n return <>{children(queryResult.data)}</>;\n}\n\nexport function ProductLoader({\n loaderKey,\n handle,\n productId,\n productMetafieldIdentifiers,\n variantMetafieldIdentifiers,\n children,\n fallback,\n}: ProductLoaderProps) {\n const args = buildProductLoaderArgs({\n handle,\n productId,\n productMetafieldIdentifiers,\n variantMetafieldIdentifiers,\n });\n\n return (\n <LoaderErrorBoundary\n fallback={fallback ?? null}\n resetKey={`${loaderKey}:${JSON.stringify(args)}`}\n >\n <Suspense fallback={fallback ?? null}>\n <ProductLoaderInner loaderKey={loaderKey} args={args}>\n {children}\n </ProductLoaderInner>\n </Suspense>\n </LoaderErrorBoundary>\n );\n}\n"],
5
+ "mappings": ";AAsCS;AAhCT,SAAS,gBAAgB;AAEzB,SAAS,wBAAwB;AACjC,SAAS,yBAAyB;AAElC,SAAS,oBAAoB;AAC7B,SAAS,2BAA2B;AACpC,SAAS,8BAA8B;AAQvC,SAAS,mBAAmB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AACF,GAIG;AACD,QAAM,cAAc,iBAAiB;AAAA,IACnC,UAAU,CAAC,WAAW,IAAI;AAAA,IAC1B,SAAS,YAAY;AACnB,YAAM,aAAa,MAAM,aAAa,EAAE,WAAW,KAAK,CAAC;AACzD,aAAO,kBAAkB,MAAM,UAAU;AAAA,IAC3C;AAAA,EACF,CAAC;AAED,SAAO,gCAAG,mBAAS,YAAY,IAAI,GAAE;AACvC;AAEO,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAuB;AACrB,QAAM,OAAO,uBAAuB;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,SACE;AAAA,IAAC;AAAA;AAAA,MACC,UAAU,YAAY;AAAA,MACtB,UAAU,GAAG,SAAS,IAAI,KAAK,UAAU,IAAI,CAAC;AAAA,MAE9C,8BAAC,YAAS,UAAU,YAAY,MAC9B,8BAAC,sBAAmB,WAAsB,MACvC,UACH,GACF;AAAA;AAAA,EACF;AAEJ;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@replohq/canopy-sdk",
3
- "version": "0.8.4",
3
+ "version": "0.9.0",
4
4
  "description": "Replo Canopy SDK — cart, analytics, data loaders, and editor runtime for agent-built Next.js sites.",
5
5
  "type": "module",
6
6
  "sideEffects": false,