@replohq/canopy-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/_vendor/replo-utils/lib/errors.d.ts +83 -0
  2. package/_vendor/replo-utils/lib/json.d.ts +6 -0
  3. package/_vendor/replo-utils/lib/misc.d.ts +128 -0
  4. package/_vendor/replo-utils/lib/misc.mjs +1 -0
  5. package/_vendor/replo-utils/lib/object.d.ts +31 -0
  6. package/_vendor/replo-utils/lib/parse.d.ts +15 -0
  7. package/_vendor/schemas/agentTools/customIntegrations/loaders/levanta.d.ts +49 -0
  8. package/_vendor/schemas/agentTools/customIntegrations/loaders/levanta.mjs +36 -0
  9. package/_vendor/schemas/agentTools/customIntegrations/loaders/product.d.ts +334 -0
  10. package/_vendor/schemas/agentTools/customIntegrations/loaders/product.mjs +50 -0
  11. package/_vendor/schemas/cart.d.ts +198 -0
  12. package/_vendor/schemas/cart.mjs +83 -0
  13. package/_vendor/schemas/errors.d.ts +428 -0
  14. package/_vendor/schemas/errors.mjs +955 -0
  15. package/_vendor/schemas/generated/errors.d.ts +61 -0
  16. package/_vendor/schemas/generated/selectMode.d.ts +95 -0
  17. package/_vendor/schemas/generated/selectMode.mjs +1 -0
  18. package/_vendor/schemas/loaderKeys.d.ts +39 -0
  19. package/_vendor/schemas/loaderKeys.mjs +23 -0
  20. package/_vendor/schemas/objectType.d.ts +895 -0
  21. package/_vendor/schemas/objectType.mjs +2 -0
  22. package/_vendor/schemas/registry.d.ts +243 -0
  23. package/_vendor/schemas/sandboxFiles.d.ts +35 -0
  24. package/_vendor/schemas/selectMode.d.ts +507 -0
  25. package/_vendor/schemas/selectMode.mjs +194 -0
  26. package/_vendor/schemas/sellingPlan.d.ts +60 -0
  27. package/_vendor/schemas/sellingPlan.mjs +1 -0
  28. package/analytics/analytics-provider.d.ts +13 -0
  29. package/analytics/analytics-provider.js +104 -0
  30. package/analytics/analytics-provider.js.map +7 -0
  31. package/analytics/analytics-sink.d.ts +20 -0
  32. package/analytics/analytics-sink.js +1 -0
  33. package/analytics/analytics-sink.js.map +7 -0
  34. package/analytics/hooks/use-product-viewed-analytics.d.ts +23 -0
  35. package/analytics/hooks/use-product-viewed-analytics.js +34 -0
  36. package/analytics/hooks/use-product-viewed-analytics.js.map +7 -0
  37. package/analytics/sinks/ga4-sink.d.ts +15 -0
  38. package/analytics/sinks/ga4-sink.js +52 -0
  39. package/analytics/sinks/ga4-sink.js.map +7 -0
  40. package/analytics/sinks/meta-sink.d.ts +14 -0
  41. package/analytics/sinks/meta-sink.js +44 -0
  42. package/analytics/sinks/meta-sink.js.map +7 -0
  43. package/analytics/sinks/pinterest-sink.d.ts +14 -0
  44. package/analytics/sinks/pinterest-sink.js +76 -0
  45. package/analytics/sinks/pinterest-sink.js.map +7 -0
  46. package/analytics/sinks/reddit-sink.d.ts +14 -0
  47. package/analytics/sinks/reddit-sink.js +80 -0
  48. package/analytics/sinks/reddit-sink.js.map +7 -0
  49. package/analytics/sinks/replo-sink.d.ts +14 -0
  50. package/analytics/sinks/replo-sink.js +57 -0
  51. package/analytics/sinks/replo-sink.js.map +7 -0
  52. package/analytics/sinks/snapchat-sink.d.ts +14 -0
  53. package/analytics/sinks/snapchat-sink.js +67 -0
  54. package/analytics/sinks/snapchat-sink.js.map +7 -0
  55. package/analytics/sinks/tiktok-sink.d.ts +14 -0
  56. package/analytics/sinks/tiktok-sink.js +79 -0
  57. package/analytics/sinks/tiktok-sink.js.map +7 -0
  58. package/analytics/sinks/window-sink.d.ts +18 -0
  59. package/analytics/sinks/window-sink.js +46 -0
  60. package/analytics/sinks/window-sink.js.map +7 -0
  61. package/analytics/utils/analytics-utils.d.ts +7 -0
  62. package/analytics/utils/analytics-utils.js +130 -0
  63. package/analytics/utils/analytics-utils.js.map +7 -0
  64. package/analytics/utils/navigation-tracker.d.ts +16 -0
  65. package/analytics/utils/navigation-tracker.js +44 -0
  66. package/analytics/utils/navigation-tracker.js.map +7 -0
  67. package/cart/buy-now-action.d.ts +21 -0
  68. package/cart/buy-now-action.js +104 -0
  69. package/cart/buy-now-action.js.map +7 -0
  70. package/cart/cart-actions.d.ts +63 -0
  71. package/cart/cart-actions.js +90 -0
  72. package/cart/cart-actions.js.map +7 -0
  73. package/cart/cart-loader.d.ts +9 -0
  74. package/cart/cart-loader.js +11 -0
  75. package/cart/cart-loader.js.map +7 -0
  76. package/cart/cart-provider.d.ts +85 -0
  77. package/cart/cart-provider.js +358 -0
  78. package/cart/cart-provider.js.map +7 -0
  79. package/cart/cart-types.d.ts +154 -0
  80. package/cart/cart-types.js +16 -0
  81. package/cart/cart-types.js.map +7 -0
  82. package/cart/gateways/cart-gateway.d.ts +10 -0
  83. package/cart/gateways/cart-gateway.js +19 -0
  84. package/cart/gateways/cart-gateway.js.map +7 -0
  85. package/cart/gateways/cookie-cart-gateway.d.ts +28 -0
  86. package/cart/gateways/cookie-cart-gateway.js +109 -0
  87. package/cart/gateways/cookie-cart-gateway.js.map +7 -0
  88. package/cart/gateways/default-cart-gateway.d.ts +19 -0
  89. package/cart/gateways/default-cart-gateway.js +30 -0
  90. package/cart/gateways/default-cart-gateway.js.map +7 -0
  91. package/cart/gateways/resolver-cart-gateway.d.ts +2 -0
  92. package/cart/gateways/resolver-cart-gateway.js +106 -0
  93. package/cart/gateways/resolver-cart-gateway.js.map +7 -0
  94. package/cart/gateways/stripe-cart-gateway.d.ts +19 -0
  95. package/cart/gateways/stripe-cart-gateway.js +28 -0
  96. package/cart/gateways/stripe-cart-gateway.js.map +7 -0
  97. package/cart/gateways/stripe-constants.d.ts +1 -0
  98. package/cart/gateways/stripe-constants.js +5 -0
  99. package/cart/gateways/stripe-constants.js.map +7 -0
  100. package/cart/hooks/use-add-to-cart.d.ts +63 -0
  101. package/cart/hooks/use-add-to-cart.js +120 -0
  102. package/cart/hooks/use-add-to-cart.js.map +7 -0
  103. package/cart/hooks/use-buy-now.d.ts +49 -0
  104. package/cart/hooks/use-buy-now.js +62 -0
  105. package/cart/hooks/use-buy-now.js.map +7 -0
  106. package/cart/utils/cart-utils.d.ts +31 -0
  107. package/cart/utils/cart-utils.js +48 -0
  108. package/cart/utils/cart-utils.js.map +7 -0
  109. package/cart/utils/cookie-cart-persistence.d.ts +55 -0
  110. package/cart/utils/cookie-cart-persistence.js +153 -0
  111. package/cart/utils/cookie-cart-persistence.js.map +7 -0
  112. package/cart/utils/variant-to-cart-line.d.ts +124 -0
  113. package/cart/utils/variant-to-cart-line.js +202 -0
  114. package/cart/utils/variant-to-cart-line.js.map +7 -0
  115. package/chunk-46YU2W6T.mjs +538 -0
  116. package/chunk-4TZVNC3W.mjs +33 -0
  117. package/chunk-INHK6MYI.mjs +1598 -0
  118. package/editor/ClientErrorBoundary.d.ts +7 -0
  119. package/editor/ClientErrorBoundary.js +48 -0
  120. package/editor/ClientErrorBoundary.js.map +7 -0
  121. package/editor/LinkInterceptor.d.ts +1 -0
  122. package/editor/LinkInterceptor.js +124 -0
  123. package/editor/LinkInterceptor.js.map +7 -0
  124. package/editor/posthog-relay.d.ts +10 -0
  125. package/editor/posthog-relay.js +60 -0
  126. package/editor/posthog-relay.js.map +7 -0
  127. package/editor/select-mode/EditorSelection.d.ts +24 -0
  128. package/editor/select-mode/EditorSelection.js +34 -0
  129. package/editor/select-mode/EditorSelection.js.map +7 -0
  130. package/editor/select-mode/descriptor/elementDescriptor.d.ts +15 -0
  131. package/editor/select-mode/descriptor/elementDescriptor.js +213 -0
  132. package/editor/select-mode/descriptor/elementDescriptor.js.map +7 -0
  133. package/editor/select-mode/fiber.d.ts +52 -0
  134. package/editor/select-mode/fiber.js +269 -0
  135. package/editor/select-mode/fiber.js.map +7 -0
  136. package/editor/select-mode/hooks/useCrosshairCursor.d.ts +12 -0
  137. package/editor/select-mode/hooks/useCrosshairCursor.js +20 -0
  138. package/editor/select-mode/hooks/useCrosshairCursor.js.map +7 -0
  139. package/editor/select-mode/hooks/useParentMessaging.d.ts +24 -0
  140. package/editor/select-mode/hooks/useParentMessaging.js +33 -0
  141. package/editor/select-mode/hooks/useParentMessaging.js.map +7 -0
  142. package/editor/select-mode/hooks/useSelectModeController.d.ts +8 -0
  143. package/editor/select-mode/hooks/useSelectModeController.js +49 -0
  144. package/editor/select-mode/hooks/useSelectModeController.js.map +7 -0
  145. package/editor/select-mode/hooks/useSelectionHover.d.ts +22 -0
  146. package/editor/select-mode/hooks/useSelectionHover.js +98 -0
  147. package/editor/select-mode/hooks/useSelectionHover.js.map +7 -0
  148. package/editor/select-mode/hooks/useSelectionInteractions.d.ts +32 -0
  149. package/editor/select-mode/hooks/useSelectionInteractions.js +293 -0
  150. package/editor/select-mode/hooks/useSelectionInteractions.js.map +7 -0
  151. package/editor/select-mode/hooks/useSelectionScrollSync.d.ts +28 -0
  152. package/editor/select-mode/hooks/useSelectionScrollSync.js +77 -0
  153. package/editor/select-mode/hooks/useSelectionScrollSync.js.map +7 -0
  154. package/editor/select-mode/interactions/selectionGeometry.d.ts +80 -0
  155. package/editor/select-mode/interactions/selectionGeometry.js +160 -0
  156. package/editor/select-mode/interactions/selectionGeometry.js.map +7 -0
  157. package/editor/select-mode/selectModeSession.d.ts +21 -0
  158. package/editor/select-mode/selectModeSession.js +7 -0
  159. package/editor/select-mode/selectModeSession.js.map +7 -0
  160. package/editor/select-mode/selectionFrame.d.ts +48 -0
  161. package/editor/select-mode/selectionFrame.js +74 -0
  162. package/editor/select-mode/selectionFrame.js.map +7 -0
  163. package/editor/select-mode/symbolicate.d.ts +3 -0
  164. package/editor/select-mode/symbolicate.js +139 -0
  165. package/editor/select-mode/symbolicate.js.map +7 -0
  166. package/env.d.ts +13 -0
  167. package/env.js +20 -0
  168. package/env.js.map +7 -0
  169. package/gateways/canopy-api.d.ts +84 -0
  170. package/gateways/canopy-api.js +203 -0
  171. package/gateways/canopy-api.js.map +7 -0
  172. package/hooks/use-client-value.d.ts +10 -0
  173. package/hooks/use-client-value.js +12 -0
  174. package/hooks/use-client-value.js.map +7 -0
  175. package/hooks/use-formatted-price.d.ts +15 -0
  176. package/hooks/use-formatted-price.js +19 -0
  177. package/hooks/use-formatted-price.js.map +7 -0
  178. package/lib/get-query-client.d.ts +2 -0
  179. package/lib/get-query-client.js +34 -0
  180. package/lib/get-query-client.js.map +7 -0
  181. package/lib/integration-utils.d.ts +2 -0
  182. package/lib/integration-utils.js +9 -0
  183. package/lib/integration-utils.js.map +7 -0
  184. package/lib/shopify-utils.d.ts +16 -0
  185. package/lib/shopify-utils.js +11 -0
  186. package/lib/shopify-utils.js.map +7 -0
  187. package/lib/url-utils.d.ts +4 -0
  188. package/lib/url-utils.js +8 -0
  189. package/lib/url-utils.js.map +7 -0
  190. package/loaders/collection-loader.d.ts +11 -0
  191. package/loaders/collection-loader.js +53 -0
  192. package/loaders/collection-loader.js.map +7 -0
  193. package/loaders/collection-products-loader.d.ts +12 -0
  194. package/loaders/collection-products-loader.js +56 -0
  195. package/loaders/collection-products-loader.js.map +7 -0
  196. package/loaders/invoke-loader-action.d.ts +11 -0
  197. package/loaders/invoke-loader-action.js +14 -0
  198. package/loaders/invoke-loader-action.js.map +7 -0
  199. package/loaders/invoke-loader-server.d.ts +18 -0
  200. package/loaders/invoke-loader-server.js +35 -0
  201. package/loaders/invoke-loader-server.js.map +7 -0
  202. package/loaders/invoke-loader.d.ts +14 -0
  203. package/loaders/invoke-loader.js +36 -0
  204. package/loaders/invoke-loader.js.map +7 -0
  205. package/loaders/levanta-product-loader.d.ts +11 -0
  206. package/loaders/levanta-product-loader.js +53 -0
  207. package/loaders/levanta-product-loader.js.map +7 -0
  208. package/loaders/loader-error-boundary.d.ts +25 -0
  209. package/loaders/loader-error-boundary.js +24 -0
  210. package/loaders/loader-error-boundary.js.map +7 -0
  211. package/loaders/okendo-review-aggregate-loader.d.ts +17 -0
  212. package/loaders/okendo-review-aggregate-loader.js +56 -0
  213. package/loaders/okendo-review-aggregate-loader.js.map +7 -0
  214. package/loaders/okendo-reviews-loader.d.ts +23 -0
  215. package/loaders/okendo-reviews-loader.js +54 -0
  216. package/loaders/okendo-reviews-loader.js.map +7 -0
  217. package/loaders/prefetch-loaders.d.ts +33 -0
  218. package/loaders/prefetch-loaders.js +46 -0
  219. package/loaders/prefetch-loaders.js.map +7 -0
  220. package/loaders/product-loader.d.ts +11 -0
  221. package/loaders/product-loader.js +53 -0
  222. package/loaders/product-loader.js.map +7 -0
  223. package/loaders/rebuy-recommendations-loader.d.ts +159 -0
  224. package/loaders/rebuy-recommendations-loader.js +57 -0
  225. package/loaders/rebuy-recommendations-loader.js.map +7 -0
  226. package/loaders/smile-earning-rules-loader.d.ts +19 -0
  227. package/loaders/smile-earning-rules-loader.js +44 -0
  228. package/loaders/smile-earning-rules-loader.js.map +7 -0
  229. package/loaders/smile-rewards-loader.d.ts +19 -0
  230. package/loaders/smile-rewards-loader.js +44 -0
  231. package/loaders/smile-rewards-loader.js.map +7 -0
  232. package/loaders/smile-vip-tiers-loader.d.ts +18 -0
  233. package/loaders/smile-vip-tiers-loader.js +43 -0
  234. package/loaders/smile-vip-tiers-loader.js.map +7 -0
  235. package/package.json +29 -0
  236. package/providers/query-provider.d.ts +1 -0
  237. package/providers/query-provider.js +12 -0
  238. package/providers/query-provider.js.map +7 -0
  239. package/providers/replo-provider.d.ts +1 -0
  240. package/providers/replo-provider.js +20 -0
  241. package/providers/replo-provider.js.map +7 -0
package/env.js.map ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../env.ts"],
4
+ "sourcesContent": ["import { getCloudflareContext } from \"@opennextjs/cloudflare\";\nimport { z } from \"zod\";\n\ntype Env = {\n CANOPY_API_HOST: string;\n PROJECT_ID: string;\n\n // NOTE (Gabe 2025-06-26): If there's no Shopify integration these will be\n // undefined.\n SHOPIFY_URL?: string;\n // NOTE (Gabe 2025-06-26): Even if there's an integration, if we haven't been\n // given elevated scope this may be null.\n SHOPIFY_STOREFRONT_ACCESS_TOKEN?: string | null;\n STRIPE_CONNECT_ACCOUNT_ID?: string | null;\n CHECKOUT_PROVIDER?: \"shopify\" | \"stripe\" | \"none\";\n\n REPLO_INTERNAL_REVALIDATE_SECRET?: string;\n /** Shared secret sent in X-Replo-Resolver-Auth for server-to-server cart calls. */\n CART_AUTH_SECRET?: string;\n};\n\nconst envSchema = z.object({\n CANOPY_API_HOST: z.string().min(1),\n PROJECT_ID: z.string().uuid(),\n SHOPIFY_URL: z.string().optional(),\n SHOPIFY_STOREFRONT_ACCESS_TOKEN: z.string().nullable().optional(),\n STRIPE_CONNECT_ACCOUNT_ID: z.string().nullable().optional(),\n CHECKOUT_PROVIDER: z.enum([\"shopify\", \"stripe\", \"none\"]).optional(),\n REPLO_INTERNAL_REVALIDATE_SECRET: z.string().optional(),\n CART_AUTH_SECRET: z.string().optional(),\n});\n\nexport const getEnv = async (): Promise<Env> => {\n const { env } = await getCloudflareContext({ async: true });\n return envSchema.parse(env);\n};\n"],
5
+ "mappings": "AAAA,SAAS,4BAA4B;AACrC,SAAS,SAAS;AAoBlB,MAAM,YAAY,EAAE,OAAO;AAAA,EACzB,iBAAiB,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACjC,YAAY,EAAE,OAAO,EAAE,KAAK;AAAA,EAC5B,aAAa,EAAE,OAAO,EAAE,SAAS;AAAA,EACjC,iCAAiC,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,EAChE,2BAA2B,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,EAC1D,mBAAmB,EAAE,KAAK,CAAC,WAAW,UAAU,MAAM,CAAC,EAAE,SAAS;AAAA,EAClE,kCAAkC,EAAE,OAAO,EAAE,SAAS;AAAA,EACtD,kBAAkB,EAAE,OAAO,EAAE,SAAS;AACxC,CAAC;AAEM,MAAM,SAAS,YAA0B;AAC9C,QAAM,EAAE,IAAI,IAAI,MAAM,qBAAqB,EAAE,OAAO,KAAK,CAAC;AAC1D,SAAO,UAAU,MAAM,GAAG;AAC5B;",
6
+ "names": []
7
+ }
@@ -0,0 +1,84 @@
1
+ import type { Cart } from "../_vendor/schemas/cart";
2
+ import { ReploError } from "../_vendor/schemas/errors";
3
+ type CanopyApiGatewayErrorConfig = {
4
+ message: string;
5
+ statusCode?: number;
6
+ cause?: unknown;
7
+ additionalData?: Record<string, unknown>;
8
+ };
9
+ export declare class CanopyApiGatewayError extends ReploError {
10
+ statusCode: number;
11
+ constructor(config: CanopyApiGatewayErrorConfig);
12
+ }
13
+ export declare function isCanopyApiGatewayError(error: unknown): error is CanopyApiGatewayError;
14
+ declare class CanopyApiGateway {
15
+ private apiHost;
16
+ private baseUrl;
17
+ constructor(apiHost: string);
18
+ private static readonly REQUEST_TIMEOUT_MILLISECONDS;
19
+ static setup(): Promise<CanopyApiGateway>;
20
+ private _post;
21
+ private _get;
22
+ invokeLoader({ loaderKey, args, }: {
23
+ loaderKey: string;
24
+ args: Record<string, unknown>;
25
+ }): Promise<{
26
+ data: unknown;
27
+ meta?: {
28
+ cache: {
29
+ hit: boolean;
30
+ ttlSeconds: number;
31
+ };
32
+ } | undefined;
33
+ }>;
34
+ private _cartPost;
35
+ cartGet({ cartId }: {
36
+ cartId: string;
37
+ }): Promise<Cart | null>;
38
+ cartCreate(options?: {
39
+ lines?: {
40
+ merchandiseId: string;
41
+ quantity: number;
42
+ attributes?: {
43
+ key: string;
44
+ value: string;
45
+ }[];
46
+ sellingPlanId?: string | null;
47
+ }[];
48
+ discountCodes?: string[];
49
+ }): Promise<Cart>;
50
+ cartAddLines({ cartId, lines, }: {
51
+ cartId: string;
52
+ lines: {
53
+ merchandiseId: string;
54
+ quantity: number;
55
+ attributes?: {
56
+ key: string;
57
+ value: string;
58
+ }[];
59
+ sellingPlanId?: string | null;
60
+ }[];
61
+ }): Promise<Cart>;
62
+ cartUpdateLines({ cartId, lines, }: {
63
+ cartId: string;
64
+ lines: {
65
+ lineId: string;
66
+ quantity: number;
67
+ attributes?: {
68
+ key: string;
69
+ value: string;
70
+ }[];
71
+ sellingPlanId?: string | null;
72
+ }[];
73
+ }): Promise<Cart>;
74
+ cartRemoveLines({ cartId, lineIds, }: {
75
+ cartId: string;
76
+ lineIds: string[];
77
+ }): Promise<Cart>;
78
+ cartUpdateDiscountCodes({ cartId, discountCodes, }: {
79
+ cartId: string;
80
+ discountCodes: string[];
81
+ }): Promise<Cart>;
82
+ }
83
+ export declare function getCanopyApiGateway(): Promise<CanopyApiGateway>;
84
+ export {};
@@ -0,0 +1,203 @@
1
+ import { cartSchema } from "../_vendor/schemas/cart.mjs";
2
+ import { ReploError } from "../_vendor/schemas/errors.mjs";
3
+ import { z } from "zod";
4
+ import { getEnv } from "../env";
5
+ import { buildBaseUrl } from "../lib/url-utils";
6
+ class CanopyApiGatewayError extends ReploError {
7
+ statusCode;
8
+ constructor(config) {
9
+ const resolvedStatusCode = config.statusCode ?? 500;
10
+ super({
11
+ message: config.message,
12
+ cause: config.cause,
13
+ additionalData: {
14
+ ...config.additionalData,
15
+ statusCode: resolvedStatusCode
16
+ }
17
+ });
18
+ this.statusCode = resolvedStatusCode;
19
+ }
20
+ }
21
+ function isCanopyApiGatewayError(error) {
22
+ return error instanceof CanopyApiGatewayError;
23
+ }
24
+ class UnknownCanopyApiError extends CanopyApiGatewayError {
25
+ constructor(config) {
26
+ super({ ...config, statusCode: 502 });
27
+ }
28
+ }
29
+ const loaderInvokeResponseSchema = z.object({
30
+ data: z.unknown(),
31
+ meta: z.object({
32
+ cache: z.object({
33
+ hit: z.boolean(),
34
+ ttlSeconds: z.number()
35
+ })
36
+ }).optional()
37
+ });
38
+ class CanopyApiGateway {
39
+ apiHost;
40
+ baseUrl;
41
+ constructor(apiHost) {
42
+ this.apiHost = apiHost;
43
+ this.baseUrl = buildBaseUrl(apiHost);
44
+ }
45
+ static REQUEST_TIMEOUT_MILLISECONDS = 1e4;
46
+ static async setup() {
47
+ const env = await getEnv();
48
+ return new CanopyApiGateway(env.CANOPY_API_HOST);
49
+ }
50
+ async _post(url, body) {
51
+ const abortController = new AbortController();
52
+ const timeoutId = setTimeout(() => {
53
+ abortController.abort();
54
+ }, CanopyApiGateway.REQUEST_TIMEOUT_MILLISECONDS);
55
+ try {
56
+ return await fetch(url, {
57
+ method: "POST",
58
+ headers: { "Content-Type": "application/json" },
59
+ body: JSON.stringify(body),
60
+ signal: abortController.signal
61
+ });
62
+ } catch (error) {
63
+ let message = `Failed to POST to canopy-api at ${url}: ${error}`;
64
+ if (process.env.NODE_ENV !== "production") {
65
+ message += `
66
+
67
+ apiHost: ${this.apiHost}
68
+ If you're running locally, make sure the canopy-api cloudflare worker is running. You may need to restart the dev server.`;
69
+ }
70
+ throw new UnknownCanopyApiError({ message, cause: error });
71
+ } finally {
72
+ clearTimeout(timeoutId);
73
+ }
74
+ }
75
+ async _get(url) {
76
+ const abortController = new AbortController();
77
+ const timeoutId = setTimeout(() => {
78
+ abortController.abort();
79
+ }, CanopyApiGateway.REQUEST_TIMEOUT_MILLISECONDS);
80
+ try {
81
+ return await fetch(url, { signal: abortController.signal });
82
+ } catch (error) {
83
+ let message = `Failed to GET from canopy-api at ${url}: ${error}`;
84
+ if (process.env.NODE_ENV !== "production") {
85
+ message += `
86
+
87
+ apiHost: ${this.apiHost}
88
+ If you're running locally, make sure the canopy-api cloudflare worker is running. You may need to restart the dev server.`;
89
+ }
90
+ throw new UnknownCanopyApiError({ message, cause: error });
91
+ } finally {
92
+ clearTimeout(timeoutId);
93
+ }
94
+ }
95
+ async invokeLoader({
96
+ loaderKey,
97
+ args
98
+ }) {
99
+ const env = await getEnv();
100
+ const response = await this._post(`${this.baseUrl}/api/v1/loaders/invoke`, {
101
+ projectId: env.PROJECT_ID,
102
+ loaderKey,
103
+ args
104
+ });
105
+ if (!response.ok) {
106
+ const errorBody = await response.text().catch(() => "");
107
+ throw new CanopyApiGatewayError({
108
+ message: `Failed to invoke loader ${loaderKey}: ${response.status} ${response.statusText}${errorBody ? ` \u2014 ${errorBody}` : ""}`,
109
+ statusCode: response.status
110
+ });
111
+ }
112
+ return loaderInvokeResponseSchema.parse(await response.json());
113
+ }
114
+ // ---------------------------------------------------------------------------
115
+ // Cart operations (canopy-api-backed ExternalCart)
116
+ // ---------------------------------------------------------------------------
117
+ async _cartPost(path, body) {
118
+ const env = await getEnv();
119
+ const authSecret = env.CART_AUTH_SECRET;
120
+ const url = `${this.baseUrl}/api/v1/cart${path}`;
121
+ const abortController = new AbortController();
122
+ const timeoutId = setTimeout(() => {
123
+ abortController.abort();
124
+ }, CanopyApiGateway.REQUEST_TIMEOUT_MILLISECONDS);
125
+ let response;
126
+ try {
127
+ response = await fetch(url, {
128
+ method: "POST",
129
+ headers: {
130
+ "Content-Type": "application/json",
131
+ ...authSecret ? { "X-Replo-Resolver-Auth": authSecret } : {}
132
+ },
133
+ body: JSON.stringify({ ...body, projectId: env.PROJECT_ID }),
134
+ signal: abortController.signal
135
+ });
136
+ } catch (error) {
137
+ throw new UnknownCanopyApiError({
138
+ message: `Failed to POST cart operation to ${url}: ${error}`,
139
+ cause: error
140
+ });
141
+ } finally {
142
+ clearTimeout(timeoutId);
143
+ }
144
+ if (!response.ok) {
145
+ const text = await response.text().catch(() => "");
146
+ throw new CanopyApiGatewayError({
147
+ message: `Cart operation ${path} failed: ${response.status} ${response.statusText} \u2014 ${text}`,
148
+ statusCode: response.status
149
+ });
150
+ }
151
+ const json = await response.json();
152
+ return cartSchema.parse(json.data);
153
+ }
154
+ async cartGet({ cartId }) {
155
+ try {
156
+ return await this._cartPost("/get", { cartId });
157
+ } catch (error) {
158
+ if (error instanceof CanopyApiGatewayError && error.statusCode === 404) {
159
+ return null;
160
+ }
161
+ throw error;
162
+ }
163
+ }
164
+ async cartCreate(options) {
165
+ return this._cartPost("/create", {
166
+ lines: options?.lines,
167
+ discountCodes: options?.discountCodes
168
+ });
169
+ }
170
+ async cartAddLines({
171
+ cartId,
172
+ lines
173
+ }) {
174
+ return this._cartPost("/add-lines", { cartId, lines });
175
+ }
176
+ async cartUpdateLines({
177
+ cartId,
178
+ lines
179
+ }) {
180
+ return this._cartPost("/update-lines", { cartId, lines });
181
+ }
182
+ async cartRemoveLines({
183
+ cartId,
184
+ lineIds
185
+ }) {
186
+ return this._cartPost("/remove-lines", { cartId, lineIds });
187
+ }
188
+ async cartUpdateDiscountCodes({
189
+ cartId,
190
+ discountCodes
191
+ }) {
192
+ return this._cartPost("/update-discount-codes", { cartId, discountCodes });
193
+ }
194
+ }
195
+ async function getCanopyApiGateway() {
196
+ return CanopyApiGateway.setup();
197
+ }
198
+ export {
199
+ CanopyApiGatewayError,
200
+ getCanopyApiGateway,
201
+ isCanopyApiGatewayError
202
+ };
203
+ //# sourceMappingURL=canopy-api.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../gateways/canopy-api.ts"],
4
+ "sourcesContent": ["import type { Cart } from \"schemas/cart\";\n\nimport { cartSchema } from \"schemas/cart\";\nimport { ReploError } from \"schemas/errors\";\nimport { z } from \"zod\";\n\nimport { getEnv } from \"../env\";\nimport { buildBaseUrl } from \"../lib/url-utils\";\n\ntype CanopyApiGatewayErrorConfig = {\n message: string;\n statusCode?: number;\n cause?: unknown;\n additionalData?: Record<string, unknown>;\n};\n\nexport class CanopyApiGatewayError extends ReploError {\n statusCode: number;\n\n constructor(config: CanopyApiGatewayErrorConfig) {\n const resolvedStatusCode = config.statusCode ?? 500;\n super({\n message: config.message,\n cause: config.cause,\n additionalData: {\n ...config.additionalData,\n statusCode: resolvedStatusCode,\n },\n });\n this.statusCode = resolvedStatusCode;\n }\n}\n\nexport function isCanopyApiGatewayError(\n error: unknown,\n): error is CanopyApiGatewayError {\n return error instanceof CanopyApiGatewayError;\n}\n\nclass UnknownCanopyApiError extends CanopyApiGatewayError {\n constructor(config: Omit<CanopyApiGatewayErrorConfig, \"statusCode\">) {\n super({ ...config, statusCode: 502 });\n }\n}\n\nconst loaderInvokeResponseSchema = z.object({\n data: z.unknown(),\n meta: z\n .object({\n cache: z.object({\n hit: z.boolean(),\n ttlSeconds: z.number(),\n }),\n })\n .optional(),\n});\n\nclass CanopyApiGateway {\n private apiHost: string;\n private baseUrl: string;\n constructor(apiHost: string) {\n this.apiHost = apiHost;\n this.baseUrl = buildBaseUrl(apiHost);\n }\n\n private static readonly REQUEST_TIMEOUT_MILLISECONDS = 10_000;\n\n static async setup() {\n const env = await getEnv();\n\n return new CanopyApiGateway(env.CANOPY_API_HOST);\n }\n\n private async _post(url: string, body: unknown) {\n const abortController = new AbortController();\n const timeoutId = setTimeout(() => {\n abortController.abort();\n }, CanopyApiGateway.REQUEST_TIMEOUT_MILLISECONDS);\n\n try {\n return await fetch(url, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(body),\n signal: abortController.signal,\n });\n } catch (error) {\n let message = `Failed to POST to canopy-api at ${url}: ${error}`;\n if (process.env.NODE_ENV !== \"production\") {\n message += `\\n\\napiHost: ${this.apiHost}\\nIf you're running locally, make sure the canopy-api cloudflare worker is running. You may need to restart the dev server.`;\n }\n throw new UnknownCanopyApiError({ message, cause: error });\n } finally {\n clearTimeout(timeoutId);\n }\n }\n\n private async _get(url: string) {\n const abortController = new AbortController();\n const timeoutId = setTimeout(() => {\n abortController.abort();\n }, CanopyApiGateway.REQUEST_TIMEOUT_MILLISECONDS);\n\n try {\n return await fetch(url, { signal: abortController.signal });\n } catch (error) {\n let message = `Failed to GET from canopy-api at ${url}: ${error}`;\n if (process.env.NODE_ENV !== \"production\") {\n message += `\\n\\napiHost: ${this.apiHost}\\nIf you're running locally, make sure the canopy-api cloudflare worker is running. You may need to restart the dev server.`;\n }\n throw new UnknownCanopyApiError({ message, cause: error });\n } finally {\n clearTimeout(timeoutId);\n }\n }\n\n async invokeLoader({\n loaderKey,\n args,\n }: {\n loaderKey: string;\n args: Record<string, unknown>;\n }) {\n const env = await getEnv();\n const response = await this._post(`${this.baseUrl}/api/v1/loaders/invoke`, {\n projectId: env.PROJECT_ID,\n loaderKey,\n args,\n });\n\n if (!response.ok) {\n const errorBody = await response.text().catch(() => \"\");\n throw new CanopyApiGatewayError({\n message: `Failed to invoke loader ${loaderKey}: ${response.status} ${response.statusText}${errorBody ? ` \u2014 ${errorBody}` : \"\"}`,\n statusCode: response.status,\n });\n }\n\n return loaderInvokeResponseSchema.parse(await response.json());\n }\n\n // ---------------------------------------------------------------------------\n // Cart operations (canopy-api-backed ExternalCart)\n // ---------------------------------------------------------------------------\n\n private async _cartPost(\n path: string,\n body: Record<string, unknown>,\n ): Promise<Cart> {\n const env = await getEnv();\n const authSecret = env.CART_AUTH_SECRET;\n const url = `${this.baseUrl}/api/v1/cart${path}`;\n\n const abortController = new AbortController();\n const timeoutId = setTimeout(() => {\n abortController.abort();\n }, CanopyApiGateway.REQUEST_TIMEOUT_MILLISECONDS);\n\n let response: Response;\n try {\n response = await fetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...(authSecret ? { \"X-Replo-Resolver-Auth\": authSecret } : {}),\n },\n body: JSON.stringify({ ...body, projectId: env.PROJECT_ID }),\n signal: abortController.signal,\n });\n } catch (error) {\n throw new UnknownCanopyApiError({\n message: `Failed to POST cart operation to ${url}: ${error}`,\n cause: error,\n });\n } finally {\n clearTimeout(timeoutId);\n }\n\n if (!response.ok) {\n const text = await response.text().catch(() => \"\");\n throw new CanopyApiGatewayError({\n message: `Cart operation ${path} failed: ${response.status} ${response.statusText} \u2014 ${text}`,\n statusCode: response.status,\n });\n }\n\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const json = (await response.json()) as { data: unknown };\n return cartSchema.parse(json.data);\n }\n\n async cartGet({ cartId }: { cartId: string }): Promise<Cart | null> {\n try {\n return await this._cartPost(\"/get\", { cartId });\n } catch (error) {\n if (error instanceof CanopyApiGatewayError && error.statusCode === 404) {\n return null;\n }\n throw error;\n }\n }\n\n async cartCreate(options?: {\n lines?: {\n merchandiseId: string;\n quantity: number;\n attributes?: { key: string; value: string }[];\n sellingPlanId?: string | null;\n }[];\n discountCodes?: string[];\n }): Promise<Cart> {\n return this._cartPost(\"/create\", {\n lines: options?.lines,\n discountCodes: options?.discountCodes,\n });\n }\n\n async cartAddLines({\n cartId,\n lines,\n }: {\n cartId: string;\n lines: {\n merchandiseId: string;\n quantity: number;\n attributes?: { key: string; value: string }[];\n sellingPlanId?: string | null;\n }[];\n }): Promise<Cart> {\n return this._cartPost(\"/add-lines\", { cartId, lines });\n }\n\n async cartUpdateLines({\n cartId,\n lines,\n }: {\n cartId: string;\n lines: {\n lineId: string;\n quantity: number;\n attributes?: { key: string; value: string }[];\n sellingPlanId?: string | null;\n }[];\n }): Promise<Cart> {\n return this._cartPost(\"/update-lines\", { cartId, lines });\n }\n\n async cartRemoveLines({\n cartId,\n lineIds,\n }: {\n cartId: string;\n lineIds: string[];\n }): Promise<Cart> {\n return this._cartPost(\"/remove-lines\", { cartId, lineIds });\n }\n\n async cartUpdateDiscountCodes({\n cartId,\n discountCodes,\n }: {\n cartId: string;\n discountCodes: string[];\n }): Promise<Cart> {\n return this._cartPost(\"/update-discount-codes\", { cartId, discountCodes });\n }\n}\n\nexport async function getCanopyApiGateway() {\n return CanopyApiGateway.setup();\n}\n"],
5
+ "mappings": "AAEA,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,SAAS;AAElB,SAAS,cAAc;AACvB,SAAS,oBAAoB;AAStB,MAAM,8BAA8B,WAAW;AAAA,EACpD;AAAA,EAEA,YAAY,QAAqC;AAC/C,UAAM,qBAAqB,OAAO,cAAc;AAChD,UAAM;AAAA,MACJ,SAAS,OAAO;AAAA,MAChB,OAAO,OAAO;AAAA,MACd,gBAAgB;AAAA,QACd,GAAG,OAAO;AAAA,QACV,YAAY;AAAA,MACd;AAAA,IACF,CAAC;AACD,SAAK,aAAa;AAAA,EACpB;AACF;AAEO,SAAS,wBACd,OACgC;AAChC,SAAO,iBAAiB;AAC1B;AAEA,MAAM,8BAA8B,sBAAsB;AAAA,EACxD,YAAY,QAAyD;AACnE,UAAM,EAAE,GAAG,QAAQ,YAAY,IAAI,CA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MAAM,aAAa;AAAA,IACjB;AAAA,IACA;AAAA,EACF,GAQkB;AAChB,WAAO,KAAK,UAAU,cAAc,EAAE,QAAQ,MAAM,CAAC;AAAA,EACvD;AAAA,EAEA,MAAM,gBAAgB;AAAA,IACpB;AAAA,IACA;AAAA,EACF,GAQkB;AAChB,WAAO,KAAK,UAAU,iBAAiB,EAAE,QAAQ,MAAM,CAAC;AAAA,EAC1D;AAAA,EAEA,MAAM,gBAAgB;AAAA,IACpB;AAAA,IACA;AAAA,EACF,GAGkB;AAChB,WAAO,KAAK,UAAU,iBAAiB,EAAE,QAAQ,QAAQ,CAAC;AAAA,EAC5D;AAAA,EAEA,MAAM,wBAAwB;AAAA,IAC5B;AAAA,IACA;AAAA,EACF,GAGkB;AAChB,WAAO,KAAK,UAAU,0BAA0B,EAAE,QAAQ,cAAc,CAAC;AAAA,EAC3E;AACF;AAEA,eAAsB,sBAAsB;AAC1C,SAAO,iBAAiB,MAAM;AAChC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * NOTE (Max, 2025-09-15): This hook is to be used for values that aren't available on the server (such as window.location).
3
+ *
4
+ * This hook will use a dummy value both on the server & on hydration. Then,
5
+ * after hydration, this useEffect will update the value to the actual value.
6
+ *
7
+ * The useEffect doesn't have any dependencies - it's designed to only run once. So if you expect your read() function to return
8
+ * different values through the lifecycle of the component, you should not use this hook.
9
+ */
10
+ export declare function useClientValue<T>(readValue: () => T, initialValue: T): T;
@@ -0,0 +1,12 @@
1
+ import * as React from "react";
2
+ function useClientValue(readValue, initialValue) {
3
+ const [value, setValue] = React.useState(initialValue);
4
+ React.useEffect(() => {
5
+ setValue(readValue());
6
+ }, []);
7
+ return value;
8
+ }
9
+ export {
10
+ useClientValue
11
+ };
12
+ //# sourceMappingURL=use-client-value.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../hooks/use-client-value.ts"],
4
+ "sourcesContent": ["import * as React from \"react\";\n\n/**\n * NOTE (Max, 2025-09-15): This hook is to be used for values that aren't available on the server (such as window.location).\n *\n * This hook will use a dummy value both on the server & on hydration. Then,\n * after hydration, this useEffect will update the value to the actual value.\n *\n * The useEffect doesn't have any dependencies - it's designed to only run once. So if you expect your read() function to return\n * different values through the lifecycle of the component, you should not use this hook.\n */\n\nexport function useClientValue<T>(readValue: () => T, initialValue: T) {\n const [value, setValue] = React.useState<T>(initialValue);\n\n /* eslint-disable replo/no-use-effect -- Legacy effect - may or may not be necessary */\n React.useEffect(() => {\n setValue(readValue());\n }, []);\n /* eslint-enable replo/no-use-effect */\n return value;\n}\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;AAYhB,SAAS,eAAkB,WAAoB,cAAiB;AACrE,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAY,YAAY;AAGxD,QAAM,UAAU,MAAM;AACpB,aAAS,UAAU,CAAC;AAAA,EACtB,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Use `useFormattedPrice` to format prices with proper currency and locale.
3
+ * @returns A formatted price string based on the price and currency code. It
4
+ * already takes into account the user's locale/browser.
5
+ * @example
6
+ * ```tsx
7
+ * import { useFormattedPrice } from "canopy-sdk/hooks/use-formatted-price";
8
+ *
9
+ * const originalPrice = 19.99;
10
+ * const originalPriceFormatted = useFormattedPrice(originalPrice, "USD");
11
+ * // Display the formatted price
12
+ * <p>{originalPriceFormatted}</p>;
13
+ * ```
14
+ */
15
+ export declare const useFormattedPrice: (price: number | null, currency: string | null) => string | null;
@@ -0,0 +1,19 @@
1
+ import { useClientValue } from "./use-client-value";
2
+ const useFormattedPrice = (price, currency) => {
3
+ const navigatorLanguage = useClientValue(
4
+ () => window.navigator.language,
5
+ "en-US"
6
+ );
7
+ if (!price) {
8
+ return null;
9
+ }
10
+ const priceFormatted = new Intl.NumberFormat(navigatorLanguage, {
11
+ style: "currency",
12
+ currency: currency ?? "USD"
13
+ }).format(price);
14
+ return priceFormatted;
15
+ };
16
+ export {
17
+ useFormattedPrice
18
+ };
19
+ //# sourceMappingURL=use-formatted-price.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../hooks/use-formatted-price.ts"],
4
+ "sourcesContent": ["/**\n * Use useFormattedPrice() hook to display prices with proper currency symbols and formatting. Pass in a price number and currency code (e.g., \"USD\") and it returns a formatted string like \"$19.99\".\n * @module\n */\nimport { useClientValue } from \"./use-client-value\";\n\n/**\n * Use `useFormattedPrice` to format prices with proper currency and locale.\n * @returns A formatted price string based on the price and currency code. It\n * already takes into account the user's locale/browser.\n * @example\n * ```tsx\n * import { useFormattedPrice } from \"canopy-sdk/hooks/use-formatted-price\";\n *\n * const originalPrice = 19.99;\n * const originalPriceFormatted = useFormattedPrice(originalPrice, \"USD\");\n * // Display the formatted price\n * <p>{originalPriceFormatted}</p>;\n * ```\n */\nexport const useFormattedPrice = (\n price: number | null,\n currency: string | null,\n) => {\n const navigatorLanguage = useClientValue(\n () => window.navigator.language,\n \"en-US\",\n );\n\n if (!price) {\n return null;\n }\n\n const priceFormatted = new Intl.NumberFormat(navigatorLanguage, {\n style: \"currency\",\n currency: currency ?? \"USD\",\n }).format(price);\n\n return priceFormatted;\n};\n"],
5
+ "mappings": "AAIA,SAAS,sBAAsB;AAgBxB,MAAM,oBAAoB,CAC/B,OACA,aACG;AACH,QAAM,oBAAoB;AAAA,IACxB,MAAM,OAAO,UAAU;AAAA,IACvB;AAAA,EACF;AAEA,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAEA,QAAM,iBAAiB,IAAI,KAAK,aAAa,mBAAmB;AAAA,IAC9D,OAAO;AAAA,IACP,UAAU,YAAY;AAAA,EACxB,CAAC,EAAE,OAAO,KAAK;AAEf,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ import { QueryClient } from "@tanstack/react-query";
2
+ export declare function getQueryClient(): QueryClient;
@@ -0,0 +1,34 @@
1
+ import {
2
+ defaultShouldDehydrateQuery,
3
+ isServer,
4
+ QueryClient
5
+ } from "@tanstack/react-query";
6
+ const STALE_TIME_MILLISECONDS = 60 * 1e3;
7
+ const makeQueryClient = () => {
8
+ return new QueryClient({
9
+ defaultOptions: {
10
+ queries: {
11
+ staleTime: STALE_TIME_MILLISECONDS
12
+ },
13
+ dehydrate: {
14
+ shouldDehydrateQuery: (query) => {
15
+ return defaultShouldDehydrateQuery(query) || query.state.status === "pending";
16
+ }
17
+ }
18
+ }
19
+ });
20
+ };
21
+ let browserQueryClient;
22
+ function getQueryClient() {
23
+ if (isServer) {
24
+ return makeQueryClient();
25
+ }
26
+ if (browserQueryClient == null) {
27
+ browserQueryClient = makeQueryClient();
28
+ }
29
+ return browserQueryClient;
30
+ }
31
+ export {
32
+ getQueryClient
33
+ };
34
+ //# sourceMappingURL=get-query-client.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ export type CheckoutProvider = "shopify" | "stripe" | "none";
2
+ export declare function getCheckoutProvider(): Promise<CheckoutProvider>;
@@ -0,0 +1,9 @@
1
+ import { getEnv } from "../env";
2
+ async function getCheckoutProvider() {
3
+ const env = await getEnv();
4
+ return env.CHECKOUT_PROVIDER ?? "none";
5
+ }
6
+ export {
7
+ getCheckoutProvider
8
+ };
9
+ //# sourceMappingURL=integration-utils.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../lib/integration-utils.ts"],
4
+ "sourcesContent": ["import { getEnv } from \"../env\";\n\nexport type CheckoutProvider = \"shopify\" | \"stripe\" | \"none\";\n\nexport async function getCheckoutProvider(): Promise<CheckoutProvider> {\n const env = await getEnv();\n return env.CHECKOUT_PROVIDER ?? \"none\";\n}\n"],
5
+ "mappings": "AAAA,SAAS,cAAc;AAIvB,eAAsB,sBAAiD;AACrE,QAAM,MAAM,MAAM,OAAO;AACzB,SAAO,IAAI,qBAAqB;AAClC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Utility functions for working with Shopify IDs and GIDs
3
+ */
4
+ /**
5
+ * Converts a legacy resource ID to a Shopify GraphQL ID
6
+ * @param id - The legacy resource ID (e.g., "123456")
7
+ * @param type - The Shopify resource type
8
+ * @returns The full Shopify GID (e.g., "gid://shopify/ProductVariant/123456")
9
+ */
10
+ export declare function convertLegacyResourceIdToGraphQLId(id: string, type: "Product" | "ProductVariant"): string;
11
+ /**
12
+ * Converts a Shopify GraphQL ID to a legacy resource ID
13
+ * @param id - The full Shopify GID (e.g., "gid://shopify/ProductVariant/123456")
14
+ * @returns The legacy resource ID (e.g., "123456")
15
+ */
16
+ export declare function convertGraphQLIdToLegacyResourceId(id: string): string;
@@ -0,0 +1,11 @@
1
+ function convertLegacyResourceIdToGraphQLId(id, type) {
2
+ return `gid://shopify/${type}/${id}`;
3
+ }
4
+ function convertGraphQLIdToLegacyResourceId(id) {
5
+ return id.split("/").pop() ?? id;
6
+ }
7
+ export {
8
+ convertGraphQLIdToLegacyResourceId,
9
+ convertLegacyResourceIdToGraphQLId
10
+ };
11
+ //# sourceMappingURL=shopify-utils.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../lib/shopify-utils.ts"],
4
+ "sourcesContent": ["/**\n * Utility functions for working with Shopify IDs and GIDs\n */\n\n/**\n * Converts a legacy resource ID to a Shopify GraphQL ID\n * @param id - The legacy resource ID (e.g., \"123456\")\n * @param type - The Shopify resource type\n * @returns The full Shopify GID (e.g., \"gid://shopify/ProductVariant/123456\")\n */\nexport function convertLegacyResourceIdToGraphQLId(\n id: string,\n type: \"Product\" | \"ProductVariant\",\n): string {\n return `gid://shopify/${type}/${id}`;\n}\n\n/**\n * Converts a Shopify GraphQL ID to a legacy resource ID\n * @param id - The full Shopify GID (e.g., \"gid://shopify/ProductVariant/123456\")\n * @returns The legacy resource ID (e.g., \"123456\")\n */\nexport function convertGraphQLIdToLegacyResourceId(id: string): string {\n return id.split(\"/\").pop() ?? id;\n}\n"],
5
+ "mappings": "AAUO,SAAS,mCACd,IACA,MACQ;AACR,SAAO,iBAAiB,IAAI,IAAI,EAAE;AACpC;AAOO,SAAS,mCAAmC,IAAoB;AACrE,SAAO,GAAG,MAAM,GAAG,EAAE,IAAI,KAAK;AAChC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Builds a base URL from an API host, using http for local hosts and https otherwise.
3
+ */
4
+ export declare function buildBaseUrl(apiHost: string): string;
@@ -0,0 +1,8 @@
1
+ function buildBaseUrl(apiHost) {
2
+ const isLocal = apiHost.startsWith("localhost") || apiHost.startsWith("127.0.0.1") || apiHost.startsWith("host.docker.internal");
3
+ return `${isLocal ? "http" : "https"}://${apiHost}`;
4
+ }
5
+ export {
6
+ buildBaseUrl
7
+ };
8
+ //# sourceMappingURL=url-utils.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../lib/url-utils.ts"],
4
+ "sourcesContent": ["/**\n * Builds a base URL from an API host, using http for local hosts and https otherwise.\n */\nexport function buildBaseUrl(apiHost: string): string {\n const isLocal =\n apiHost.startsWith(\"localhost\") ||\n apiHost.startsWith(\"127.0.0.1\") ||\n apiHost.startsWith(\"host.docker.internal\");\n return `${isLocal ? \"http\" : \"https\"}://${apiHost}`;\n}\n"],
5
+ "mappings": "AAGO,SAAS,aAAa,SAAyB;AACpD,QAAM,UACJ,QAAQ,WAAW,WAAW,KAC9B,QAAQ,WAAW,WAAW,KAC9B,QAAQ,WAAW,sBAAsB;AAC3C,SAAO,GAAG,UAAU,SAAS,OAAO,MAAM,OAAO;AACnD;",
6
+ "names": []
7
+ }
@@ -0,0 +1,11 @@
1
+ import type { ReactNode } from "react";
2
+ import type { FullCollection } from "../_vendor/schemas/agentTools/customIntegrations/loaders/product";
3
+ type CollectionLoaderProps = {
4
+ loaderKey: string;
5
+ handle?: string;
6
+ collectionGid?: string;
7
+ children: (data: FullCollection) => ReactNode;
8
+ fallback?: ReactNode;
9
+ };
10
+ export declare function CollectionLoader({ loaderKey, handle, collectionGid, children, fallback, }: CollectionLoaderProps): import("react/jsx-runtime").JSX.Element;
11
+ export {};
@@ -0,0 +1,53 @@
1
+ "use client";
2
+ import { Fragment, jsx } from "react/jsx-runtime";
3
+ import { Suspense } from "react";
4
+ import { useSuspenseQuery } from "@tanstack/react-query";
5
+ import { fullCollectionSchema } from "../_vendor/schemas/agentTools/customIntegrations/loaders/product.mjs";
6
+ import { invokeLoader } from "./invoke-loader";
7
+ import { LoaderErrorBoundary } from "./loader-error-boundary";
8
+ function CollectionLoaderInner({
9
+ loaderKey,
10
+ handle,
11
+ collectionGid,
12
+ children
13
+ }) {
14
+ const queryResult = useSuspenseQuery({
15
+ queryKey: [loaderKey, { handle, collectionGid }],
16
+ queryFn: async () => {
17
+ const loadedData = await invokeLoader({
18
+ loaderKey,
19
+ args: { handle, collectionGid }
20
+ });
21
+ return fullCollectionSchema.parse(loadedData);
22
+ }
23
+ });
24
+ return /* @__PURE__ */ jsx(Fragment, { children: children(queryResult.data) });
25
+ }
26
+ function CollectionLoader({
27
+ loaderKey,
28
+ handle,
29
+ collectionGid,
30
+ children,
31
+ fallback
32
+ }) {
33
+ return /* @__PURE__ */ jsx(
34
+ LoaderErrorBoundary,
35
+ {
36
+ fallback: fallback ?? null,
37
+ resetKey: `${loaderKey}:${handle ?? ""}:${collectionGid ?? ""}`,
38
+ children: /* @__PURE__ */ jsx(Suspense, { fallback: fallback ?? null, children: /* @__PURE__ */ jsx(
39
+ CollectionLoaderInner,
40
+ {
41
+ loaderKey,
42
+ handle,
43
+ collectionGid,
44
+ children
45
+ }
46
+ ) })
47
+ }
48
+ );
49
+ }
50
+ export {
51
+ CollectionLoader
52
+ };
53
+ //# sourceMappingURL=collection-loader.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../loaders/collection-loader.tsx"],
4
+ "sourcesContent": ["\"use client\";\n\nimport type { ReactNode } from \"react\";\nimport type { FullCollection } from \"schemas/agentTools/customIntegrations/loaders/product\";\n\nimport { Suspense } from \"react\";\n\nimport { useSuspenseQuery } from \"@tanstack/react-query\";\nimport { fullCollectionSchema } from \"schemas/agentTools/customIntegrations/loaders/product\";\n\nimport { invokeLoader } from \"./invoke-loader\";\nimport { LoaderErrorBoundary } from \"./loader-error-boundary\";\n\ntype CollectionLoaderProps = {\n loaderKey: string;\n handle?: string;\n collectionGid?: string;\n children: (data: FullCollection) => ReactNode;\n fallback?: ReactNode;\n};\n\nfunction CollectionLoaderInner({\n loaderKey,\n handle,\n collectionGid,\n children,\n}: Omit<CollectionLoaderProps, \"fallback\">) {\n const queryResult = useSuspenseQuery({\n queryKey: [loaderKey, { handle, collectionGid }],\n queryFn: async () => {\n const loadedData = await invokeLoader({\n loaderKey,\n args: { handle, collectionGid },\n });\n return fullCollectionSchema.parse(loadedData);\n },\n });\n\n return <>{children(queryResult.data)}</>;\n}\n\nexport function CollectionLoader({\n loaderKey,\n handle,\n collectionGid,\n children,\n fallback,\n}: CollectionLoaderProps) {\n return (\n <LoaderErrorBoundary\n fallback={fallback ?? null}\n resetKey={`${loaderKey}:${handle ?? \"\"}:${collectionGid ?? \"\"}`}\n >\n <Suspense fallback={fallback ?? null}>\n <CollectionLoaderInner\n loaderKey={loaderKey}\n handle={handle}\n collectionGid={collectionGid}\n >\n {children}\n </CollectionLoaderInner>\n </Suspense>\n </LoaderErrorBoundary>\n );\n}\n"],
5
+ "mappings": ";AAsCS;AAjCT,SAAS,gBAAgB;AAEzB,SAAS,wBAAwB;AACjC,SAAS,4BAA4B;AAErC,SAAS,oBAAoB;AAC7B,SAAS,2BAA2B;AAUpC,SAAS,sBAAsB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA4C;AAC1C,QAAM,cAAc,iBAAiB;AAAA,IACnC,UAAU,CAAC,WAAW,EAAE,QAAQ,cAAc,CAAC;AAAA,IAC/C,SAAS,YAAY;AACnB,YAAM,aAAa,MAAM,aAAa;AAAA,QACpC;AAAA,QACA,MAAM,EAAE,QAAQ,cAAc;AAAA,MAChC,CAAC;AACD,aAAO,qBAAqB,MAAM,UAAU;AAAA,IAC9C;AAAA,EACF,CAAC;AAED,SAAO,gCAAG,mBAAS,YAAY,IAAI,GAAE;AACvC;AAEO,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA0B;AACxB,SACE;AAAA,IAAC;AAAA;AAAA,MACC,UAAU,YAAY;AAAA,MACtB,UAAU,GAAG,SAAS,IAAI,UAAU,EAAE,IAAI,iBAAiB,EAAE;AAAA,MAE7D,8BAAC,YAAS,UAAU,YAAY,MAC9B;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA;AAAA,UAEC;AAAA;AAAA,MACH,GACF;AAAA;AAAA,EACF;AAEJ;",
6
+ "names": []
7
+ }
@@ -0,0 +1,12 @@
1
+ import type { ReactNode } from "react";
2
+ import type { PaginatedProducts } from "../_vendor/schemas/agentTools/customIntegrations/loaders/product";
3
+ type CollectionProductsLoaderProps = {
4
+ loaderKey: string;
5
+ collectionGid: string;
6
+ first?: number;
7
+ after?: string;
8
+ children: (data: PaginatedProducts) => ReactNode;
9
+ fallback?: ReactNode;
10
+ };
11
+ export declare function CollectionProductsLoader({ loaderKey, collectionGid, first, after, children, fallback, }: CollectionProductsLoaderProps): import("react/jsx-runtime").JSX.Element;
12
+ export {};