@replohq/canopy-sdk 1.3.0 → 1.3.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.
@@ -53,3 +53,8 @@ export declare function formatAmount({ amount, currencyCode, locale, }: {
53
53
  locale?: string;
54
54
  }): string;
55
55
  export declare const amountSchema: z.ZodNumber;
56
+ /** An amount in minor units paired with its ISO 4217 currency code. */
57
+ export declare const amountWithCurrencyCodeSchema: z.ZodObject<{
58
+ amount: z.ZodNumber;
59
+ currencyCode: z.ZodString;
60
+ }, z.core.$strip>;
@@ -189,5 +189,9 @@ function formatAmount({
189
189
  var amountSchema = z.number().int().describe(
190
190
  "Integer amount in the currency's minor units (Stripe convention): 1999 = $19.99 USD, 1999 = \xA51999 JPY, 1999 = 1.999 KWD"
191
191
  );
192
+ var amountWithCurrencyCodeSchema = z.object({
193
+ amount: amountSchema,
194
+ currencyCode: z.string()
195
+ });
192
196
 
193
- export { InvalidAmountError, UnsupportedCurrencyError, amountSchema, formatAmount, fromMajorUnitsToMinorUnits, fromMinorUnitsToMajorUnits, fromMinorUnitsToMajorUnitsString, parseDecimalToMinorUnits };
197
+ export { InvalidAmountError, UnsupportedCurrencyError, amountSchema, amountWithCurrencyCodeSchema, formatAmount, fromMajorUnitsToMinorUnits, fromMinorUnitsToMajorUnits, fromMinorUnitsToMajorUnitsString, parseDecimalToMinorUnits };
@@ -8,11 +8,16 @@ const cartImageSchema = z.object({
8
8
  url: z.string(),
9
9
  altText: z.string().nullable()
10
10
  });
11
+ const amountSchema = z.number().int();
12
+ const amountWithCurrencyCodeSchema = z.object({
13
+ amount: amountSchema,
14
+ currencyCode: z.string()
15
+ });
11
16
  const sellingPlanPriceAdjustmentSchema = z.object({
12
- compareAtPrice: z.object({ amount: z.number(), currencyCode: z.string() }),
13
- perDeliveryPrice: z.object({ amount: z.number(), currencyCode: z.string() }),
14
- price: z.object({ amount: z.number(), currencyCode: z.string() }),
15
- unitPrice: z.object({ amount: z.number(), currencyCode: z.string() }).nullable()
17
+ compareAtPrice: amountWithCurrencyCodeSchema,
18
+ perDeliveryPrice: amountWithCurrencyCodeSchema,
19
+ price: amountWithCurrencyCodeSchema,
20
+ unitPrice: amountWithCurrencyCodeSchema.nullable()
16
21
  });
17
22
  const sellingPlanAllocationSchema = z.object({
18
23
  sellingPlan: z.object({
@@ -21,14 +26,8 @@ const sellingPlanAllocationSchema = z.object({
21
26
  description: z.string().nullable()
22
27
  }),
23
28
  priceAdjustments: z.array(sellingPlanPriceAdjustmentSchema),
24
- checkoutChargeAmount: z.object({
25
- amount: z.number(),
26
- currencyCode: z.string()
27
- }),
28
- remainingBalanceChargeAmount: z.object({
29
- amount: z.number(),
30
- currencyCode: z.string()
31
- })
29
+ checkoutChargeAmount: amountWithCurrencyCodeSchema,
30
+ remainingBalanceChargeAmount: amountWithCurrencyCodeSchema
32
31
  });
33
32
  const cartLineMerchandiseSchema = z.object({
34
33
  id: z.string(),
@@ -37,8 +36,8 @@ const cartLineMerchandiseSchema = z.object({
37
36
  title: z.string()
38
37
  }),
39
38
  title: z.string(),
40
- price: z.number(),
41
- compareAtPrice: z.number().nullish(),
39
+ price: amountSchema,
40
+ compareAtPrice: amountSchema.nullish(),
42
41
  image: cartImageSchema.nullable(),
43
42
  selectedOptions: z.array(z.object({ name: z.string(), value: z.string() }))
44
43
  });
@@ -50,8 +49,8 @@ const cartLineSchema = z.object({
50
49
  sellingPlanAllocation: sellingPlanAllocationSchema.nullish()
51
50
  });
52
51
  const cartCostSchema = z.object({
53
- subtotalAmount: z.number(),
54
- totalAmount: z.number(),
52
+ subtotalAmount: amountSchema,
53
+ totalAmount: amountSchema,
55
54
  currencyCode: z.string()
56
55
  });
57
56
  const cartDiscountCodeSchema = z.object({
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../cart/cart-schema.ts"],
4
- "sourcesContent": ["import { z } from \"zod\";\n\n// NOTE (Ryan, 2026-07-23, REPL-27611): Self-contained copy of the cart wire\n// schema that the canopy-sdk gateway validates on published pages, so nothing\n// shipped to a generated site imports from `schemas`. The backend keeps the\n// canonical copy in `schemas/cart.ts` (its cart services can't depend on\n// canopy-sdk without a cycle); `cart-schema.spec.ts` keeps the two in lockstep.\n\n// ---------------------------------------------------------------------------\n// Cart line attribute\n// ---------------------------------------------------------------------------\n\nexport const cartLineAttributeSchema = z.object({\n key: z.string(),\n value: z.union([z.string(), z.number(), z.boolean()]),\n});\n\nexport const cartLineAttributesSchema = z.array(cartLineAttributeSchema);\n\nexport type CartLineAttribute = z.infer<typeof cartLineAttributeSchema>;\n\n// ---------------------------------------------------------------------------\n// Image (cart-scoped; lightweight compared to objectType image)\n// ---------------------------------------------------------------------------\n\nexport const cartImageSchema = z.object({\n url: z.string(),\n altText: z.string().nullable(),\n});\n\nexport type CartImage = z.infer<typeof cartImageSchema>;\n\n// ---------------------------------------------------------------------------\n// Selling plan types\n// ---------------------------------------------------------------------------\n\nconst sellingPlanPriceAdjustmentSchema = z.object({\n compareAtPrice: z.object({ amount: z.number(), currencyCode: z.string() }),\n perDeliveryPrice: z.object({ amount: z.number(), currencyCode: z.string() }),\n price: z.object({ amount: z.number(), currencyCode: z.string() }),\n unitPrice: z\n .object({ amount: z.number(), currencyCode: z.string() })\n .nullable(),\n});\n\nconst sellingPlanAllocationSchema = z.object({\n sellingPlan: z.object({\n id: z.string(),\n name: z.string(),\n description: z.string().nullable(),\n }),\n priceAdjustments: z.array(sellingPlanPriceAdjustmentSchema),\n checkoutChargeAmount: z.object({\n amount: z.number(),\n currencyCode: z.string(),\n }),\n remainingBalanceChargeAmount: z.object({\n amount: z.number(),\n currencyCode: z.string(),\n }),\n});\n\n// ---------------------------------------------------------------------------\n// Cart line merchandise\n// ---------------------------------------------------------------------------\n\nexport const cartLineMerchandiseSchema = z.object({\n id: z.string(),\n product: z.object({\n id: z.string(),\n title: z.string(),\n }),\n title: z.string(),\n price: z.number(),\n compareAtPrice: z.number().nullish(),\n image: cartImageSchema.nullable(),\n selectedOptions: z.array(z.object({ name: z.string(), value: z.string() })),\n});\n\nexport type CartLineMerchandise = z.infer<typeof cartLineMerchandiseSchema>;\n\n// ---------------------------------------------------------------------------\n// Cart line\n// ---------------------------------------------------------------------------\n\nexport const cartLineSchema = z.object({\n id: z.string(),\n quantity: z.number(),\n merchandise: cartLineMerchandiseSchema,\n attributes: z.array(cartLineAttributeSchema),\n sellingPlanAllocation: sellingPlanAllocationSchema.nullish(),\n});\n\nexport type CartLine = z.infer<typeof cartLineSchema>;\n\n// ---------------------------------------------------------------------------\n// Cart cost\n// ---------------------------------------------------------------------------\n\nexport const cartCostSchema = z.object({\n subtotalAmount: z.number(),\n totalAmount: z.number(),\n currencyCode: z.string(),\n});\n\nexport type CartCost = z.infer<typeof cartCostSchema>;\n\n// ---------------------------------------------------------------------------\n// Cart discount code\n// ---------------------------------------------------------------------------\n\nexport const cartDiscountCodeSchema = z.object({\n code: z.string(),\n applicable: z.boolean(),\n});\n\nexport type CartDiscountCode = z.infer<typeof cartDiscountCodeSchema>;\n\n// ---------------------------------------------------------------------------\n// Cart (top level)\n// ---------------------------------------------------------------------------\n\nexport const cartSchema = z.object({\n id: z.string(),\n lines: z.array(cartLineSchema),\n cost: cartCostSchema,\n checkoutUrl: z.string().optional(),\n discountCodes: z.array(cartDiscountCodeSchema).optional(),\n});\n\nexport type Cart = z.infer<typeof cartSchema>;\n\n// ---------------------------------------------------------------------------\n// Cart mutation input schemas (used by both resolver and SDK gateway)\n// ---------------------------------------------------------------------------\n\nexport const addCartLinesInputSchema = z.object({\n merchandiseId: z.string(),\n quantity: z.number().int().positive(),\n attributes: z.array(cartLineAttributeSchema).optional(),\n sellingPlanId: z.string().nullish(),\n});\n\nexport type AddCartLineInput = z.infer<typeof addCartLinesInputSchema>;\n\nexport const updateCartLineInputSchema = z.object({\n lineId: z.string(),\n quantity: z.number().int().min(0),\n attributes: z.array(cartLineAttributeSchema).optional(),\n sellingPlanId: z.string().nullish(),\n});\n\nex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,OAAO,EAAE,IAAI,EAAE,SAAS;AAAA,EACpC,YAAY,EAAE,MAAM,uBAAuB,EAAE,SAAS;AAAA,EACtD,eAAe,EAAE,OAAO,EAAE,QAAQ;AACpC,CAAC;AAIM,MAAM,4BAA4B,EAAE,OAAO;AAAA,EAChD,QAAQ,EAAE,OAAO;AAAA,EACjB,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC;AAAA,EAChC,YAAY,EAAE,MAAM,uBAAuB,EAAE,SAAS;AAAA,EACtD,eAAe,EAAE,OAAO,EAAE,QAAQ;AACpC,CAAC;",
4
+ "sourcesContent": ["import { z } from \"zod\";\n\n// NOTE (Ryan, 2026-07-23, REPL-27611): Self-contained copy of the cart wire\n// schema that the canopy-sdk gateway validates on published pages, so nothing\n// shipped to a generated site imports from `schemas`. The backend keeps the\n// canonical copy in `schemas/cart.ts` (its cart services can't depend on\n// canopy-sdk without a cycle); `cart-schema.spec.ts` keeps the two in lockstep.\n// This module is internal wire validation; public types live in `cart/cart-types`.\n\n// ---------------------------------------------------------------------------\n// Cart line attribute\n// ---------------------------------------------------------------------------\n\nexport const cartLineAttributeSchema = z.object({\n key: z.string(),\n value: z.union([z.string(), z.number(), z.boolean()]),\n});\n\nexport const cartLineAttributesSchema = z.array(cartLineAttributeSchema);\n\nexport type CartLineAttribute = z.infer<typeof cartLineAttributeSchema>;\n\n// ---------------------------------------------------------------------------\n// Image (cart-scoped; lightweight compared to objectType image)\n// ---------------------------------------------------------------------------\n\nexport const cartImageSchema = z.object({\n url: z.string(),\n altText: z.string().nullable(),\n});\n\nexport type CartImage = z.infer<typeof cartImageSchema>;\n\n// ---------------------------------------------------------------------------\n// Selling plan types\n// ---------------------------------------------------------------------------\n\n// Integer minor units (Stripe convention): 1999 = $19.99 USD. Mirrors\n// amountSchema in schemas/money.ts, which shipped code cannot import.\nconst amountSchema = z.number().int();\nconst amountWithCurrencyCodeSchema = z.object({\n amount: amountSchema,\n currencyCode: z.string(),\n});\n\nconst sellingPlanPriceAdjustmentSchema = z.object({\n compareAtPrice: amountWithCurrencyCodeSchema,\n perDeliveryPrice: amountWithCurrencyCodeSchema,\n price: amountWithCurrencyCodeSchema,\n unitPrice: amountWithCurrencyCodeSchema.nullable(),\n});\n\nconst sellingPlanAllocationSchema = z.object({\n sellingPlan: z.object({\n id: z.string(),\n name: z.string(),\n description: z.string().nullable(),\n }),\n priceAdjustments: z.array(sellingPlanPriceAdjustmentSchema),\n checkoutChargeAmount: amountWithCurrencyCodeSchema,\n remainingBalanceChargeAmount: amountWithCurrencyCodeSchema,\n});\n\n// ---------------------------------------------------------------------------\n// Cart line merchandise\n// ---------------------------------------------------------------------------\n\nexport const cartLineMerchandiseSchema = z.object({\n id: z.string(),\n product: z.object({\n id: z.string(),\n title: z.string(),\n }),\n title: z.string(),\n price: amountSchema,\n compareAtPrice: amountSchema.nullish(),\n image: cartImageSchema.nullable(),\n selectedOptions: z.array(z.object({ name: z.string(), value: z.string() })),\n});\n\nexport type CartLineMerchandise = z.infer<typeof cartLineMerchandiseSchema>;\n\n// ---------------------------------------------------------------------------\n// Cart line\n// ---------------------------------------------------------------------------\n\nexport const cartLineSchema = z.object({\n id: z.string(),\n quantity: z.number(),\n merchandise: cartLineMerchandiseSchema,\n attributes: z.array(cartLineAttributeSchema),\n sellingPlanAllocation: sellingPlanAllocationSchema.nullish(),\n});\n\nexport type CartLine = z.infer<typeof cartLineSchema>;\n\n// ---------------------------------------------------------------------------\n// Cart cost\n// ---------------------------------------------------------------------------\n\nexport const cartCostSchema = z.object({\n subtotalAmount: amountSchema,\n totalAmount: amountSchema,\n currencyCode: z.string(),\n});\n\nexport type CartCost = z.infer<typeof cartCostSchema>;\n\n// ---------------------------------------------------------------------------\n// Cart discount code\n// ---------------------------------------------------------------------------\n\nexport const cartDiscountCodeSchema = z.object({\n code: z.string(),\n applicable: z.boolean(),\n});\n\nexport type CartDiscountCode = z.infer<typeof cartDiscountCodeSchema>;\n\n// ---------------------------------------------------------------------------\n// Cart (top level)\n// ---------------------------------------------------------------------------\n\nexport const cartSchema = z.object({\n id: z.string(),\n lines: z.array(cartLineSchema),\n cost: cartCostSchema,\n checkoutUrl: z.string().optional(),\n discountCodes: z.array(cartDiscountCodeSchema).optional(),\n});\n\nexport type Cart = z.infer<typeof cartSchema>;\n\n// ---------------------------------------------------------------------------\n// Cart mutation input schemas (used by both resolver and SDK gateway)\n// ---------------------------------------------------------------------------\n\nexport const addCartLinesInputSchema = z.object({\n merchandiseId: z.string(),\n quantity: z.number().int().positive(),\n attributes: z.array(cartLineAttributeSchema).optional(),\n sellingPlanId: z.string().nullish(),\n});\n\nexport type AddCartLineInput = z.infer<typeof addCartLinesInputSchema>;\n\nexport const updateCartLineInputSchema = z.object({\n lineId: z.string(),\n quantity: z.number().int().min(0),\n attributes: z.array(cartLineAttributeSchema).optional(),\n sellingPlanId: z.string().nullish(),\n});\n\nexport type UpdateCartLineInput = z.infer<typeof updateCartLineInputSchema>;\n"],
5
+ "mappings": "AAAA,SAAS,SAAS;AAaX,MAAM,0BAA0B,EAAE,OAAO;AAAA,EAC9C,KAAK,EAAE,OAAO;AAAA,EACd,OAAO,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC;AACtD,CAAC;AAEM,MAAM,2BAA2B,EAAE,MAAM,uBAAuB;AAQhE,MAAM,kBAAkB,EAAE,OAAO;AAAA,EACtC,KAAK,EAAE,OAAO;AAAA,EACd,SAAS,EAAE,OAAO,EAAE,SAAS;AAC/B,CAAC;AAUD,MAAM,eAAe,EAAE,OAAO,EAAE,IAAI;AACpC,MAAM,+BAA+B,EAAE,OAAO;AAAA,EAC5C,QAAQ;AAAA,EACR,cAAc,EAAE,OAAO;AACzB,CAAC;AAED,MAAM,mCAAmC,EAAE,OAAO;AAAA,EAChD,gBAAgB;AAAA,EAChB,kBAAkB;AAAA,EAClB,OAAO;AAAA,EACP,WAAW,6BAA6B,SAAS;AACnD,CAAC;A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AO,EAAE,SAAS;AAAA,EACjC,eAAe,EAAE,MAAM,sBAAsB,EAAE,SAAS;AAC1D,CAAC;AAQM,MAAM,0BAA0B,EAAE,OAAO;AAAA,EAC9C,eAAe,EAAE,OAAO;AAAA,EACxB,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS;AAAA,EACpC,YAAY,EAAE,MAAM,uBAAuB,EAAE,SAAS;AAAA,EACtD,eAAe,EAAE,OAAO,EAAE,QAAQ;AACpC,CAAC;AAIM,MAAM,4BAA4B,EAAE,OAAO;AAAA,EAChD,QAAQ,EAAE,OAAO;AAAA,EACjB,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC;AAAA,EAChC,YAAY,EAAE,MAAM,uBAAuB,EAAE,SAAS;AAAA,EACtD,eAAe,EAAE,OAAO,EAAE,QAAQ;AACpC,CAAC;",
6
6
  "names": []
7
7
  }
@@ -1,6 +1,9 @@
1
1
  "use server";
2
2
  import { getCanopyApiGateway } from "../../gateways/canopy-api";
3
3
  class ResolverCartGateway {
4
+ // Returns the gateway's wire-parsed Cart where the client Cart is expected.
5
+ // Safe because client = wire + widenings only — enforced by the widening
6
+ // assertions in cart-schema.spec.ts.
4
7
  async getCart(cartId) {
5
8
  try {
6
9
  const gateway = await getCanopyApiGateway();
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../cart/gateways/resolver-cart-gateway.ts"],
4
- "sourcesContent": ["\"use server\";\n\nimport type {\n AddToCartPayload,\n Cart,\n CartLinePayload,\n RemoveFromCartPayload,\n UpdateCartDiscountCodesPayload,\n UpdateCartLineItemPayload,\n} from \"../cart-types\";\nimport type { CartGateway } from \"./cart-gateway\";\n\nimport { getCanopyApiGateway } from \"../../gateways/canopy-api\";\n\n/**\n * @author Ryan\n * CartGateway that delegates all mutations to the canopy-api's cart\n * endpoints. Used for \"externalCart\" integrations (Shopify). canopy-api\n * handles credential resolution and upstream API calls.\n */\nclass ResolverCartGateway implements CartGateway {\n async getCart(cartId: string): Promise<Cart | null> {\n try {\n const gateway = await getCanopyApiGateway();\n return await gateway.cartGet({ cartId });\n } catch (error) {\n console.warn(`Cart ${cartId} not found via canopy-api:`, error);\n return null;\n }\n }\n\n async createCart(\n lines?: CartLinePayload[],\n discountCodes?: string[],\n ): Promise<Cart | null> {\n try {\n const gateway = await getCanopyApiGateway();\n return await gateway.cartCreate({\n lines: lines?.map((line) => ({\n merchandiseId: line.id,\n quantity: line.quantity,\n attributes: line.properties?.map((prop) => ({\n key: prop.key,\n value: String(prop.value),\n })),\n sellingPlanId: line.sellingPlanId,\n })),\n discountCodes,\n });\n } catch (error) {\n console.warn(\"Failed to create cart via canopy-api:\", error);\n return null;\n }\n }\n\n async addToCart(cartPayload: AddToCartPayload): Promise<Cart | null> {\n try {\n const gateway = await getCanopyApiGateway();\n return await gateway.cartAddLines({\n cartId: cartPayload.cartId,\n lines: cartPayload.lines.map((line) => ({\n merchandiseId: line.id,\n quantity: line.quantity,\n attributes: line.properties?.map((prop) => ({\n key: prop.key,\n value: String(prop.value),\n })),\n sellingPlanId: line.sellingPlanId,\n })),\n });\n } catch (error) {\n console.warn(\"Failed to add to cart via canopy-api:\", error);\n return null;\n }\n }\n\n async updateCartLineItem(\n cartPayload: UpdateCartLineItemPayload,\n ): Promise<Cart | null> {\n try {\n const gateway = await getCanopyApiGateway();\n return await gateway.cartUpdateLines({\n cartId: cartPayload.cartId,\n lines: [\n {\n lineId: cartPayload.line.id,\n quantity: cartPayload.line.quantity,\n attributes: cartPayload.line.properties?.map((prop) => ({\n key: prop.key,\n value: String(prop.value),\n })),\n sellingPlanId: cartPayload.line.sellingPlanId,\n },\n ],\n });\n } catch (error) {\n console.warn(\"Failed to update cart line via canopy-api:\", error);\n return null;\n }\n }\n\n async removeCartLineItems(\n cartPayload: RemoveFromCartPayload,\n ): Promise<Cart | null> {\n try {\n const gateway = await getCanopyApiGateway();\n return await gateway.cartRemoveLines({\n cartId: cartPayload.cartId,\n lineIds: cartPayload.lineIds,\n });\n } catch (error) {\n console.warn(\"Failed to remove cart lines via canopy-api:\", error);\n return null;\n }\n }\n\n async updateCartDiscountCodes(\n cartPayload: UpdateCartDiscountCodesPayload,\n ): Promise<Cart | null> {\n try {\n const gateway = await getCanopyApiGateway();\n return await gateway.cartUpdateDiscountCodes({\n cartId: cartPayload.cartId,\n discountCodes: cartPayload.discountCodes,\n });\n } catch (error) {\n console.warn(\"Failed to update discount codes via canopy-api:\", error);\n return null;\n }\n }\n}\n\nexport async function createResolverCartGateway(): Promise<CartGateway> {\n return new ResolverCartGateway();\n}\n"],
5
- "mappings": ";AAYA,SAAS,2BAA2B;AAQpC,MAAM,oBAA2C;AAAA,EAC/C,MAAM,QAAQ,QAAsC;AAClD,QAAI;AACF,YAAM,UAAU,MAAM,oBAAoB;AAC1C,aAAO,MAAM,QAAQ,QAAQ,EAAE,OAAO,CAAC;AAAA,IACzC,SAAS,OAAO;AACd,cAAQ,KAAK,QAAQ,MAAM,8BAA8B,KAAK;AAC9D,aAAO;AAAA,IACT;AAAA,EACF;AAAA,EAEA,MAAM,WACJ,OACA,eACsB;AACtB,QAAI;AACF,YAAM,UAAU,MAAM,oBAAoB;AAC1C,aAAO,MAAM,QAAQ,WAAW;AAAA,QAC9B,OAAO,OAAO,IAAI,CAAC,UAAU;AAAA,UAC3B,eAAe,KAAK;AAAA,UACpB,UAAU,KAAK;AAAA,UACf,YAAY,KAAK,YAAY,IAAI,CAAC,UAAU;AAAA,YAC1C,KAAK,KAAK;AAAA,YACV,OAAO,OAAO,KAAK,KAAK;AAAA,UAC1B,EAAE;AAAA,UACF,eAAe,KAAK;AAAA,QACtB,EAAE;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH,SAAS,OAAO;AACd,cAAQ,KAAK,yCAAyC,KAAK;AAC3D,aAAO;AAAA,IACT;AAAA,EACF;AAAA,EAEA,MAAM,UAAU,aAAqD;AACnE,QAAI;AACF,YAAM,UAAU,MAAM,oBAAoB;AAC1C,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B;AACtB,QAAI;AACF,YAAM,UAAU,MAAM,oBAAoB;AAC1C,aAAO,MAAM,QAAQ,wBAAwB;AAAA,QAC3C,QAAQ,YAAY;AAAA,QACpB,eAAe,YAAY;AAAA,MAC7B,CAAC;AAAA,IACH,SAAS,OAAO;AACd,cAAQ,KAAK,mDAAmD,KAAK;AACrE,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEA,eAAsB,4BAAkD;AACtE,SAAO,IAAI,oBAAoB;AACjC;",
4
+ "sourcesContent": ["\"use server\";\n\nimport type {\n AddToCartPayload,\n Cart,\n CartLinePayload,\n RemoveFromCartPayload,\n UpdateCartDiscountCodesPayload,\n UpdateCartLineItemPayload,\n} from \"../cart-types\";\nimport type { CartGateway } from \"./cart-gateway\";\n\nimport { getCanopyApiGateway } from \"../../gateways/canopy-api\";\n\n/**\n * @author Ryan\n * CartGateway that delegates all mutations to the canopy-api's cart\n * endpoints. Used for \"externalCart\" integrations (Shopify). canopy-api\n * handles credential resolution and upstream API calls.\n */\nclass ResolverCartGateway implements CartGateway {\n // Returns the gateway's wire-parsed Cart where the client Cart is expected.\n // Safe because client = wire + widenings only \u2014 enforced by the widening\n // assertions in cart-schema.spec.ts.\n async getCart(cartId: string): Promise<Cart | null> {\n try {\n const gateway = await getCanopyApiGateway();\n return await gateway.cartGet({ cartId });\n } catch (error) {\n console.warn(`Cart ${cartId} not found via canopy-api:`, error);\n return null;\n }\n }\n\n async createCart(\n lines?: CartLinePayload[],\n discountCodes?: string[],\n ): Promise<Cart | null> {\n try {\n const gateway = await getCanopyApiGateway();\n return await gateway.cartCreate({\n lines: lines?.map((line) => ({\n merchandiseId: line.id,\n quantity: line.quantity,\n attributes: line.properties?.map((prop) => ({\n key: prop.key,\n value: String(prop.value),\n })),\n sellingPlanId: line.sellingPlanId,\n })),\n discountCodes,\n });\n } catch (error) {\n console.warn(\"Failed to create cart via canopy-api:\", error);\n return null;\n }\n }\n\n async addToCart(cartPayload: AddToCartPayload): Promise<Cart | null> {\n try {\n const gateway = await getCanopyApiGateway();\n return await gateway.cartAddLines({\n cartId: cartPayload.cartId,\n lines: cartPayload.lines.map((line) => ({\n merchandiseId: line.id,\n quantity: line.quantity,\n attributes: line.properties?.map((prop) => ({\n key: prop.key,\n value: String(prop.value),\n })),\n sellingPlanId: line.sellingPlanId,\n })),\n });\n } catch (error) {\n console.warn(\"Failed to add to cart via canopy-api:\", error);\n return null;\n }\n }\n\n async updateCartLineItem(\n cartPayload: UpdateCartLineItemPayload,\n ): Promise<Cart | null> {\n try {\n const gateway = await getCanopyApiGateway();\n return await gateway.cartUpdateLines({\n cartId: cartPayload.cartId,\n lines: [\n {\n lineId: cartPayload.line.id,\n quantity: cartPayload.line.quantity,\n attributes: cartPayload.line.properties?.map((prop) => ({\n key: prop.key,\n value: String(prop.value),\n })),\n sellingPlanId: cartPayload.line.sellingPlanId,\n },\n ],\n });\n } catch (error) {\n console.warn(\"Failed to update cart line via canopy-api:\", error);\n return null;\n }\n }\n\n async removeCartLineItems(\n cartPayload: RemoveFromCartPayload,\n ): Promise<Cart | null> {\n try {\n const gateway = await getCanopyApiGateway();\n return await gateway.cartRemoveLines({\n cartId: cartPayload.cartId,\n lineIds: cartPayload.lineIds,\n });\n } catch (error) {\n console.warn(\"Failed to remove cart lines via canopy-api:\", error);\n return null;\n }\n }\n\n async updateCartDiscountCodes(\n cartPayload: UpdateCartDiscountCodesPayload,\n ): Promise<Cart | null> {\n try {\n const gateway = await getCanopyApiGateway();\n return await gateway.cartUpdateDiscountCodes({\n cartId: cartPayload.cartId,\n discountCodes: cartPayload.discountCodes,\n });\n } catch (error) {\n console.warn(\"Failed to update discount codes via canopy-api:\", error);\n return null;\n }\n }\n}\n\nexport async function createResolverCartGateway(): Promise<CartGateway> {\n return new ResolverCartGateway();\n}\n"],
5
+ "mappings": ";AAYA,SAAS,2BAA2B;AAQpC,MAAM,oBAA2C;AAAA;AAAA;AAAA;AAAA,EAI/C,MAAM,QAAQ,QAAsC;AAClD,QAAI;A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,UAAU,MAAM,oBAAoB;AAC1C,aAAO,MAAM,QAAQ,gBAAgB;AAAA,QACnC,QAAQ,YAAY;AAAA,QACpB,OAAO;AAAA,UACL;AAAA,YACE,QAAQ,YAAY,KAAK;AAAA,YACzB,UAAU,YAAY,KAAK;AAAA,YAC3B,YAAY,YAAY,KAAK,YAAY,IAAI,CAAC,UAAU;AAAA,cACtD,KAAK,KAAK;AAAA,cACV,OAAO,OAAO,KAAK,KAAK;AAAA,YAC1B,EAAE;AAAA,YACF,eAAe,YAAY,KAAK;AAAA,UAClC;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH,SAAS,OAAO;AACd,cAAQ,KAAK,8CAA8C,KAAK;AAChE,aAAO;AAAA,IACT;AAAA,EACF;AAAA,EAEA,MAAM,oBACJ,aACsB;AACtB,QAAI;AACF,YAAM,UAAU,MAAM,oBAAoB;AAC1C,aAAO,MAAM,QAAQ,gBAAgB;AAAA,QACnC,QAAQ,YAAY;AAAA,QACpB,SAAS,YAAY;AAAA,MACvB,CAAC;AAAA,IACH,SAAS,OAAO;AACd,cAAQ,KAAK,+CAA+C,KAAK;AACjE,aAAO;AAAA,IACT;AAAA,EACF;AAAA,EAEA,MAAM,wBACJ,aACsB;AACtB,QAAI;AACF,YAAM,UAAU,MAAM,oBAAoB;AAC1C,aAAO,MAAM,QAAQ,wBAAwB;AAAA,QAC3C,QAAQ,YAAY;AAAA,QACpB,eAAe,YAAY;AAAA,MAC7B,CAAC;AAAA,IACH,SAAS,OAAO;AACd,cAAQ,KAAK,mDAAmD,KAAK;AACrE,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEA,eAAsB,4BAAkD;AACtE,SAAO,IAAI,oBAAoB;AACjC;",
6
6
  "names": []
7
7
  }
@@ -49,13 +49,13 @@ function LinkInterceptor() {
49
49
  return originalWindowOpen.call(window, url, target, features);
50
50
  };
51
51
  history.pushState = function(state, unused, url) {
52
- if (url != null && url !== "" && urlLeavesSandbox(url) === true) {
52
+ if (url && urlLeavesSandbox(url) === true) {
53
53
  return;
54
54
  }
55
55
  return originalPushState.call(history, state, unused, url);
56
56
  };
57
57
  history.replaceState = function(state, unused, url) {
58
- if (url != null && url !== "" && urlLeavesSandbox(url) === true) {
58
+ if (url && urlLeavesSandbox(url) === true) {
59
59
  return;
60
60
  }
61
61
  return originalReplaceState.call(history, state, unused, url);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../editor/LinkInterceptor.tsx"],
4
- "sourcesContent": ["\"use client\";\n\nimport { useEffect } from \"react\";\n\nimport { displayModeStore } from \"./select-mode/displayModeStore\";\n\ntype NavigationNavigateEvent = {\n destination?: { url?: string };\n preventDefault?: () => void;\n};\n\ntype NavigationLike = {\n addEventListener: (\n type: \"navigate\",\n listener: (event: NavigationNavigateEvent) => void,\n ) => void;\n removeEventListener: (\n type: \"navigate\",\n listener: (event: NavigationNavigateEvent) => void,\n ) => void;\n};\n\nfunction blockNavigation(event: MouseEvent) {\n event.preventDefault();\n event.stopPropagation();\n event.stopImmediatePropagation();\n}\n\nfunction isNavigationLike(value: unknown): value is NavigationLike {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n\n return (\n typeof Reflect.get(value, \"addEventListener\") === \"function\" &&\n typeof Reflect.get(value, \"removeEventListener\") === \"function\"\n );\n}\n\nfunction getWindowNavigation() {\n const navigation = Reflect.get(window, \"navigation\");\n return isNavigationLike(navigation) ? navigation : null;\n}\n\nfunction shouldInterceptNavigationForAgentPreview() {\n if (typeof window === \"undefined\") {\n return false;\n }\n\n if (window.parent === window) {\n return false;\n }\n\n return (\n new URLSearchParams(window.location.search).get(\"__reploAgentPreview\") ===\n \"1\"\n );\n}\n\nfunction urlLeavesSandbox(rawUrl: string | URL): boolean | null {\n try {\n const resolved =\n typeof rawUrl === \"string\"\n ? new URL(rawUrl, window.location.href)\n : new URL(rawUrl.href, window.location.href);\n return resolved.origin !== window.location.origin;\n } catch {\n return null;\n }\n}\n\nexport default function LinkInterceptor() {\n // eslint-disable-next-line replo/no-use-effect -- Browser navigation APIs must be patched at client runtime and restored when the interceptor unmounts.\n useEffect(() => {\n if (!shouldInterceptNavigationForAgentPreview()) {\n return;\n }\n\n const originalWindowOpen = window.open;\n const originalPushState = history.pushState;\n const originalReplaceState = history.replaceState;\n const navigation = getWindowNavigation();\n\n window.open = function (\n url?: string | URL,\n target?: string,\n features?: string,\n ) {\n if (url !== undefined && url !== \"\" && urlLeavesSandbox(url) === true) {\n return null;\n }\n\n return originalWindowOpen.call(window, url, target, features);\n };\n\n history.pushState = function (\n state: Parameters<History[\"pushState\"]>[0],\n unused: string,\n url?: string | URL | null,\n ) {\n if (url != null && url !== \"\" && urlLeavesSandbox(url) === true) {\n return;\n }\n\n return originalPushState.call(history, state, unused, url);\n };\n\n history.replaceState = function (\n state: Parameters<History[\"replaceState\"]>[0],\n unused: string,\n url?: string | URL | null,\n ) {\n if (url != null && url !== \"\" && urlLeavesSandbox(url) === true) {\n return;\n }\n\n return originalReplaceState.call(history, state, unused, url);\n };\n\n const handleNavigate = (event: NavigationNavigateEvent) => {\n const destinationUrl = event.destination?.url;\n if (\n destinationUrl === undefined ||\n destinationUrl === \"\" ||\n urlLeavesSandbox(destinationUrl) !== true\n ) {\n return;\n }\n\n event.preventDefault?.();\n };\n\n const handleClick = (event: MouseEvent) => {\n // While select mode is active a link click must select the element, not\n // navigate. `useSelectionInteractions` prevents the default nav, but this\n // sibling capture listener would still post `replo:navigate` and move the\n // preview off the page \u2014 `stopPropagation` there can't suppress a\n // listener on the same node, so we bail out here explicitly.\n if (displayModeStore.getSnapshot() === \"selection\") {\n return;\n }\n\n const target = event.target;\n\n if (!(target instanceof Element)) {\n return;\n }\n\n const link = target.closest(\"a[href]\");\n\n if (!(link instanceof HTMLAnchorElement)) {\n return;\n }\n\n const href = link.getAttribute(\"href\");\n if (!href) {\n return;\n }\n\n if (href.startsWith(\"#\")) {\n return;\n }\n\n const linkTarget = link.getAttribute(\"target\");\n if (linkTarget && linkTarget !== \"_self\") {\n blockNavigation(event);\n return;\n }\n\n if (urlLeavesSandbox(href) === true) {\n blockNavigation(event);\n return;\n }\n\n event.preventDefault();\n\n let route: string;\n try {\n route = new URL(href, window.location.href).pathname;\n } catch {\n route = href;\n }\n\n window.parent.postMessage(\n {\n type: \"replo:navigate\",\n route,\n },\n \"*\",\n );\n };\n\n navigation?.addEventListener(\"navigate\", handleNavigate);\n document.addEventListener(\"click\", handleClick, true);\n\n return () => {\n window.open = originalWindowOpen;\n history.pushState = originalPushState;\n history.replaceState = originalReplaceState;\n navigation?.removeEventListener(\"navigate\", handleNavigate);\n document.removeEventListener(\"click\", handleClick, true);\n };\n }, []);\n\n return null;\n}\n"],
5
- "mappings": ";AAEA,SAAS,iBAAiB;AAE1B,SAAS,wBAAwB;AAkBjC,SAAS,gBAAgB,OAAmB;AAC1C,QAAM,eAAe;AACrB,QAAM,gBAAgB;AACtB,QAAM,yBAAyB;AACjC;AAEA,SAAS,iBAAiB,OAAyC;AACjE,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO;AAAA,EACT;AAEA,SACE,OAAO,QAAQ,IAAI,OAAO,kBAAkB,MAAM,cAClD,OAAO,QAAQ,IAAI,OAAO,qBAAqB,MAAM;AAEzD;AAEA,SAAS,sBAAsB;AAC7B,QAAM,aAAa,QAAQ,IAAI,QAAQ,YAAY;AACnD,SAAO,iBAAiB,UAAU,IAAI,aAAa;AACrD;AAEA,SAAS,2CAA2C;AAClD,MAAI,OAAO,WAAW,aAAa;AACjC,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,WAAW,QAAQ;AAC5B,WAAO;AAAA,EACT;AAEA,SACE,IAAI,gBAAgB,OAAO,SAAS,MAAM,EAAE,IAAI,qBAAqB,MACrE;AAEJ;AAEA,SAAS,iBAAiB,QAAsC;AAC9D,MAAI;AACF,UAAM,WACJ,OAAO,WAAW,WACd,IAAI,IAAI,QAAQ,OAAO,SAAS,IAAI,IACpC,IAAI,IAAI,OAA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O,OAAO,QAAQ,SAAS;AAErC,UAAI,EAAE,gBAAgB,oBAAoB;AACxC;AAAA,MACF;AAEA,YAAM,OAAO,KAAK,aAAa,MAAM;AACrC,UAAI,CAAC,MAAM;AACT;AAAA,MACF;AAEA,UAAI,KAAK,WAAW,GAAG,GAAG;AACxB;AAAA,MACF;AAEA,YAAM,aAAa,KAAK,aAAa,QAAQ;AAC7C,UAAI,cAAc,eAAe,SAAS;AACxC,wBAAgB,KAAK;AACrB;AAAA,MACF;AAEA,UAAI,iBAAiB,IAAI,MAAM,MAAM;AACnC,wBAAgB,KAAK;AACrB;AAAA,MACF;AAEA,YAAM,eAAe;AAErB,UAAI;AACJ,UAAI;AACF,gBAAQ,IAAI,IAAI,MAAM,OAAO,SAAS,IAAI,EAAE;AAAA,MAC9C,QAAQ;AACN,gBAAQ;AAAA,MACV;AAEA,aAAO,OAAO;AAAA,QACZ;AAAA,UACE,MAAM;AAAA,UACN;AAAA,QACF;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,gBAAY,iBAAiB,YAAY,cAAc;AACvD,aAAS,iBAAiB,SAAS,aAAa,IAAI;AAEpD,WAAO,MAAM;AACX,aAAO,OAAO;AACd,cAAQ,YAAY;AACpB,cAAQ,eAAe;AACvB,kBAAY,oBAAoB,YAAY,cAAc;AAC1D,eAAS,oBAAoB,SAAS,aAAa,IAAI;AAAA,IACzD;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;",
4
+ "sourcesContent": ["\"use client\";\n\nimport { useEffect } from \"react\";\n\nimport { displayModeStore } from \"./select-mode/displayModeStore\";\n\ntype NavigationNavigateEvent = {\n destination?: { url?: string };\n preventDefault?: () => void;\n};\n\ntype NavigationLike = {\n addEventListener: (\n type: \"navigate\",\n listener: (event: NavigationNavigateEvent) => void,\n ) => void;\n removeEventListener: (\n type: \"navigate\",\n listener: (event: NavigationNavigateEvent) => void,\n ) => void;\n};\n\nfunction blockNavigation(event: MouseEvent) {\n event.preventDefault();\n event.stopPropagation();\n event.stopImmediatePropagation();\n}\n\nfunction isNavigationLike(value: unknown): value is NavigationLike {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n\n return (\n typeof Reflect.get(value, \"addEventListener\") === \"function\" &&\n typeof Reflect.get(value, \"removeEventListener\") === \"function\"\n );\n}\n\nfunction getWindowNavigation() {\n const navigation = Reflect.get(window, \"navigation\");\n return isNavigationLike(navigation) ? navigation : null;\n}\n\nfunction shouldInterceptNavigationForAgentPreview() {\n if (typeof window === \"undefined\") {\n return false;\n }\n\n if (window.parent === window) {\n return false;\n }\n\n return (\n new URLSearchParams(window.location.search).get(\"__reploAgentPreview\") ===\n \"1\"\n );\n}\n\nfunction urlLeavesSandbox(rawUrl: string | URL): boolean | null {\n try {\n const resolved =\n typeof rawUrl === \"string\"\n ? new URL(rawUrl, window.location.href)\n : new URL(rawUrl.href, window.location.href);\n return resolved.origin !== window.location.origin;\n } catch {\n return null;\n }\n}\n\nexport default function LinkInterceptor() {\n // eslint-disable-next-line replo/no-use-effect -- Browser navigation APIs must be patched at client runtime and restored when the interceptor unmounts.\n useEffect(() => {\n if (!shouldInterceptNavigationForAgentPreview()) {\n return;\n }\n\n const originalWindowOpen = window.open;\n const originalPushState = history.pushState;\n const originalReplaceState = history.replaceState;\n const navigation = getWindowNavigation();\n\n window.open = function (\n url?: string | URL,\n target?: string,\n features?: string,\n ) {\n if (url !== undefined && url !== \"\" && urlLeavesSandbox(url) === true) {\n return null;\n }\n\n return originalWindowOpen.call(window, url, target, features);\n };\n\n history.pushState = function (\n state: Parameters<History[\"pushState\"]>[0],\n unused: string,\n url?: string | URL | null,\n ) {\n if (url && urlLeavesSandbox(url) === true) {\n return;\n }\n\n return originalPushState.call(history, state, unused, url);\n };\n\n history.replaceState = function (\n state: Parameters<History[\"replaceState\"]>[0],\n unused: string,\n url?: string | URL | null,\n ) {\n if (url && urlLeavesSandbox(url) === true) {\n return;\n }\n\n return originalReplaceState.call(history, state, unused, url);\n };\n\n const handleNavigate = (event: NavigationNavigateEvent) => {\n const destinationUrl = event.destination?.url;\n if (\n destinationUrl === undefined ||\n destinationUrl === \"\" ||\n urlLeavesSandbox(destinationUrl) !== true\n ) {\n return;\n }\n\n event.preventDefault?.();\n };\n\n const handleClick = (event: MouseEvent) => {\n // While select mode is active a link click must select the element, not\n // navigate. `useSelectionInteractions` prevents the default nav, but this\n // sibling capture listener would still post `replo:navigate` and move the\n // preview off the page \u2014 `stopPropagation` there can't suppress a\n // listener on the same node, so we bail out here explicitly.\n if (displayModeStore.getSnapshot() === \"selection\") {\n return;\n }\n\n const target = event.target;\n\n if (!(target instanceof Element)) {\n return;\n }\n\n const link = target.closest(\"a[href]\");\n\n if (!(link instanceof HTMLAnchorElement)) {\n return;\n }\n\n const href = link.getAttribute(\"href\");\n if (!href) {\n return;\n }\n\n if (href.startsWith(\"#\")) {\n return;\n }\n\n const linkTarget = link.getAttribute(\"target\");\n if (linkTarget && linkTarget !== \"_self\") {\n blockNavigation(event);\n return;\n }\n\n if (urlLeavesSandbox(href) === true) {\n blockNavigation(event);\n return;\n }\n\n event.preventDefault();\n\n let route: string;\n try {\n route = new URL(href, window.location.href).pathname;\n } catch {\n route = href;\n }\n\n window.parent.postMessage(\n {\n type: \"replo:navigate\",\n route,\n },\n \"*\",\n );\n };\n\n navigation?.addEventListener(\"navigate\", handleNavigate);\n document.addEventListener(\"click\", handleClick, true);\n\n return () => {\n window.open = originalWindowOpen;\n history.pushState = originalPushState;\n history.replaceState = originalReplaceState;\n navigation?.removeEventListener(\"navigate\", handleNavigate);\n document.removeEventListener(\"click\", handleClick, true);\n };\n }, []);\n\n return null;\n}\n"],
5
+ "mappings": ";AAEA,SAAS,iBAAiB;AAE1B,SAAS,wBAAwB;AAkBjC,SAAS,gBAAgB,OAAmB;AAC1C,QAAM,eAAe;AACrB,QAAM,gBAAgB;AACtB,QAAM,yBAAyB;AACjC;AAEA,SAAS,iBAAiB,OAAyC;AACjE,MAAI,OAAO,UAAU,YAAY,UAAU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a,IAAI;AAEpD,WAAO,MAAM;AACX,aAAO,OAAO;AACd,cAAQ,YAAY;AACpB,cAAQ,eAAe;AACvB,kBAAY,oBAAoB,YAAY,cAAc;AAC1D,eAAS,oBAAoB,SAAS,aAAa,IAAI;AAAA,IACzD;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,4 @@
1
+ import { isNullish } from "../../_vendor/replo-utils/lib/misc.mjs";
1
2
  const SYMBOLICATE_ENDPOINT = "/__nextjs_original-stack-frames";
2
3
  function isLikelyCompiledLocation(location) {
3
4
  if (!location) {
@@ -136,7 +137,7 @@ function applyResolved({
136
137
  original,
137
138
  frame
138
139
  }) {
139
- if (!frame || !frame.file || frame.line1 == null) {
140
+ if (!frame || !frame.file || isNullish(frame.line1)) {
140
141
  return original;
141
142
  }
142
143
  return {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../editor/select-mode/symbolicate.ts"],
4
- "sourcesContent": ["import type {\n SelectedElement,\n SelectModeFiberChainEntry,\n SelectModeSourceLocation,\n} from \"schemas/generated/selectMode\";\n\n/**\n * Runtime source-attribution for React 19 + Next.js Turbopack.\n *\n * React 19 removed `fiber._debugSource`; the only per-element source pointer\n * left is `fiber._debugStack`, whose `.stack` references compiled SSR/client\n * chunks. We POST those compiled frames to Next.js's dev-only\n * `/__nextjs_original-stack-frames` endpoint, which symbolicates them through\n * Turbopack's in-memory source maps \u2014 the same mechanism the Next error\n * overlay uses (see `next/dist/server/dev/middleware-turbopack.js`).\n */\n\ntype NextStackFrame = {\n file: string | null;\n methodName: string | null;\n arguments: string[];\n // Next.js's `/__nextjs_original-stack-frames` reads these as `line1`/`column1`\n // (1-based) in the request body \u2014 same field names it uses in the response.\n // Sending `lineNumber`/`column` is silently dropped on the server side.\n line1: number | null;\n column1: number | null;\n};\n\ntype ResolvedFrame = {\n file: string | null;\n line1?: number | null;\n column1?: number | null;\n methodName?: string | null;\n ignored?: boolean;\n arguments?: string[];\n};\n\ntype OriginalStackFrameResponse = {\n originalStackFrame: ResolvedFrame | null;\n originalCodeFrame: string | null;\n};\n\ntype SettledResponseEntry =\n | { status: \"fulfilled\"; value: OriginalStackFrameResponse }\n | { status: \"rejected\"; reason: string };\n\nconst SYMBOLICATE_ENDPOINT = \"/__nextjs_original-stack-frames\";\n\nfunction isLikelyCompiledLocation(\n location: SelectModeSourceLocation | undefined,\n): boolean {\n if (!location) {\n return false;\n }\n const filePath = location.filePath;\n return (\n filePath.includes(\".next\") ||\n filePath.includes(\"/chunks/\") ||\n filePath.includes(\"webpack-internal:\") ||\n filePath.includes(\"turbopack:\") ||\n filePath.endsWith(\".js\") ||\n filePath.startsWith(\"about:\")\n );\n}\n\n// A resolved source that lives in a dependency or framework internal is never\n// the user's own code. The canonical case is Next's `<Image>`, whose rendered\n// `<img>` symbolicates to\n// `.../node_modules/next/src/client/image-component.tsx` \u2014 useless as an edit\n// target. We skip these and keep walking the ownership chain toward the user's\n// call site. See (Noah, 2026-07-09, REPL-29098).\nfunction isDependencyOrInternalPath(filePath: string): boolean {\n return (\n filePath.includes(\"node_modules\") ||\n filePath.includes(\"/dist/compiled/\") ||\n filePath.startsWith(\"about:\")\n );\n}\n\n// React 19 fibers for server-rendered (RSC) elements carry a `_debugStack`\n// whose top frame points at an SSR chunk (e.g. `about://React/Server/file://\n// .../.next-dev/.../server/chunks/ssr/*.js`). The endpoint resolves those\n// against the server bundler context; client chunks go through the client\n// bundler context. Mis-routing returns the compiled chunk unchanged.\nfunction isServerChunk(filePath: string): boolean {\n return (\n filePath.startsWith(\"about://React/Server\") ||\n filePath.includes(\"/server/chunks/\") ||\n filePath.includes(\".next-dev/dev/server/\") ||\n filePath.includes(\".next/server/\")\n );\n}\n\n// Matches the `/_next/static/...` tail of a browser chunk URL's pathname.\n// Capture group 1 is the `/static/...` segment that lives under the dist dir\n// on disk. Mirrors `regexNextStatic` in\n// `next/dist/server/lib/parse-stack.js`.\nconst NEXT_STATIC_PATH_PATTERN = /\\/_next(\\/static\\/.+)/;\n\n// Absolute path to the dev dist dir (e.g.\n// `/workspace/dev/website/.next-dev/dev`). Next.js define-injects this into\n// dev client bundles (see the `__NEXT_DIST_DIR` define in\n// `next/dist/build/define-env.ts`); because canopy-sdk is transpiled into the\n// host Next app, the replacement reaches this reference too. Outside a Next\n// dev client build the value is absent, so we bail and leave the URL as-is.\nfunction getNextDistDir(): string | null {\n try {\n const distDir = process.env.__NEXT_DIST_DIR;\n return typeof distDir === \"string\" && distDir.length > 0 ? distDir : null;\n } catch {\n return null;\n }\n}\n\n// Turbopack's `/__nextjs_original-stack-frames` backend only resolves source\n// maps for `file://` (or bare filesystem) paths \u2014 it rejects browser chunk\n// URLs (`https://host/_next/static/chunks/X.js`) with \"Unknown url scheme\",\n// which is why client-component frames never symbolicated in the sandbox\n// (everything is served over https) even though it worked for RSC frames that\n// already carry filesystem paths. Rewrite the URL to the on-disk dist path the\n// same way Next's own server-side stack parser does, so the endpoint can map\n// it back to the user's `.tsx`.\nfunction rewriteBrowserChunkUrlToDistPath(filePath: string): string {\n if (!/^https?:\\/\\//.test(filePath)) {\n return filePath;\n }\n const distDir = getNextDistDir();\n if (!distDir) {\n return filePath;\n }\n let url: URL;\n try {\n url = new URL(filePath);\n } catch {\n return filePath;\n }\n const staticPathMatch = NEXT_STATIC_PATH_PATTERN.exec(url.pathname);\n if (!staticPathMatch?.[1]) {\n return filePath;\n }\n const normalizedDistDir = distDir.replace(/\\\\/g, \"/\").replace(/\\/$/, \"\");\n return `file://${normalizedDistDir}${staticPathMatch[1]}${url.search}`;\n}\n\n// React 19's `_debugStack.stack` for RSC components wraps the SSR chunk URL\n// in an `about://React/Server/` prefix and appends a `?<digits>` cache-buster\n// (e.g. `about://React/Server/file:///.../[root-of-the-server]__abc._.js?21`).\n// Turbopack's source-map lookup matches against the bare chunk URL; with\n// either decoration in place it returns the compiled chunk unchanged. Client\n// components instead carry a plain browser chunk URL, which Turbopack rejects\n// outright unless rewritten to its on-disk `file://` path.\nfunction normalizeFilePathForSymbolicator(filePath: string): string {\n let normalized = filePath;\n if (normalized.startsWith(\"about://React/Server/\")) {\n normalized = normalized.slice(\"about://React/Server/\".length);\n }\n normalized = normalized.replace(/\\?\\d+$/, \"\");\n return rewriteBrowserChunkUrlToDistPath(normalized);\n}\n\nfunction toNextStackFrame(location: SelectModeSourceLocation): NextStackFrame {\n return {\n file: normalizeFilePathForSymbolicator(location.filePath),\n methodName: location.componentName ?? null,\n arguments: [],\n line1: location.lineNumber,\n column1: location.columnNumber ?? null,\n };\n}\n\nfunction extractResolvedFrame(\n entry: SettledResponseEntry | null,\n): ResolvedFrame | null {\n if (!entry || entry.status !== \"fulfilled\") {\n return null;\n }\n return entry.value?.originalStackFrame ?? null;\n}\n\nasync function postFrames({\n frames,\n isServer,\n}: {\n frames: NextStackFrame[];\n isServer: boolean;\n}): Promise<(SettledResponseEntry | null)[]> {\n if (frames.length === 0) {\n return [];\n }\n try {\n const response = await fetch(SYMBOLICATE_ENDPOINT, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n frames,\n isServer,\n isEdgeServer: false,\n isAppDirectory: true,\n }),\n });\n if (!response.ok) {\n console.log(\"[selectMode] symbolicate: endpoint returned non-OK status\", {\n status: response.status,\n isServer,\n });\n return frames.map(() => null);\n }\n const parsed: unknown = await response.json();\n if (Array.isArray(parsed)) {\n // Promise.allSettled-shaped entries; see\n // node_modules/next/dist/server/dev/middleware-turbopack.js.\n // Legacy cast - the runtime shape isn't exported as a type.\n // eslint-disable-next-line replo/no-as-cast\n return parsed as (SettledResponseEntry | null)[];\n }\n return frames.map(() => null);\n } catch (error) {\n console.log(\"[selectMode] symbolicate: fetch failed\", {\n isServer,\n error,\n });\n return frames.map(() => null);\n }\n}\n\nasync function symbolicateFrames(\n frames: NextStackFrame[],\n): Promise<(SettledResponseEntry | null)[]> {\n const serverIndices: number[] = [];\n const clientIndices: number[] = [];\n for (const [index, frame] of frames.entries()) {\n if (frame.file && isServerChunk(frame.file)) {\n serverIndices.push(index);\n } else {\n clientIndices.push(index);\n }\n }\n\n const [serverResults, clientResults] = await Promise.all([\n postFrames({\n frames: serverIndices.map((index) => frames[index]!),\n isServer: true,\n }),\n postFrames({\n frames: clientIndices.map((index) => frames[index]!),\n isServer: false,\n }),\n ]);\n\n const merged: (SettledResponseEntry | null)[] = frames.map(() => null);\n for (const [position, index] of serverIndices.entries()) {\n merged[index] = serverResults[position] ?? null;\n }\n for (const [position, index] of clientIndices.entries()) {\n merged[index] = clientResults[position] ?? null;\n }\n return merged;\n}\n\nfunction applyResolved({\n original,\n frame,\n}: {\n original: SelectModeSourceLocation;\n frame: ResolvedFrame | null;\n}): SelectModeSourceLocation {\n if (!frame || !frame.file || frame.line1 == null) {\n return original;\n }\n return {\n filePath: frame.file,\n lineNumber: frame.line1,\n columnNumber: frame.column1 ?? undefined,\n componentName: original.componentName,\n };\n}\n\n// The innermost chain entry that is a usable edit target: already-symbolicated\n// (still-compiled frames failed to resolve and are useless) and outside\n// dependency/framework code. See (Noah, 2026-07-09, REPL-29098).\nfunction findUserSourceLocation(\n fiberChain: SelectModeFiberChainEntry[],\n): SelectModeSourceLocation | undefined {\n return fiberChain.find((entry) => {\n return (\n !isLikelyCompiledLocation(entry.sourceLocation) &&\n !isDependencyOrInternalPath(entry.sourceLocation.filePath)\n );\n })?.sourceLocation;\n}\n\nexport async function symbolicateSelectedElement(\n selectedElement: SelectedElement,\n): Promise<SelectedElement> {\n const targets: {\n location: SelectModeSourceLocation;\n apply: (next: SelectModeSourceLocation) => void;\n }[] = [];\n\n const fiberChain: SelectModeFiberChainEntry[] =\n selectedElement.fiberChain.map((entry) => ({ ...entry }));\n for (const entry of fiberChain) {\n if (isLikelyCompiledLocation(entry.sourceLocation)) {\n targets.push({\n location: entry.sourceLocation,\n apply: (next) => {\n entry.sourceLocation = next;\n },\n });\n }\n }\n\n let sourceLocation = selectedElement.sourceLocation;\n // With a chain present `sourceLocation` is re-derived from it below, so\n // targeting it here would just duplicate the chain head's round trip.\n if (\n fiberChain.length === 0 &&\n sourceLocation &&\n isLikelyCompiledLocation(sourceLocation)\n ) {\n const captured = sourceLocation;\n targets.push({\n location: captured,\n apply: (next) => {\n sourceLocation = next;\n },\n });\n }\n\n if (targets.length === 0) {\n return selectedElement;\n }\n\n const resolved = await symbolicateFrames(\n targets.map((target) => toNextStackFrame(target.location)),\n );\n\n for (const [index, target] of targets.entries()) {\n const frame = extractResolvedFrame(resolved[index] ?? null);\n target.apply(applyResolved({ original: target.location, frame }));\n }\n\n if (fiberChain.length > 0) {\n // Fall back to the chain head so we never regress to attributing nothing.\n sourceLocation =\n findUserSourceLocation(fiberChain) ?? fiberChain[0]!.sourceLocation;\n }\n\n return {\n ...selectedElement,\n sourceLocation,\n fiberChain,\n };\n}\n"],
5
- "mappings": "AA8CA,MAAM,uBAAuB;AAE7B,SAAS,yBACP,UACS;AACT,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AACA,QAAM,WAAW,SAAS;AAC1B,SACE,SAAS,SAAS,OAAO,KACzB,SAAS,SAAS,UAAU,KAC5B,SAAS,SAAS,mBAAmB,KACrC,SAAS,SAAS,YAAY,KAC9B,SAAS,SAAS,KAAK,KACvB,SAAS,WAAW,QAAQ;AAEhC;AAQA,SAAS,2BAA2B,UAA2B;AAC7D,SACE,SAAS,SAAS,cAAc,KAChC,SAAS,SAAS,iBAAiB,KACnC,SAAS,WAAW,QAAQ;AAEhC;AAOA,SAAS,cAAc,UAA2B;AAChD,SACE,SAAS,WAAW,sBAAsB,KAC1C,SAAS,SAAS,iBAAiB,KACnC,SAAS,SAAS,uBAAuB,KACzC,SAAS,SAAS,eAAe;AAErC;AAMA,MAAM,2BAA2B;AAQjC,SAAS,iBAAgC;AACvC,MAAI;AACF,UAAM,UAAU,QAAQ,IAAI;AAC5B,WAAO,OAAO,YAAY,YAAY,QAAQ,SAAS,IAAI,UAAU;AAAA,EACv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,MACnB;AAAA,IACF,CAAC;AAAA,EACH;AAEA,MAAI,QAAQ,WAAW,GAAG;AACxB,WAAO;AAAA,EACT;AAEA,QAAM,WAAW,MAAM;AAAA,IACrB,QAAQ,IAAI,CAAC,WAAW,iBAAiB,OAAO,QAAQ,CAAC;AAAA,EAC3D;AAEA,aAAW,CAAC,OAAO,MAAM,KAAK,QAAQ,QAAQ,GAAG;AAC/C,UAAM,QAAQ,qBAAqB,SAAS,KAAK,KAAK,IAAI;AAC1D,WAAO,MAAM,cAAc,EAAE,UAAU,OAAO,UAAU,MAAM,CAAC,CAAC;AAAA,EAClE;AAEA,MAAI,WAAW,SAAS,GAAG;AAEzB,qBACE,uBAAuB,UAAU,KAAK,WAAW,CAAC,EAAG;AAAA,EACzD;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import type {\n SelectedElement,\n SelectModeFiberChainEntry,\n SelectModeSourceLocation,\n} from \"schemas/generated/selectMode\";\n\nimport { isNullish } from \"replo-utils/lib/misc\";\n\n/**\n * Runtime source-attribution for React 19 + Next.js Turbopack.\n *\n * React 19 removed `fiber._debugSource`; the only per-element source pointer\n * left is `fiber._debugStack`, whose `.stack` references compiled SSR/client\n * chunks. We POST those compiled frames to Next.js's dev-only\n * `/__nextjs_original-stack-frames` endpoint, which symbolicates them through\n * Turbopack's in-memory source maps \u2014 the same mechanism the Next error\n * overlay uses (see `next/dist/server/dev/middleware-turbopack.js`).\n */\n\ntype NextStackFrame = {\n file: string | null;\n methodName: string | null;\n arguments: string[];\n // Next.js's `/__nextjs_original-stack-frames` reads these as `line1`/`column1`\n // (1-based) in the request body \u2014 same field names it uses in the response.\n // Sending `lineNumber`/`column` is silently dropped on the server side.\n line1: number | null;\n column1: number | null;\n};\n\ntype ResolvedFrame = {\n file: string | null;\n line1?: number | null;\n column1?: number | null;\n methodName?: string | null;\n ignored?: boolean;\n arguments?: string[];\n};\n\ntype OriginalStackFrameResponse = {\n originalStackFrame: ResolvedFrame | null;\n originalCodeFrame: string | null;\n};\n\ntype SettledResponseEntry =\n | { status: \"fulfilled\"; value: OriginalStackFrameResponse }\n | { status: \"rejected\"; reason: string };\n\nconst SYMBOLICATE_ENDPOINT = \"/__nextjs_original-stack-frames\";\n\nfunction isLikelyCompiledLocation(\n location: SelectModeSourceLocation | undefined,\n): boolean {\n if (!location) {\n return false;\n }\n const filePath = location.filePath;\n return (\n filePath.includes(\".next\") ||\n filePath.includes(\"/chunks/\") ||\n filePath.includes(\"webpack-internal:\") ||\n filePath.includes(\"turbopack:\") ||\n filePath.endsWith(\".js\") ||\n filePath.startsWith(\"about:\")\n );\n}\n\n// A resolved source that lives in a dependency or framework internal is never\n// the user's own code. The canonical case is Next's `<Image>`, whose rendered\n// `<img>` symbolicates to\n// `.../node_modules/next/src/client/image-component.tsx` \u2014 useless as an edit\n// target. We skip these and keep walking the ownership chain toward the user's\n// call site. See (Noah, 2026-07-09, REPL-29098).\nfunction isDependencyOrInternalPath(filePath: string): boolean {\n return (\n filePath.includes(\"node_modules\") ||\n filePath.includes(\"/dist/compiled/\") ||\n filePath.startsWith(\"about:\")\n );\n}\n\n// React 19 fibers for server-rendered (RSC) elements carry a `_debugStack`\n// whose top frame points at an SSR chunk (e.g. `about://React/Server/file://\n// .../.next-dev/.../server/chunks/ssr/*.js`). The endpoint resolves those\n// against the server bundler context; client chunks go through the client\n// bundler context. Mis-routing returns the compiled chunk unchanged.\nfunction isServerChunk(filePath: string): boolean {\n return (\n filePath.startsWith(\"about://React/Server\") ||\n filePath.includes(\"/server/chunks/\") ||\n filePath.includes(\".next-dev/dev/server/\") ||\n filePath.includes(\".next/server/\")\n );\n}\n\n// Matches the `/_next/static/...` tail of a browser chunk URL's pathname.\n// Capture group 1 is the `/static/...` segment that lives under the dist dir\n// on disk. Mirrors `regexNextStatic` in\n// `next/dist/server/lib/parse-stack.js`.\nconst NEXT_STATIC_PATH_PATTERN = /\\/_next(\\/static\\/.+)/;\n\n// Absolute path to the dev dist dir (e.g.\n// `/workspace/dev/website/.next-dev/dev`). Next.js define-injects this into\n// dev client bundles (see the `__NEXT_DIST_DIR` define in\n// `next/dist/build/define-env.ts`); because canopy-sdk is transpiled into the\n// host Next app, the replacement reaches this reference too. Outside a Next\n// dev client build the value is absent, so we bail and leave the URL as-is.\nfunction getNextDistDir(): string | null {\n try {\n const distDir = process.env.__NEXT_DIST_DIR;\n return typeof distDir === \"string\" && distDir.length > 0 ? distDir : null;\n } catch {\n return null;\n }\n}\n\n// Turbopack's `/__nextjs_original-stack-frames` backend only resolves source\n// maps for `file://` (or bare filesystem) paths \u2014 it rejects browser chunk\n// URLs (`https://host/_next/static/chunks/X.js`) with \"Unknown url scheme\",\n// which is why client-component frames never symbolicated in the sandbox\n// (everything is served over https) even though it worked for RSC frames that\n// already carry filesystem paths. Rewrite the URL to the on-disk dist path the\n// same way Next's own server-side stack parser does, so the endpoint can map\n// it back to the user's `.tsx`.\nfunction rewriteBrowserChunkUrlToDistPath(filePath: string): string {\n if (!/^https?:\\/\\//.test(filePath)) {\n return filePath;\n }\n const distDir = getNextDistDir();\n if (!distDir) {\n return filePath;\n }\n let url: URL;\n try {\n url = new URL(filePath);\n } catch {\n return filePath;\n }\n const staticPathMatch = NEXT_STATIC_PATH_PATTERN.exec(url.pathname);\n if (!staticPathMatch?.[1]) {\n return filePath;\n }\n const normalizedDistDir = distDir.replace(/\\\\/g, \"/\").replace(/\\/$/, \"\");\n return `file://${normalizedDistDir}${staticPathMatch[1]}${url.search}`;\n}\n\n// React 19's `_debugStack.stack` for RSC components wraps the SSR chunk URL\n// in an `about://React/Server/` prefix and appends a `?<digits>` cache-buster\n// (e.g. `about://React/Server/file:///.../[root-of-the-server]__abc._.js?21`).\n// Turbopack's source-map lookup matches against the bare chunk URL; with\n// either decoration in place it returns the compiled chunk unchanged. Client\n// components instead carry a plain browser chunk URL, which Turbopack rejects\n// outright unless rewritten to its on-disk `file://` path.\nfunction normalizeFilePathForSymbolicator(filePath: string): string {\n let normalized = filePath;\n if (normalized.startsWith(\"about://React/Server/\")) {\n normalized = normalized.slice(\"about://React/Server/\".length);\n }\n normalized = normalized.replace(/\\?\\d+$/, \"\");\n return rewriteBrowserChunkUrlToDistPath(normalized);\n}\n\nfunction toNextStackFrame(location: SelectModeSourceLocation): NextStackFrame {\n return {\n file: normalizeFilePathForSymbolicator(location.filePath),\n methodName: location.componentName ?? null,\n arguments: [],\n line1: location.lineNumber,\n column1: location.columnNumber ?? null,\n };\n}\n\nfunction extractResolvedFrame(\n entry: SettledResponseEntry | null,\n): ResolvedFrame | null {\n if (!entry || entry.status !== \"fulfilled\") {\n return null;\n }\n return entry.value?.originalStackFrame ?? null;\n}\n\nasync function postFrames({\n frames,\n isServer,\n}: {\n frames: NextStackFrame[];\n isServer: boolean;\n}): Promise<(SettledResponseEntry | null)[]> {\n if (frames.length === 0) {\n return [];\n }\n try {\n const response = await fetch(SYMBOLICATE_ENDPOINT, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n frames,\n isServer,\n isEdgeServer: false,\n isAppDirectory: true,\n }),\n });\n if (!response.ok) {\n console.log(\"[selectMode] symbolicate: endpoint returned non-OK status\", {\n status: response.status,\n isServer,\n });\n return frames.map(() => null);\n }\n const parsed: unknown = await response.json();\n if (Array.isArray(parsed)) {\n // Promise.allSettled-shaped entries; see\n // node_modules/next/dist/server/dev/middleware-turbopack.js.\n // Legacy cast - the runtime shape isn't exported as a type.\n // eslint-disable-next-line replo/no-as-cast\n return parsed as (SettledResponseEntry | null)[];\n }\n return frames.map(() => null);\n } catch (error) {\n console.log(\"[selectMode] symbolicate: fetch failed\", {\n isServer,\n error,\n });\n return frames.map(() => null);\n }\n}\n\nasync function symbolicateFrames(\n frames: NextStackFrame[],\n): Promise<(SettledResponseEntry | null)[]> {\n const serverIndices: number[] = [];\n const clientIndices: number[] = [];\n for (const [index, frame] of frames.entries()) {\n if (frame.file && isServerChunk(frame.file)) {\n serverIndices.push(index);\n } else {\n clientIndices.push(index);\n }\n }\n\n const [serverResults, clientResults] = await Promise.all([\n postFrames({\n frames: serverIndices.map((index) => frames[index]!),\n isServer: true,\n }),\n postFrames({\n frames: clientIndices.map((index) => frames[index]!),\n isServer: false,\n }),\n ]);\n\n const merged: (SettledResponseEntry | null)[] = frames.map(() => null);\n for (const [position, index] of serverIndices.entries()) {\n merged[index] = serverResults[position] ?? null;\n }\n for (const [position, index] of clientIndices.entries()) {\n merged[index] = clientResults[position] ?? null;\n }\n return merged;\n}\n\nfunction applyResolved({\n original,\n frame,\n}: {\n original: SelectModeSourceLocation;\n frame: ResolvedFrame | null;\n}): SelectModeSourceLocation {\n if (!frame || !frame.file || isNullish(frame.line1)) {\n return original;\n }\n return {\n filePath: frame.file,\n lineNumber: frame.line1,\n columnNumber: frame.column1 ?? undefined,\n componentName: original.componentName,\n };\n}\n\n// The innermost chain entry that is a usable edit target: already-symbolicated\n// (still-compiled frames failed to resolve and are useless) and outside\n// dependency/framework code. See (Noah, 2026-07-09, REPL-29098).\nfunction findUserSourceLocation(\n fiberChain: SelectModeFiberChainEntry[],\n): SelectModeSourceLocation | undefined {\n return fiberChain.find((entry) => {\n return (\n !isLikelyCompiledLocation(entry.sourceLocation) &&\n !isDependencyOrInternalPath(entry.sourceLocation.filePath)\n );\n })?.sourceLocation;\n}\n\nexport async function symbolicateSelectedElement(\n selectedElement: SelectedElement,\n): Promise<SelectedElement> {\n const targets: {\n location: SelectModeSourceLocation;\n apply: (next: SelectModeSourceLocation) => void;\n }[] = [];\n\n const fiberChain: SelectModeFiberChainEntry[] =\n selectedElement.fiberChain.map((entry) => ({ ...entry }));\n for (const entry of fiberChain) {\n if (isLikelyCompiledLocation(entry.sourceLocation)) {\n targets.push({\n location: entry.sourceLocation,\n apply: (next) => {\n entry.sourceLocation = next;\n },\n });\n }\n }\n\n let sourceLocation = selectedElement.sourceLocation;\n // With a chain present `sourceLocation` is re-derived from it below, so\n // targeting it here would just duplicate the chain head's round trip.\n if (\n fiberChain.length === 0 &&\n sourceLocation &&\n isLikelyCompiledLocation(sourceLocation)\n ) {\n const captured = sourceLocation;\n targets.push({\n location: captured,\n apply: (next) => {\n sourceLocation = next;\n },\n });\n }\n\n if (targets.length === 0) {\n return selectedElement;\n }\n\n const resolved = await symbolicateFrames(\n targets.map((target) => toNextStackFrame(target.location)),\n );\n\n for (const [index, target] of targets.entries()) {\n const frame = extractResolvedFrame(resolved[index] ?? null);\n target.apply(applyResolved({ original: target.location, frame }));\n }\n\n if (fiberChain.length > 0) {\n // Fall back to the chain head so we never regress to attributing nothing.\n sourceLocation =\n findUserSourceLocation(fiberChain) ?? fiberChain[0]!.sourceLocation;\n }\n\n return {\n ...selectedElement,\n sourceLocation,\n fiberChain,\n };\n}\n"],
5
+ "mappings": "AAMA,SAAS,iBAAiB;AA0C1B,MAAM,uBAAuB;AAE7B,SAAS,yBACP,UACS;AACT,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AACA,QAAM,WAAW,SAAS;AAC1B,SACE,SAAS,SAAS,OAAO,KACzB,SAAS,SAAS,UAAU,KAC5B,SAAS,SAAS,mBAAmB,KACrC,SAAS,SAAS,YAAY,KAC9B,SAAS,SAAS,KAAK,KACvB,SAAS,WAAW,QAAQ;AAEhC;AAQA,SAAS,2BAA2B,UAA2B;AAC7D,SACE,SAAS,SAAS,cAAc,KAChC,SAAS,SAAS,iBAAiB,KACnC,SAAS,WAAW,QAAQ;AAEhC;AAOA,SAAS,cAAc,UAA2B;AAChD,SACE,SAAS,WAAW,sBAAsB,KAC1C,SAAS,SAAS,iBAAiB,KACnC,SAAS,SAAS,uBAAuB,KACzC,SAAS,SAAS,eAAe;AAErC;AAMA,MAAM,2BAA2B;AAQjC,SAAS,iBAAgC;AACvC,MAAI;AACF,UAAM,UAAU,QAAQ,IAAI;AAC5B,WAAO,OAAO,YAAY,YAAY,QAAQ,SAAS,IAAI,UAAU;AAAA,EACvE,QAAQ;AACN,WAAO;AAA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CAAC;AAAA,EACH;AAEA,MAAI,QAAQ,WAAW,GAAG;AACxB,WAAO;AAAA,EACT;AAEA,QAAM,WAAW,MAAM;AAAA,IACrB,QAAQ,IAAI,CAAC,WAAW,iBAAiB,OAAO,QAAQ,CAAC;AAAA,EAC3D;AAEA,aAAW,CAAC,OAAO,MAAM,KAAK,QAAQ,QAAQ,GAAG;AAC/C,UAAM,QAAQ,qBAAqB,SAAS,KAAK,KAAK,IAAI;AAC1D,WAAO,MAAM,cAAc,EAAE,UAAU,OAAO,UAAU,MAAM,CAAC,CAAC;AAAA,EAClE;AAEA,MAAI,WAAW,SAAS,GAAG;AAEzB,qBACE,uBAAuB,UAAU,KAAK,WAAW,CAAC,EAAG;AAAA,EACzD;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -23,7 +23,7 @@ function getQueryClient() {
23
23
  if (isServer) {
24
24
  return makeQueryClient();
25
25
  }
26
- if (browserQueryClient == null) {
26
+ if (!browserQueryClient) {
27
27
  browserQueryClient = makeQueryClient();
28
28
  }
29
29
  return browserQueryClient;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../lib/get-query-client.ts"],
4
- "sourcesContent": ["import {\n defaultShouldDehydrateQuery,\n isServer,\n QueryClient,\n} from \"@tanstack/react-query\";\n\nconst STALE_TIME_MILLISECONDS = 60 * 1000;\n\nconst makeQueryClient = () => {\n return new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: STALE_TIME_MILLISECONDS,\n },\n dehydrate: {\n shouldDehydrateQuery: (query) => {\n return (\n defaultShouldDehydrateQuery(query) ||\n query.state.status === \"pending\"\n );\n },\n },\n },\n });\n};\n\nlet browserQueryClient: QueryClient | undefined;\n\nexport function getQueryClient() {\n if (isServer) {\n return makeQueryClient();\n }\n\n if (browserQueryClient == null) {\n browserQueryClient = makeQueryClient();\n }\n\n return browserQueryClient;\n}\n"],
5
- "mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,MAAM,0BAA0B,KAAK;AAErC,MAAM,kBAAkB,MAAM;AAC5B,SAAO,IAAI,YAAY;AAAA,IACrB,gBAAgB;AAAA,MACd,SAAS;AAAA,QACP,WAAW;AAAA,MACb;AAAA,MACA,WAAW;AAAA,QACT,sBAAsB,CAAC,UAAU;AAC/B,iBACE,4BAA4B,KAAK,KACjC,MAAM,MAAM,WAAW;AAAA,QAE3B;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEA,IAAI;AAEG,SAAS,iBAAiB;AAC/B,MAAI,UAAU;AACZ,WAAO,gBAAgB;AAAA,EACzB;AAEA,MAAI,sBAAsB,MAAM;AAC9B,yBAAqB,gBAAgB;AAAA,EACvC;AAEA,SAAO;AACT;",
4
+ "sourcesContent": ["import {\n defaultShouldDehydrateQuery,\n isServer,\n QueryClient,\n} from \"@tanstack/react-query\";\n\nconst STALE_TIME_MILLISECONDS = 60 * 1000;\n\nconst makeQueryClient = () => {\n return new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: STALE_TIME_MILLISECONDS,\n },\n dehydrate: {\n shouldDehydrateQuery: (query) => {\n return (\n defaultShouldDehydrateQuery(query) ||\n query.state.status === \"pending\"\n );\n },\n },\n },\n });\n};\n\nlet browserQueryClient: QueryClient | undefined;\n\nexport function getQueryClient() {\n if (isServer) {\n return makeQueryClient();\n }\n\n if (!browserQueryClient) {\n browserQueryClient = makeQueryClient();\n }\n\n return browserQueryClient;\n}\n"],
5
+ "mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,MAAM,0BAA0B,KAAK;AAErC,MAAM,kBAAkB,MAAM;AAC5B,SAAO,IAAI,YAAY;AAAA,IACrB,gBAAgB;AAAA,MACd,SAAS;AAAA,QACP,WAAW;AAAA,MACb;AAAA,MACA,WAAW;AAAA,QACT,sBAAsB,CAAC,UAAU;AAC/B,iBACE,4BAA4B,KAAK,KACjC,MAAM,MAAM,WAAW;AAAA,QAE3B;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEA,IAAI;AAEG,SAAS,iBAAiB;AAC/B,MAAI,UAAU;AACZ,WAAO,gBAAgB;AAAA,EACzB;AAEA,MAAI,CAAC,oBAAoB;AACvB,yBAAqB,gBAAgB;AAAA,EACvC;AAEA,SAAO;AACT;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@replohq/canopy-sdk",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
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,