@putiikkipalvelu/storefront-sdk 0.3.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +368 -154
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +325 -13
- package/dist/index.d.ts +325 -13
- package/dist/index.js +365 -151
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/errors.ts","../src/utils/fetch.ts","../src/resources/store.ts","../src/resources/products.ts","../src/resources/categories.ts","../src/resources/cart.ts","../src/utils/pricing.ts","../src/utils/cart-calculations.ts","../src/resources/shipping.ts","../src/resources/customer.ts","../src/resources/order.ts","../src/resources/checkout.ts","../src/client.ts"],"sourcesContent":["/**\n * Base error class for all Storefront API errors\n */\nexport class StorefrontError extends Error {\n public readonly status: number;\n public readonly code: string;\n\n constructor(message: string, status: number, code: string) {\n super(message);\n this.name = \"StorefrontError\";\n this.status = status;\n this.code = code;\n\n // Maintains proper stack trace in V8 environments\n const ErrorWithCapture = Error as typeof Error & {\n captureStackTrace?: (target: object, constructor: Function) => void;\n };\n if (ErrorWithCapture.captureStackTrace) {\n ErrorWithCapture.captureStackTrace(this, StorefrontError);\n }\n }\n}\n\n/**\n * Error thrown when API returns 401 Unauthorized\n */\nexport class AuthError extends StorefrontError {\n constructor(message: string = \"Invalid or missing API key\") {\n super(message, 401, \"UNAUTHORIZED\");\n this.name = \"AuthError\";\n }\n}\n\n/**\n * Error thrown when API returns 429 Too Many Requests\n */\nexport class RateLimitError extends StorefrontError {\n public readonly retryAfter: number | null;\n\n constructor(message: string = \"Rate limit exceeded\", retryAfter: number | null = null) {\n super(message, 429, \"RATE_LIMIT_EXCEEDED\");\n this.name = \"RateLimitError\";\n this.retryAfter = retryAfter;\n }\n}\n\n/**\n * Error thrown when a requested resource is not found (404)\n */\nexport class NotFoundError extends StorefrontError {\n constructor(message: string = \"Resource not found\") {\n super(message, 404, \"NOT_FOUND\");\n this.name = \"NotFoundError\";\n }\n}\n\n/**\n * Error thrown when request validation fails (400)\n */\nexport class ValidationError extends StorefrontError {\n constructor(message: string = \"Validation failed\") {\n super(message, 400, \"VALIDATION_ERROR\");\n this.name = \"ValidationError\";\n }\n}\n\n/**\n * Error thrown when login fails due to unverified email\n * Contains customerId for resending verification email\n */\nexport class VerificationRequiredError extends StorefrontError {\n public readonly requiresVerification: true = true;\n public readonly customerId: string;\n\n constructor(message: string, customerId: string) {\n super(message, 403, \"VERIFICATION_REQUIRED\");\n this.name = \"VerificationRequiredError\";\n this.customerId = customerId;\n }\n}\n","import type { FetchOptions } from \"../types/index.js\";\r\nimport {\r\n StorefrontError,\r\n AuthError,\r\n RateLimitError,\r\n NotFoundError,\r\n ValidationError,\r\n VerificationRequiredError,\r\n} from \"./errors.js\";\r\n\r\n// SDK version - will be replaced during build or read from package.json\r\nconst SDK_VERSION = \"0.1.0\";\r\n\r\nexport interface FetcherConfig {\r\n apiKey: string;\r\n baseUrl: string;\r\n timeout?: number;\r\n}\r\n\r\nexport interface RequestOptions extends FetchOptions {\r\n method?: \"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\";\r\n body?: unknown;\r\n params?: Record<string, string | number | boolean | undefined>;\r\n}\r\n\r\n/**\r\n * Fetcher instance type returned by createFetcher\r\n */\r\nexport type Fetcher = ReturnType<typeof createFetcher>;\r\n\r\n/**\r\n * Create a configured fetcher instance for making API requests\r\n */\r\nexport function createFetcher(config: FetcherConfig) {\r\n const { apiKey, baseUrl, timeout = 30000 } = config;\r\n\r\n /**\r\n * Make an authenticated request to the Storefront API\r\n */\r\n async function request<T>(endpoint: string, options: RequestOptions = {}): Promise<T> {\r\n const { method = \"GET\", body, params, signal, headers = {}, cache, ...frameworkOptions } = options;\r\n\r\n // Build URL with query parameters\r\n // Ensure baseUrl ends with / for proper URL resolution\r\n const normalizedBase = baseUrl.endsWith(\"/\") ? baseUrl : `${baseUrl}/`;\r\n // Remove leading slash from endpoint to avoid URL resolution issues\r\n const normalizedEndpoint = endpoint.startsWith(\"/\") ? endpoint.slice(1) : endpoint;\r\n const url = new URL(normalizedEndpoint, normalizedBase);\r\n\r\n if (params) {\r\n for (const [key, value] of Object.entries(params)) {\r\n if (value !== undefined) {\r\n url.searchParams.set(key, String(value));\r\n }\r\n }\r\n }\r\n\r\n // Create abort controller for timeout\r\n const controller = new AbortController();\r\n const timeoutId = setTimeout(() => controller.abort(), timeout);\r\n\r\n // Combine signals if provided\r\n const combinedSignal = signal\r\n ? AbortSignal.any([signal, controller.signal])\r\n : controller.signal;\r\n\r\n try {\r\n const fetchOptions: RequestInit & Record<string, unknown> = {\r\n method,\r\n headers: {\r\n \"Content-Type\": \"application/json\",\r\n \"x-api-key\": apiKey,\r\n \"x-sdk-version\": SDK_VERSION,\r\n ...headers,\r\n },\r\n body: body ? JSON.stringify(body) : undefined,\r\n signal: combinedSignal,\r\n cache,\r\n // Spread framework-specific options (e.g., Next.js `next`, or any other)\r\n ...frameworkOptions,\r\n };\r\n\r\n const response = await fetch(url.toString(), fetchOptions);\r\n\r\n clearTimeout(timeoutId);\r\n\r\n // Handle error responses\r\n if (!response.ok) {\r\n await handleErrorResponse(response);\r\n }\r\n\r\n // Parse response\r\n const data = await response.json();\r\n return data as T;\r\n } catch (error) {\r\n clearTimeout(timeoutId);\r\n\r\n // Re-throw SDK errors\r\n if (error instanceof StorefrontError) {\r\n throw error;\r\n }\r\n\r\n // Handle abort/timeout\r\n if (error instanceof Error && error.name === \"AbortError\") {\r\n throw new StorefrontError(\"Request timed out\", 408, \"TIMEOUT\");\r\n }\r\n\r\n // Handle network errors\r\n throw new StorefrontError(\r\n error instanceof Error ? error.message : \"Network error\",\r\n 0,\r\n \"NETWORK_ERROR\"\r\n );\r\n }\r\n }\r\n\r\n return { request };\r\n}\r\n\r\n/**\r\n * Error response JSON structure\r\n */\r\ninterface ErrorResponseJson {\r\n error?: string;\r\n requiresVerification?: boolean;\r\n customerId?: string;\r\n}\r\n\r\n/**\r\n * Handle non-2xx responses and throw appropriate errors\r\n */\r\nasync function handleErrorResponse(response: Response): Promise<never> {\r\n let errorData: ErrorResponseJson = {};\r\n\r\n try {\r\n const json: unknown = await response.json();\r\n if (json && typeof json === \"object\") {\r\n errorData = json as ErrorResponseJson;\r\n }\r\n } catch {\r\n // Response body is not JSON\r\n }\r\n\r\n const message = errorData.error || response.statusText || \"Request failed\";\r\n\r\n // Check for verification required error (can be 400 or 403)\r\n if (errorData.requiresVerification && errorData.customerId) {\r\n throw new VerificationRequiredError(message, errorData.customerId);\r\n }\r\n\r\n switch (response.status) {\r\n case 401:\r\n throw new AuthError(message);\r\n\r\n case 404:\r\n throw new NotFoundError(message);\r\n\r\n case 429: {\r\n const retryAfter = response.headers.get(\"Retry-After\");\r\n throw new RateLimitError(message, retryAfter ? parseInt(retryAfter, 10) : null);\r\n }\r\n\r\n case 400:\r\n throw new ValidationError(message);\r\n\r\n default:\r\n throw new StorefrontError(message, response.status, \"API_ERROR\");\r\n }\r\n}\r\n","import type { FetchOptions, StoreConfig } from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Store resource for fetching store configuration\r\n */\r\nexport function createStoreResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Get the complete store configuration including settings, SEO, payments, campaigns, and features.\r\n *\r\n * @example Basic usage\r\n * ```typescript\r\n * const config = await client.store.getConfig();\r\n * console.log(config.store.name);\r\n * console.log(config.seo.seoTitle);\r\n * console.log(config.campaigns);\r\n * ```\r\n *\r\n * @example Next.js - with caching\r\n * ```typescript\r\n * const config = await client.store.getConfig({\r\n * next: { revalidate: 300, tags: ['store-config'] }\r\n * });\r\n * ```\r\n *\r\n * @example Nuxt - wrap with useAsyncData\r\n * ```typescript\r\n * const { data: config } = await useAsyncData(\r\n * 'store-config',\r\n * () => client.store.getConfig()\r\n * );\r\n * ```\r\n *\r\n * @example Standard fetch caching\r\n * ```typescript\r\n * const config = await client.store.getConfig({\r\n * cache: 'force-cache'\r\n * });\r\n * ```\r\n */\r\n async getConfig(options?: FetchOptions): Promise<StoreConfig> {\r\n return fetcher.request<StoreConfig>(\"/api/storefront/v1/store-config\", {\r\n ...options,\r\n });\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the store resource\r\n */\r\nexport type StoreResource = ReturnType<typeof createStoreResource>;\r\n","import type {\r\n FetchOptions,\r\n Product,\r\n ProductDetail,\r\n ProductListResponse,\r\n ProductCountResponse,\r\n ProductListParams,\r\n} from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Products resource for fetching product data\r\n */\r\nexport function createProductsResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Get latest products ordered by creation date (newest first).\r\n *\r\n * @param take - Number of products to return (required, must be >= 1)\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Array of products\r\n *\r\n * @example Basic usage\r\n * ```typescript\r\n * const products = await client.products.latest(6);\r\n * ```\r\n *\r\n * @example Next.js - with caching\r\n * ```typescript\r\n * const products = await client.products.latest(6, {\r\n * next: { revalidate: 3600, tags: ['products'] }\r\n * });\r\n * ```\r\n */\r\n async latest(take: number, options?: FetchOptions): Promise<Product[]> {\r\n return fetcher.request<Product[]>(\"/api/storefront/v1/latest-products\", {\r\n params: { take },\r\n ...options,\r\n });\r\n },\r\n\r\n /**\r\n * Get a single product by its URL slug.\r\n *\r\n * @param slug - Product URL slug\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Full product details including categories and variations\r\n * @throws NotFoundError if product doesn't exist or is not visible\r\n *\r\n * @example Basic usage\r\n * ```typescript\r\n * const product = await client.products.getBySlug('my-product');\r\n * console.log(product.name, product.categories);\r\n * ```\r\n *\r\n * @example Next.js - with caching\r\n * ```typescript\r\n * const product = await client.products.getBySlug('my-product', {\r\n * next: { revalidate: 3600, tags: ['product', 'my-product'] }\r\n * });\r\n * ```\r\n */\r\n async getBySlug(\r\n slug: string,\r\n options?: FetchOptions\r\n ): Promise<ProductDetail> {\r\n return fetcher.request<ProductDetail>(\r\n `/api/storefront/v1/product/${encodeURIComponent(slug)}`,\r\n {\r\n ...options,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Get total product count, optionally filtered by category.\r\n *\r\n * @param slugs - Optional category slugs to filter by\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Object with count property\r\n *\r\n * @example Get total count\r\n * ```typescript\r\n * const { count } = await client.products.count();\r\n * console.log(`Total products: ${count}`);\r\n * ```\r\n *\r\n * @example Get count for specific category\r\n * ```typescript\r\n * const { count } = await client.products.count(['shoes']);\r\n * console.log(`Products in shoes: ${count}`);\r\n * ```\r\n */\r\n async count(\r\n slugs?: string[],\r\n options?: FetchOptions\r\n ): Promise<ProductCountResponse> {\r\n const searchParams = new URLSearchParams();\r\n if (slugs?.length) {\r\n slugs.forEach((s) => searchParams.append(\"slugs\", s));\r\n }\r\n const query = searchParams.toString();\r\n const endpoint = `/api/storefront/v1/products-count${query ? `?${query}` : \"\"}`;\r\n\r\n return fetcher.request<ProductCountResponse>(endpoint, {\r\n ...options,\r\n });\r\n },\r\n\r\n /**\r\n * Get sorted products with pagination.\r\n * Uses optimized sorting with pre-computed effective prices.\r\n *\r\n * @param params - Query parameters (slugs, page, pageSize, sort)\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Products list with totalCount for pagination\r\n *\r\n * @example Basic usage\r\n * ```typescript\r\n * const { products, totalCount } = await client.products.sorted({\r\n * page: 1,\r\n * pageSize: 12,\r\n * sort: 'newest'\r\n * });\r\n * ```\r\n *\r\n * @example Filter by category\r\n * ```typescript\r\n * const { products, totalCount } = await client.products.sorted({\r\n * slugs: ['shoes', 'clothing'],\r\n * page: 1,\r\n * pageSize: 24,\r\n * sort: 'price_asc'\r\n * });\r\n * ```\r\n *\r\n * @example Real-time data (no cache)\r\n * ```typescript\r\n * const data = await client.products.sorted(\r\n * { page: 1, pageSize: 12 },\r\n * { cache: 'no-store' }\r\n * );\r\n * ```\r\n */\r\n async sorted(\r\n params: ProductListParams = {},\r\n options?: FetchOptions\r\n ): Promise<ProductListResponse> {\r\n const searchParams = new URLSearchParams();\r\n if (params.page) searchParams.set(\"page\", params.page.toString());\r\n if (params.pageSize)\r\n searchParams.set(\"pageSize\", params.pageSize.toString());\r\n if (params.sort) searchParams.set(\"sort\", params.sort);\r\n if (params.slugs?.length) {\r\n params.slugs.forEach((s) => searchParams.append(\"slugs\", s));\r\n }\r\n const query = searchParams.toString();\r\n const endpoint = `/api/storefront/v1/sorted-products${query ? `?${query}` : \"\"}`;\r\n\r\n return fetcher.request<ProductListResponse>(endpoint, {\r\n ...options,\r\n });\r\n },\r\n\r\n /**\r\n * Get filtered products with pagination.\r\n * Similar to sorted() but without totalCount in response.\r\n * Useful for sitemaps and bulk fetches.\r\n *\r\n * @param params - Query parameters (slugs, page, pageSize, sort)\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Products list with category name\r\n *\r\n * @example Fetch all products for sitemap\r\n * ```typescript\r\n * const { products } = await client.products.filtered({\r\n * slugs: ['all-products'],\r\n * page: 1,\r\n * pageSize: 1000\r\n * });\r\n * ```\r\n */\r\n async filtered(\r\n params: ProductListParams = {},\r\n options?: FetchOptions\r\n ): Promise<Omit<ProductListResponse, \"totalCount\">> {\r\n const searchParams = new URLSearchParams();\r\n if (params.page) searchParams.set(\"page\", params.page.toString());\r\n if (params.pageSize)\r\n searchParams.set(\"pageSize\", params.pageSize.toString());\r\n if (params.sort) searchParams.set(\"sort\", params.sort);\r\n if (params.slugs?.length) {\r\n params.slugs.forEach((s) => searchParams.append(\"slugs\", s));\r\n }\r\n const query = searchParams.toString();\r\n const endpoint = `/api/storefront/v1/filtered-products${query ? `?${query}` : \"\"}`;\r\n\r\n return fetcher.request<Omit<ProductListResponse, \"totalCount\">>(\r\n endpoint,\r\n {\r\n ...options,\r\n }\r\n );\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the products resource\r\n */\r\nexport type ProductsResource = ReturnType<typeof createProductsResource>;\r\n","import type { FetchOptions, Category, CategoryResponse } from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Categories resource for fetching category data\r\n */\r\nexport function createCategoriesResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Get all top-level categories with nested children.\r\n * Returns a hierarchical tree of categories (up to 5 levels deep).\r\n *\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Array of top-level categories with nested children\r\n *\r\n * @example Basic usage\r\n * ```typescript\r\n * const categories = await client.categories.list();\r\n * categories.forEach(cat => {\r\n * console.log(cat.name, cat.children.length);\r\n * });\r\n * ```\r\n *\r\n * @example Next.js - with caching\r\n * ```typescript\r\n * const categories = await client.categories.list({\r\n * next: { revalidate: 3600, tags: ['categories'] }\r\n * });\r\n * ```\r\n */\r\n async list(options?: FetchOptions): Promise<Category[]> {\r\n return fetcher.request<Category[]>(\"/api/storefront/v1/categories\", {\r\n ...options,\r\n });\r\n },\r\n\r\n /**\r\n * Get a single category by its URL slug.\r\n *\r\n * @param slug - Category URL slug\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Category data\r\n * @throws NotFoundError if category doesn't exist\r\n *\r\n * @example Basic usage\r\n * ```typescript\r\n * const { category } = await client.categories.getBySlug('shoes');\r\n * console.log(category.name);\r\n * ```\r\n *\r\n * @example Next.js - with caching\r\n * ```typescript\r\n * const { category } = await client.categories.getBySlug('shoes', {\r\n * next: { revalidate: 86400, tags: ['category', 'shoes'] }\r\n * });\r\n * ```\r\n */\r\n async getBySlug(\r\n slug: string,\r\n options?: FetchOptions\r\n ): Promise<CategoryResponse> {\r\n return fetcher.request<CategoryResponse>(\r\n `/api/storefront/v1/categories/${encodeURIComponent(slug)}`,\r\n {\r\n ...options,\r\n }\r\n );\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the categories resource\r\n */\r\nexport type CategoriesResource = ReturnType<typeof createCategoriesResource>;\r\n","/**\r\n * Cart Resource\r\n *\r\n * Methods for managing the shopping cart stored in Redis.\r\n * Supports both guest carts (via cartId) and authenticated user carts (via sessionId).\r\n */\r\n\r\nimport type {\r\n FetchOptions,\r\n CartResponse,\r\n CartValidationResponse,\r\n CartSessionOptions,\r\n AddToCartParams,\r\n UpdateCartQuantityParams,\r\n RemoveFromCartParams,\r\n} from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Build headers object for cart operations\r\n */\r\nfunction buildCartHeaders(options?: CartSessionOptions): Record<string, string> {\r\n const headers: Record<string, string> = {};\r\n if (options?.cartId) {\r\n headers[\"x-cart-id\"] = options.cartId;\r\n }\r\n if (options?.sessionId) {\r\n headers[\"x-session-id\"] = options.sessionId;\r\n }\r\n return headers;\r\n}\r\n\r\n/**\r\n * Cart resource for managing shopping cart\r\n */\r\nexport function createCartResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Fetch the current cart contents.\r\n *\r\n * @param options - Cart session options (cartId for guests, sessionId for logged-in users)\r\n * @param fetchOptions - Fetch options (caching, headers, etc.)\r\n * @returns Cart items and cartId (for guests)\r\n *\r\n * @example Guest user\r\n * ```typescript\r\n * const cartId = localStorage.getItem('cart-id');\r\n * const { items, cartId: newCartId } = await client.cart.get({ cartId });\r\n * ```\r\n *\r\n * @example Logged-in user\r\n * ```typescript\r\n * const { items } = await client.cart.get({ sessionId });\r\n * ```\r\n */\r\n async get(\r\n options?: CartSessionOptions,\r\n fetchOptions?: FetchOptions\r\n ): Promise<CartResponse> {\r\n return fetcher.request<CartResponse>(\"/api/storefront/v1/cart\", {\r\n method: \"GET\",\r\n headers: buildCartHeaders(options),\r\n ...fetchOptions,\r\n });\r\n },\r\n\r\n /**\r\n * Add an item to the cart.\r\n * If the item already exists, quantity is incremented.\r\n *\r\n * @param params - Add to cart parameters\r\n * @param fetchOptions - Fetch options\r\n * @returns Updated cart with new cartId for guests\r\n * @throws ValidationError if quantity exceeds available stock\r\n *\r\n * @example Add product\r\n * ```typescript\r\n * const { items, cartId } = await client.cart.addItem({\r\n * cartId: existingCartId,\r\n * productId: 'prod_123',\r\n * quantity: 2\r\n * });\r\n * // Save cartId for future requests\r\n * localStorage.setItem('cart-id', cartId);\r\n * ```\r\n *\r\n * @example Add product with variation\r\n * ```typescript\r\n * const { items, cartId } = await client.cart.addItem({\r\n * cartId,\r\n * productId: 'prod_123',\r\n * variationId: 'var_456',\r\n * quantity: 1\r\n * });\r\n * ```\r\n */\r\n async addItem(\r\n params: AddToCartParams,\r\n fetchOptions?: FetchOptions\r\n ): Promise<CartResponse> {\r\n const { cartId, sessionId, ...body } = params;\r\n return fetcher.request<CartResponse>(\"/api/storefront/v1/cart\", {\r\n method: \"POST\",\r\n headers: buildCartHeaders({ sessionId }),\r\n body: {\r\n cartId,\r\n ...body,\r\n },\r\n ...fetchOptions,\r\n });\r\n },\r\n\r\n /**\r\n * Update item quantity by delta (atomic operation).\r\n * Use positive delta to increase, negative to decrease.\r\n * Minimum quantity is 1 (use removeItem to delete).\r\n *\r\n * @param params - Update quantity parameters\r\n * @param fetchOptions - Fetch options\r\n * @returns Updated cart\r\n * @throws NotFoundError if item not in cart or quantity would go below 1\r\n *\r\n * @example Increment quantity\r\n * ```typescript\r\n * const { items } = await client.cart.updateQuantity({\r\n * cartId,\r\n * productId: 'prod_123',\r\n * delta: 1\r\n * });\r\n * ```\r\n *\r\n * @example Decrement quantity\r\n * ```typescript\r\n * const { items } = await client.cart.updateQuantity({\r\n * cartId,\r\n * productId: 'prod_123',\r\n * variationId: 'var_456',\r\n * delta: -1\r\n * });\r\n * ```\r\n */\r\n async updateQuantity(\r\n params: UpdateCartQuantityParams,\r\n fetchOptions?: FetchOptions\r\n ): Promise<CartResponse> {\r\n const { cartId, sessionId, ...body } = params;\r\n return fetcher.request<CartResponse>(\"/api/storefront/v1/cart\", {\r\n method: \"PATCH\",\r\n headers: buildCartHeaders({ sessionId }),\r\n body: {\r\n cartId,\r\n ...body,\r\n },\r\n ...fetchOptions,\r\n });\r\n },\r\n\r\n /**\r\n * Remove an item from the cart.\r\n *\r\n * @param params - Remove from cart parameters\r\n * @param fetchOptions - Fetch options\r\n * @returns Updated cart\r\n *\r\n * @example Remove product\r\n * ```typescript\r\n * const { items } = await client.cart.removeItem({\r\n * cartId,\r\n * productId: 'prod_123'\r\n * });\r\n * ```\r\n *\r\n * @example Remove variation\r\n * ```typescript\r\n * const { items } = await client.cart.removeItem({\r\n * cartId,\r\n * productId: 'prod_123',\r\n * variationId: 'var_456'\r\n * });\r\n * ```\r\n */\r\n async removeItem(\r\n params: RemoveFromCartParams,\r\n fetchOptions?: FetchOptions\r\n ): Promise<CartResponse> {\r\n const { cartId, sessionId, ...body } = params;\r\n return fetcher.request<CartResponse>(\"/api/storefront/v1/cart\", {\r\n method: \"DELETE\",\r\n headers: buildCartHeaders({ sessionId }),\r\n body: {\r\n cartId,\r\n ...body,\r\n },\r\n ...fetchOptions,\r\n });\r\n },\r\n\r\n /**\r\n * Validate cart before checkout.\r\n * Checks product availability, stock levels, and prices.\r\n * Auto-fixes issues (removes unavailable items, adjusts quantities).\r\n *\r\n * @param options - Cart session options\r\n * @param fetchOptions - Fetch options\r\n * @returns Validated cart with change metadata\r\n *\r\n * @example Validate before checkout\r\n * ```typescript\r\n * const { items, hasChanges, changes } = await client.cart.validate({ cartId });\r\n *\r\n * if (hasChanges) {\r\n * if (changes.removedItems > 0) {\r\n * notify('Some items were removed (out of stock)');\r\n * }\r\n * if (changes.quantityAdjusted > 0) {\r\n * notify('Some quantities were adjusted');\r\n * }\r\n * if (changes.priceChanged > 0) {\r\n * notify('Some prices have changed');\r\n * }\r\n * }\r\n * ```\r\n */\r\n async validate(\r\n options?: CartSessionOptions,\r\n fetchOptions?: FetchOptions\r\n ): Promise<CartValidationResponse> {\r\n return fetcher.request<CartValidationResponse>(\r\n \"/api/storefront/v1/cart/validate\",\r\n {\r\n method: \"GET\",\r\n headers: buildCartHeaders(options),\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the cart resource\r\n */\r\nexport type CartResource = ReturnType<typeof createCartResource>;\r\n","/**\r\n * Pricing Utilities\r\n *\r\n * Helper functions for calculating prices with sale logic.\r\n */\r\n\r\nimport type { ProductDetail, ProductVariation } from \"../types/products.js\";\r\nimport type { PriceInfo } from \"../types/cart.js\";\r\n\r\n/**\r\n * Check if a sale is currently active based on start and end dates.\r\n *\r\n * @param startDate - Sale start date (ISO string, Date, null, or undefined)\r\n * @param endDate - Sale end date (ISO string, Date, null, or undefined)\r\n * @returns true if the sale is currently active\r\n *\r\n * @example\r\n * ```typescript\r\n * // No dates = always active\r\n * isSaleActive(null, null); // true\r\n *\r\n * // Only start date = active if past start\r\n * isSaleActive(\"2024-01-01\", null); // true if today >= Jan 1\r\n *\r\n * // Both dates = active if within range\r\n * isSaleActive(\"2024-01-01\", \"2024-12-31\"); // true if within range\r\n * ```\r\n */\r\nexport function isSaleActive(\r\n startDate: Date | string | null | undefined,\r\n endDate: Date | string | null | undefined\r\n): boolean {\r\n // If no dates are set, sale is considered active\r\n if (!startDate && !endDate) {\r\n return true;\r\n }\r\n\r\n const now = new Date();\r\n const start = startDate ? new Date(startDate) : null;\r\n const end = endDate ? new Date(endDate) : null;\r\n\r\n // If only start date is set\r\n if (start && !end) {\r\n return now >= start;\r\n }\r\n\r\n // If only end date is set\r\n if (!start && end) {\r\n return now <= end;\r\n }\r\n\r\n // If both dates are set\r\n if (start && end) {\r\n return now >= start && now <= end;\r\n }\r\n\r\n return true;\r\n}\r\n\r\n/**\r\n * Get price information for a product or variation.\r\n * Returns the effective price (sale or regular) and sale status.\r\n * All prices are in cents.\r\n *\r\n * @param product - The product to get price info for\r\n * @param variation - Optional variation (takes precedence over product price)\r\n * @returns Price information with effective price, original price, and sale status\r\n *\r\n * @example\r\n * ```typescript\r\n * // Product without variation\r\n * const priceInfo = getPriceInfo(product);\r\n * console.log(priceInfo.effectivePrice); // 1990 (cents)\r\n * console.log(priceInfo.isOnSale); // true\r\n *\r\n * // Product with selected variation\r\n * const priceInfo = getPriceInfo(product, selectedVariation);\r\n * ```\r\n */\r\nexport function getPriceInfo(\r\n product: ProductDetail,\r\n variation?: ProductVariation\r\n): PriceInfo {\r\n if (variation) {\r\n // Use variation pricing\r\n const isOnSale =\r\n isSaleActive(variation.saleStartDate, variation.saleEndDate) &&\r\n variation.salePrice !== null;\r\n\r\n const originalPrice = variation.price ?? product.price;\r\n const effectivePrice = isOnSale\r\n ? (variation.salePrice ?? originalPrice)\r\n : originalPrice;\r\n\r\n return {\r\n effectivePrice,\r\n originalPrice,\r\n isOnSale,\r\n salePercent: isOnSale ? (variation.salePercent ?? null) : null,\r\n };\r\n }\r\n\r\n // Use product pricing\r\n const isOnSale =\r\n isSaleActive(product.saleStartDate, product.saleEndDate) &&\r\n product.salePrice !== null;\r\n\r\n const originalPrice = product.price;\r\n const effectivePrice = isOnSale\r\n ? (product.salePrice ?? originalPrice)\r\n : originalPrice;\r\n\r\n return {\r\n effectivePrice,\r\n originalPrice,\r\n isOnSale,\r\n salePercent: isOnSale ? (product.salePercent ?? null) : null,\r\n };\r\n}\r\n","/**\r\n * Cart Calculation Utilities\r\n *\r\n * Functions for calculating cart totals with campaign discounts.\r\n */\r\n\r\nimport type { CartItem } from \"../types/cart.js\";\r\nimport type { Campaign } from \"../types/storeconfig.js\";\r\nimport type {\r\n CalculatedCartItem,\r\n CartCalculationResult,\r\n} from \"../types/cart.js\";\r\nimport { getPriceInfo } from \"./pricing.js\";\r\n\r\n/**\r\n * Internal type for tracking eligible units in Buy X Pay Y campaigns\r\n */\r\ninterface EligibleUnit {\r\n price: number;\r\n productId: string;\r\n variationId?: string;\r\n originalItem: CartItem;\r\n}\r\n\r\n/**\r\n * Calculate cart totals with campaign discounts applied.\r\n *\r\n * Supports BUY_X_PAY_Y campaigns: Buy X items, pay for Y (e.g., Buy 3 Pay 2 = 1 free item)\r\n *\r\n * @param items - Cart items to calculate\r\n * @param campaigns - Active campaigns to apply\r\n * @returns Calculation result with totals and savings\r\n *\r\n * @example\r\n * ```typescript\r\n * const result = calculateCartWithCampaigns(cartItems, activeCampaigns);\r\n *\r\n * console.log(result.cartTotal); // 4990 (cents)\r\n * console.log(result.totalSavings); // 1990 (cents)\r\n *\r\n * // Render calculated items\r\n * result.calculatedItems.forEach(({ item, paidQuantity, freeQuantity }) => {\r\n * console.log(`${item.product.name}: ${paidQuantity} paid, ${freeQuantity} free`);\r\n * });\r\n * ```\r\n */\r\nexport function calculateCartWithCampaigns(\r\n items: CartItem[],\r\n campaigns: Campaign[]\r\n): CartCalculationResult {\r\n // Find applicable campaigns\r\n const buyXPayYCampaign = campaigns.find(\r\n (c) => c.type === \"BUY_X_PAY_Y\" && c.isActive\r\n );\r\n\r\n // Calculate original total (without campaign discounts)\r\n const originalTotal = items.reduce((total, { product, variation, cartQuantity }) => {\r\n const priceInfo = getPriceInfo(product, variation);\r\n return total + priceInfo.effectivePrice * cartQuantity;\r\n }, 0);\r\n\r\n // No Buy X Pay Y campaign - return items as-is\r\n if (!buyXPayYCampaign?.BuyXPayYCampaign) {\r\n const calculatedItems = items.map((item) => ({\r\n item,\r\n paidQuantity: item.cartQuantity,\r\n freeQuantity: 0,\r\n totalQuantity: item.cartQuantity,\r\n }));\r\n\r\n return {\r\n calculatedItems,\r\n cartTotal: originalTotal,\r\n originalTotal,\r\n totalSavings: 0,\r\n };\r\n }\r\n\r\n // Apply Buy X Pay Y campaign\r\n const { buyQuantity, payQuantity, applicableCategories } =\r\n buyXPayYCampaign.BuyXPayYCampaign;\r\n const applicableCategoryIds = new Set(\r\n applicableCategories.map((c) => c.id)\r\n );\r\n\r\n // Find all individual units eligible for the campaign\r\n const eligibleUnits: EligibleUnit[] = items.flatMap((item) => {\r\n const { product, variation } = item;\r\n const itemCategories = product.categories?.map((cat) => cat.id) || [];\r\n\r\n // Check if any of the product's categories are in the campaign's list\r\n const isEligible = itemCategories.some((id) =>\r\n applicableCategoryIds.has(id)\r\n );\r\n\r\n if (isEligible) {\r\n const priceInfo = getPriceInfo(product, variation);\r\n\r\n // Create an entry for each single unit of the item\r\n return Array.from({ length: item.cartQuantity }, () => ({\r\n price: priceInfo.effectivePrice,\r\n productId: product.id,\r\n variationId: variation?.id,\r\n originalItem: item,\r\n }));\r\n }\r\n\r\n return [];\r\n });\r\n\r\n // Not enough eligible items - return original quantities\r\n if (eligibleUnits.length < buyQuantity) {\r\n const calculatedItems = items.map((item) => ({\r\n item,\r\n paidQuantity: item.cartQuantity,\r\n freeQuantity: 0,\r\n totalQuantity: item.cartQuantity,\r\n }));\r\n\r\n return {\r\n calculatedItems,\r\n cartTotal: originalTotal,\r\n originalTotal,\r\n totalSavings: 0,\r\n };\r\n }\r\n\r\n // Sort by price to find the cheapest items to make free\r\n eligibleUnits.sort((a, b) => a.price - b.price);\r\n\r\n const numToMakeFree = buyQuantity - payQuantity;\r\n const itemsToMakeFree = eligibleUnits.slice(0, numToMakeFree);\r\n\r\n // Calculate total savings from free items\r\n const totalSavings = itemsToMakeFree.reduce(\r\n (sum, item) => sum + item.price,\r\n 0\r\n );\r\n\r\n // Create a map to count how many units of each product/variation should be free\r\n const freeCountMap = new Map<string, number>();\r\n for (const freebie of itemsToMakeFree) {\r\n const key = `${freebie.productId}${freebie.variationId ? `_${freebie.variationId}` : \"\"}`;\r\n freeCountMap.set(key, (freeCountMap.get(key) || 0) + 1);\r\n }\r\n\r\n // Calculate paid and free quantities for each item\r\n const calculatedItems: CalculatedCartItem[] = items.map((item) => {\r\n const key = `${item.product.id}${item.variation?.id ? `_${item.variation.id}` : \"\"}`;\r\n const freeQuantity = freeCountMap.get(key) || 0;\r\n const paidQuantity = item.cartQuantity - freeQuantity;\r\n\r\n return {\r\n item,\r\n paidQuantity: Math.max(0, paidQuantity),\r\n freeQuantity,\r\n totalQuantity: item.cartQuantity,\r\n };\r\n });\r\n\r\n // Calculate final cart total after Buy X Pay Y discounts\r\n const cartTotal = originalTotal - totalSavings;\r\n\r\n return {\r\n calculatedItems,\r\n cartTotal,\r\n originalTotal,\r\n totalSavings,\r\n };\r\n}\r\n","/**\r\n * Shipping Resource\r\n *\r\n * Methods for fetching shipment methods and pickup locations.\r\n */\r\n\r\nimport type {\r\n FetchOptions,\r\n ShipmentMethodsResponse,\r\n CartItem,\r\n Campaign,\r\n} from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\nimport { calculateCartWithCampaigns } from \"../utils/cart-calculations.js\";\r\n\r\n/**\r\n * Calculate total cart weight from cart items\r\n */\r\nfunction calculateCartWeight(items: CartItem[]): number {\r\n return items.reduce((total, item) => {\r\n const itemWeight = item.variation?.weight ?? item.product.weight ?? 0.5;\r\n return total + itemWeight * item.cartQuantity;\r\n }, 0);\r\n}\r\n\r\n/**\r\n * Calculate total cart value in cents from cart items\r\n * Uses sale price if available, otherwise regular price\r\n */\r\nfunction calculateCartTotal(items: CartItem[]): number {\r\n return items.reduce((total, item) => {\r\n // Use variation price if exists, otherwise product price\r\n // Prefer salePrice over regular price\r\n const itemPrice = item.variation\r\n ? (item.variation.salePrice ?? item.variation.price)\r\n : (item.product.salePrice ?? item.product.price);\r\n return total + itemPrice * item.cartQuantity;\r\n }, 0);\r\n}\r\n\r\n/**\r\n * Options for fetching shipment methods with weight-based filtering\r\n */\r\nexport interface GetShippingOptionsParams extends FetchOptions {\r\n /** Cart items - weight and total will be calculated automatically */\r\n cartItems?: CartItem[];\r\n /** Active campaigns - used to calculate cart total with discounts for free shipping */\r\n campaigns?: Campaign[];\r\n /** Country code (default: \"FI\") */\r\n country?: string;\r\n}\r\n\r\n/**\r\n * Shipping resource for fetching shipment methods and pickup locations\r\n */\r\nexport function createShippingResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Get shipping options for a specific postal code.\r\n * Returns pickup points and home delivery options in a unified format.\r\n *\r\n * **Pickup points are returned first** as they are more popular in Finland.\r\n *\r\n * @param postalCode - Customer's postal code (e.g., \"00100\")\r\n * @param options - Fetch options including optional cartItems for weight-based filtering\r\n * @returns Unified shipping options (pickupPoints sorted by distance, homeDelivery sorted by price)\r\n *\r\n * @example\r\n * ```typescript\r\n * const { pickupPoints, homeDelivery } = await client.shipping.getOptions(\"00100\");\r\n *\r\n * // Show pickup points (more popular in Finland)\r\n * pickupPoints.forEach(point => {\r\n * console.log(`${point.name} - ${point.carrier}`);\r\n * console.log(` ${point.address}, ${point.city}`);\r\n * console.log(` ${(point.distance! / 1000).toFixed(1)} km away`);\r\n * console.log(` Price: ${point.price / 100}€`);\r\n * });\r\n *\r\n * // Show home delivery options\r\n * homeDelivery.forEach(option => {\r\n * console.log(`${option.name}: ${option.price / 100}€`);\r\n * if (option.estimatedDelivery) {\r\n * console.log(` Delivery: ${option.estimatedDelivery} days`);\r\n * }\r\n * });\r\n * ```\r\n *\r\n * @example Weight-based filtering\r\n * ```typescript\r\n * const options = await client.shipping.getOptions(\"00100\", {\r\n * cartItems: cartItems\r\n * });\r\n * // Only shows methods that support the cart's total weight\r\n * ```\r\n *\r\n * @example International shipping\r\n * ```typescript\r\n * const options = await client.shipping.getOptions(\"112 22\", {\r\n * country: \"SE\"\r\n * });\r\n * ```\r\n */\r\n async getOptions(\r\n postalCode: string,\r\n options?: GetShippingOptionsParams\r\n ): Promise<ShipmentMethodsResponse> {\r\n const params = new URLSearchParams();\r\n\r\n if (options?.cartItems?.length) {\r\n const cartWeight = calculateCartWeight(options.cartItems);\r\n params.set(\"cartWeight\", cartWeight.toString());\r\n\r\n // Send cart total for free shipping calculation\r\n // Use calculateCartWithCampaigns if campaigns provided (accounts for discounts)\r\n const cartTotal = options.campaigns\r\n ? calculateCartWithCampaigns(options.cartItems, options.campaigns).cartTotal\r\n : calculateCartTotal(options.cartItems);\r\n params.set(\"cartTotal\", cartTotal.toString());\r\n }\r\n\r\n if (options?.country) {\r\n params.set(\"country\", options.country);\r\n }\r\n\r\n const queryString = params.toString();\r\n const url = `/api/storefront/v1/shipment-methods/${encodeURIComponent(postalCode)}${queryString ? `?${queryString}` : \"\"}`;\r\n\r\n return fetcher.request<ShipmentMethodsResponse>(url, {\r\n method: \"GET\",\r\n ...options,\r\n });\r\n },\r\n\r\n /**\r\n * @deprecated Use getOptions() instead. This method is kept for backwards compatibility.\r\n */\r\n async getWithLocations(\r\n postalCode: string,\r\n options?: GetShippingOptionsParams\r\n ): Promise<ShipmentMethodsResponse> {\r\n return this.getOptions(postalCode, options);\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the shipping resource\r\n */\r\nexport type ShippingResource = ReturnType<typeof createShippingResource>;\r\n","/**\r\n * Customer Resource\r\n *\r\n * Methods for customer authentication and account management.\r\n * Supports session-based authentication with the x-session-id header.\r\n */\r\n\r\nimport type {\r\n FetchOptions,\r\n RegisterData,\r\n RegisterResponse,\r\n LoginOptions,\r\n LoginResponse,\r\n LogoutResponse,\r\n GetUserResponse,\r\n VerifyEmailResponse,\r\n ResendVerificationResponse,\r\n UpdateProfileData,\r\n UpdateProfileResponse,\r\n DeleteAccountResponse,\r\n GetOrdersResponse,\r\n WishlistResponse,\r\n AddToWishlistResponse,\r\n RemoveFromWishlistResponse,\r\n ForgotPasswordResponse,\r\n ResetPasswordResponse,\r\n} from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Build headers for authenticated customer requests\r\n */\r\nfunction buildSessionHeaders(sessionId: string): Record<string, string> {\r\n return { \"x-session-id\": sessionId };\r\n}\r\n\r\n/**\r\n * Customer resource for authentication and account management\r\n */\r\nexport function createCustomerResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Register a new customer account.\r\n * A verification email is sent automatically by the server.\r\n * The customer must verify their email before logging in.\r\n *\r\n * @param data - Registration data (firstName, lastName, email, password)\r\n * @param fetchOptions - Fetch options\r\n * @returns Created customer data and success message\r\n *\r\n * @example\r\n * ```typescript\r\n * const { customer, message } = await client.customer.register({\r\n * firstName: 'John',\r\n * lastName: 'Doe',\r\n * email: 'john@example.com',\r\n * password: 'securePassword123'\r\n * });\r\n *\r\n * // Verification email is sent automatically by the server\r\n * console.log('Account created:', message);\r\n * ```\r\n */\r\n async register(\r\n data: RegisterData,\r\n fetchOptions?: FetchOptions\r\n ): Promise<RegisterResponse> {\r\n return fetcher.request<RegisterResponse>(\r\n \"/api/storefront/v1/customer/(auth)/register\",\r\n {\r\n method: \"POST\",\r\n body: data,\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Log in an existing customer.\r\n * Returns a session ID that must be stored and passed to authenticated endpoints.\r\n *\r\n * @param email - Customer's email address\r\n * @param password - Customer's password\r\n * @param options - Login options (optional cartId for cart merging)\r\n * @param fetchOptions - Fetch options\r\n * @returns Session ID and customer data\r\n * @throws ValidationError if email is not verified (check error for requiresVerification)\r\n *\r\n * @example\r\n * ```typescript\r\n * try {\r\n * const { sessionId, customer, expiresAt } = await client.customer.login(\r\n * 'john@example.com',\r\n * 'securePassword123',\r\n * { cartId: guestCartId } // Optional: merge guest cart\r\n * );\r\n *\r\n * // Store sessionId in a cookie\r\n * cookies().set('session-id', sessionId, {\r\n * httpOnly: true,\r\n * expires: new Date(expiresAt)\r\n * });\r\n * } catch (error) {\r\n * if (error.requiresVerification) {\r\n * // Prompt user to verify email\r\n * await client.customer.resendVerification(error.customerId);\r\n * }\r\n * }\r\n * ```\r\n */\r\n async login(\r\n email: string,\r\n password: string,\r\n options?: LoginOptions,\r\n fetchOptions?: FetchOptions\r\n ): Promise<LoginResponse> {\r\n const headers: Record<string, string> = {};\r\n if (options?.cartId) {\r\n headers[\"x-cart-id\"] = options.cartId;\r\n }\r\n\r\n return fetcher.request<LoginResponse>(\r\n \"/api/storefront/v1/customer/(auth)/login\",\r\n {\r\n method: \"POST\",\r\n body: { email, password },\r\n headers,\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Log out the current customer and invalidate their session.\r\n * If the customer had items in their cart, they are migrated to a new guest cart.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param fetchOptions - Fetch options\r\n * @returns Logout confirmation with optional new guest cart ID\r\n *\r\n * @example\r\n * ```typescript\r\n * const { cartId } = await client.customer.logout(sessionId);\r\n *\r\n * // Clear session cookie\r\n * cookies().delete('session-id');\r\n *\r\n * // If cart was migrated, store the new guest cart ID\r\n * if (cartId) {\r\n * cookies().set('cart-id', cartId);\r\n * }\r\n * ```\r\n */\r\n async logout(\r\n sessionId: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<LogoutResponse> {\r\n return fetcher.request<LogoutResponse>(\r\n \"/api/storefront/v1/customer/(auth)/logout\",\r\n {\r\n method: \"POST\",\r\n headers: buildSessionHeaders(sessionId),\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Get the currently authenticated customer's profile.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param fetchOptions - Fetch options\r\n * @returns Current customer data\r\n * @throws AuthError if session is invalid or expired\r\n *\r\n * @example\r\n * ```typescript\r\n * const sessionId = cookies().get('session-id')?.value;\r\n * if (sessionId) {\r\n * const { customer } = await client.customer.getUser(sessionId);\r\n * console.log(`Welcome back, ${customer.firstName}!`);\r\n * }\r\n * ```\r\n */\r\n async getUser(\r\n sessionId: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<GetUserResponse> {\r\n return fetcher.request<GetUserResponse>(\r\n \"/api/storefront/v1/customer/(auth)/get-user\",\r\n {\r\n method: \"GET\",\r\n headers: buildSessionHeaders(sessionId),\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Verify a customer's email address using the token sent during registration.\r\n *\r\n * @param token - Email verification token\r\n * @param fetchOptions - Fetch options\r\n * @returns Verification confirmation\r\n * @throws ValidationError if token is invalid or expired\r\n *\r\n * @example\r\n * ```typescript\r\n * // Token comes from the verification email link\r\n * const token = searchParams.get('token');\r\n *\r\n * const { message } = await client.customer.verifyEmail(token);\r\n * console.log(message); // \"Email verified successfully. You can now log in.\"\r\n * ```\r\n */\r\n async verifyEmail(\r\n token: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<VerifyEmailResponse> {\r\n return fetcher.request<VerifyEmailResponse>(\r\n \"/api/storefront/v1/customer/(auth)/verify-email\",\r\n {\r\n method: \"GET\",\r\n params: { token },\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Resend the verification email for an unverified customer.\r\n * A new verification email is sent automatically by the server.\r\n *\r\n * @param customerId - The customer's ID (from failed login response)\r\n * @param fetchOptions - Fetch options\r\n * @returns Success message\r\n * @throws ValidationError if customer is already verified or not found\r\n *\r\n * @example\r\n * ```typescript\r\n * // After login fails with requiresVerification\r\n * const { message } = await client.customer.resendVerification(customerId);\r\n *\r\n * // Verification email is sent automatically by the server\r\n * console.log(message); // \"Verification email sent.\"\r\n * ```\r\n */\r\n async resendVerification(\r\n customerId: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<ResendVerificationResponse> {\r\n return fetcher.request<ResendVerificationResponse>(\r\n \"/api/storefront/v1/customer/(auth)/resend-verification\",\r\n {\r\n method: \"POST\",\r\n body: { customerId },\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Request a password reset for a customer account.\r\n * The server sends a password reset email directly to the customer.\r\n * Returns success even if email doesn't exist (to prevent email enumeration).\r\n *\r\n * Note: The reset token is never exposed to the client for security.\r\n * The email is sent server-side with the reset link.\r\n *\r\n * @param email - Customer's email address\r\n * @param fetchOptions - Fetch options\r\n * @returns Generic success message (same whether email exists or not)\r\n *\r\n * @example\r\n * ```typescript\r\n * const response = await client.customer.forgotPassword('john@example.com');\r\n *\r\n * // Always show same message to user (email sent server-side)\r\n * console.log(response.message);\r\n * // \"If an account exists with that email, password reset instructions have been sent.\"\r\n * ```\r\n */\r\n async forgotPassword(\r\n email: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<ForgotPasswordResponse> {\r\n return fetcher.request<ForgotPasswordResponse>(\r\n \"/api/storefront/v1/customer/(auth)/forgot-password\",\r\n {\r\n method: \"POST\",\r\n body: { email },\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Reset a customer's password using a valid reset token.\r\n * The token is sent via email by the forgotPassword endpoint.\r\n * After successful reset, all existing sessions are invalidated.\r\n *\r\n * @param token - Password reset token (from email link)\r\n * @param password - New password (minimum 8 characters)\r\n * @param fetchOptions - Fetch options\r\n * @returns Success confirmation\r\n * @throws ValidationError if token is invalid or expired\r\n *\r\n * @example\r\n * ```typescript\r\n * // Token comes from the reset email link\r\n * const token = searchParams.get('token');\r\n *\r\n * try {\r\n * const { message } = await client.customer.resetPassword(token, newPassword);\r\n * console.log(message); // \"Password reset successful...\"\r\n *\r\n * // Redirect to login page\r\n * redirect('/login?reset=success');\r\n * } catch (error) {\r\n * if (error instanceof ValidationError) {\r\n * // Token invalid or expired\r\n * console.error('Please request a new password reset');\r\n * }\r\n * }\r\n * ```\r\n */\r\n async resetPassword(\r\n token: string,\r\n password: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<ResetPasswordResponse> {\r\n return fetcher.request<ResetPasswordResponse>(\r\n \"/api/storefront/v1/customer/(auth)/reset-password\",\r\n {\r\n method: \"POST\",\r\n body: { token, password },\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n // =========================================================================\r\n // Profile Management Methods\r\n // =========================================================================\r\n\r\n /**\r\n * Update the authenticated customer's profile.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param data - Profile data to update (firstName, lastName, email)\r\n * @param fetchOptions - Fetch options\r\n * @returns Updated customer data\r\n * @throws AuthError if session is invalid\r\n * @throws ValidationError if email is already taken by another customer\r\n *\r\n * @example\r\n * ```typescript\r\n * const { customer } = await client.customer.updateProfile(sessionId, {\r\n * firstName: 'Jane',\r\n * lastName: 'Smith',\r\n * email: 'jane.smith@example.com'\r\n * });\r\n *\r\n * console.log('Profile updated:', customer.email);\r\n * ```\r\n */\r\n async updateProfile(\r\n sessionId: string,\r\n data: UpdateProfileData,\r\n fetchOptions?: FetchOptions\r\n ): Promise<UpdateProfileResponse> {\r\n return fetcher.request<UpdateProfileResponse>(\r\n \"/api/storefront/v1/customer/edit-user\",\r\n {\r\n method: \"PATCH\",\r\n headers: buildSessionHeaders(sessionId),\r\n body: data,\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Delete the authenticated customer's account.\r\n * This action is permanent and cannot be undone.\r\n * All associated data (sessions, wishlist, etc.) will be deleted.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param fetchOptions - Fetch options\r\n * @returns Deletion confirmation\r\n * @throws AuthError if session is invalid\r\n *\r\n * @example\r\n * ```typescript\r\n * // Confirm with user before calling\r\n * if (confirm('Are you sure you want to delete your account?')) {\r\n * await client.customer.deleteAccount(sessionId);\r\n *\r\n * // Clear session cookie\r\n * cookies().delete('session-id');\r\n *\r\n * // Redirect to home page\r\n * redirect('/');\r\n * }\r\n * ```\r\n */\r\n async deleteAccount(\r\n sessionId: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<DeleteAccountResponse> {\r\n return fetcher.request<DeleteAccountResponse>(\r\n \"/api/storefront/v1/customer/delete-user\",\r\n {\r\n method: \"DELETE\",\r\n headers: buildSessionHeaders(sessionId),\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Get the customer's order history.\r\n * Returns all orders with line items and product details.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param customerId - The customer's ID\r\n * @param fetchOptions - Fetch options\r\n * @returns List of customer orders\r\n *\r\n * @example\r\n * ```typescript\r\n * const { orders } = await client.customer.getOrders(sessionId, customerId);\r\n *\r\n * orders.forEach(order => {\r\n * console.log(`Order #${order.orderNumber}: ${order.status}`);\r\n * order.OrderLineItems.forEach(item => {\r\n * console.log(` - ${item.name} x${item.quantity}`);\r\n * });\r\n * });\r\n * ```\r\n */\r\n async getOrders(\r\n sessionId: string,\r\n customerId: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<GetOrdersResponse> {\r\n return fetcher.request<GetOrdersResponse>(\r\n `/api/storefront/v1/customer/get-orders/${customerId}`,\r\n {\r\n method: \"GET\",\r\n headers: buildSessionHeaders(sessionId),\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n // =========================================================================\r\n // Wishlist (Nested Resource)\r\n // =========================================================================\r\n\r\n /**\r\n * Wishlist management methods.\r\n * Access via `client.customer.wishlist.get()`, `.add()`, `.remove()`.\r\n */\r\n wishlist: {\r\n /**\r\n * Get the customer's wishlist.\r\n * Returns all wishlist items with product and variation details.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param fetchOptions - Fetch options\r\n * @returns Wishlist items with product details\r\n * @throws AuthError if session is invalid\r\n *\r\n * @example\r\n * ```typescript\r\n * const { items } = await client.customer.wishlist.get(sessionId);\r\n *\r\n * items.forEach(item => {\r\n * console.log(`${item.product.name} - $${item.product.price / 100}`);\r\n * if (item.variation) {\r\n * const options = item.variation.options\r\n * .map(o => `${o.optionType.name}: ${o.value}`)\r\n * .join(', ');\r\n * console.log(` Variant: ${options}`);\r\n * }\r\n * });\r\n * ```\r\n */\r\n async get(\r\n sessionId: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<WishlistResponse> {\r\n return fetcher.request<WishlistResponse>(\r\n \"/api/storefront/v1/customer/wishlist\",\r\n {\r\n method: \"GET\",\r\n headers: buildSessionHeaders(sessionId),\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Add a product to the customer's wishlist.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param productId - The product ID to add\r\n * @param variationId - Optional variation ID (for products with variations)\r\n * @param fetchOptions - Fetch options\r\n * @returns Success message\r\n * @throws AuthError if session is invalid\r\n * @throws ValidationError if product already in wishlist\r\n *\r\n * @example\r\n * ```typescript\r\n * // Add a simple product\r\n * await client.customer.wishlist.add(sessionId, 'prod_123');\r\n *\r\n * // Add a product with a specific variation\r\n * await client.customer.wishlist.add(sessionId, 'prod_123', 'var_456');\r\n * ```\r\n */\r\n async add(\r\n sessionId: string,\r\n productId: string,\r\n variationId?: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<AddToWishlistResponse> {\r\n return fetcher.request<AddToWishlistResponse>(\r\n \"/api/storefront/v1/customer/wishlist\",\r\n {\r\n method: \"POST\",\r\n headers: buildSessionHeaders(sessionId),\r\n body: { productId, variationId },\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Remove a product from the customer's wishlist.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param productId - The product ID to remove\r\n * @param variationId - Optional variation ID (must match if item was added with variation)\r\n * @param fetchOptions - Fetch options\r\n * @returns Success message\r\n * @throws AuthError if session is invalid\r\n * @throws NotFoundError if item not in wishlist\r\n *\r\n * @example\r\n * ```typescript\r\n * // Remove a simple product\r\n * await client.customer.wishlist.remove(sessionId, 'prod_123');\r\n *\r\n * // Remove a specific variation\r\n * await client.customer.wishlist.remove(sessionId, 'prod_123', 'var_456');\r\n * ```\r\n */\r\n async remove(\r\n sessionId: string,\r\n productId: string,\r\n variationId?: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<RemoveFromWishlistResponse> {\r\n return fetcher.request<RemoveFromWishlistResponse>(\r\n \"/api/storefront/v1/customer/wishlist\",\r\n {\r\n method: \"DELETE\",\r\n headers: buildSessionHeaders(sessionId),\r\n body: { productId, variationId },\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the customer resource\r\n */\r\nexport type CustomerResource = ReturnType<typeof createCustomerResource>;\r\n","import type { FetchOptions, Order } from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Order resource for fetching order details\r\n *\r\n * Used for order confirmation pages and viewing order details.\r\n * For customer order history, use the customer.getOrders() method instead.\r\n */\r\nexport function createOrderResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Get order details by ID.\r\n *\r\n * Retrieves complete order information including line items,\r\n * customer data, and shipment method with tracking info.\r\n *\r\n * @param orderId - The order ID to fetch\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Complete order details\r\n * @throws NotFoundError if order doesn't exist or belongs to different store\r\n *\r\n * @example Basic usage (order confirmation page)\r\n * ```typescript\r\n * const order = await client.order.get(orderId);\r\n * console.log(`Order #${order.orderNumber} - ${order.status}`);\r\n * console.log(`Total: ${order.totalAmount / 100} EUR`);\r\n * ```\r\n *\r\n * @example Next.js - with caching\r\n * ```typescript\r\n * const order = await client.order.get(orderId, {\r\n * next: { revalidate: 60, tags: ['order', orderId] }\r\n * });\r\n * ```\r\n *\r\n * @example Display line items\r\n * ```typescript\r\n * const order = await client.order.get(orderId);\r\n * order.OrderLineItems.forEach(item => {\r\n * if (item.itemType !== 'SHIPPING') {\r\n * console.log(`${item.name} x${item.quantity} = ${item.totalAmount / 100} EUR`);\r\n * }\r\n * });\r\n * ```\r\n *\r\n * @example Show tracking info\r\n * ```typescript\r\n * const order = await client.order.get(orderId);\r\n * if (order.orderShipmentMethod?.trackingNumber) {\r\n * console.log(`Tracking: ${order.orderShipmentMethod.trackingNumber}`);\r\n * order.orderShipmentMethod.trackingUrls?.forEach(url => {\r\n * console.log(`Track at: ${url}`);\r\n * });\r\n * }\r\n * ```\r\n */\r\n async get(orderId: string, options?: FetchOptions): Promise<Order> {\r\n return fetcher.request<Order>(\r\n `/api/storefront/v1/order/${encodeURIComponent(orderId)}`,\r\n {\r\n ...options,\r\n }\r\n );\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the order resource\r\n */\r\nexport type OrderResource = ReturnType<typeof createOrderResource>;\r\n","import type {\r\n FetchOptions,\r\n CheckoutParams,\r\n StripeCheckoutResponse,\r\n PaytrailCheckoutResponse,\r\n} from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Extended options for checkout requests\r\n *\r\n * Checkout requires cart and session context via headers.\r\n */\r\nexport interface CheckoutOptions extends FetchOptions {\r\n /**\r\n * Cart ID for guest checkout.\r\n * Pass this when the user is not logged in.\r\n */\r\n cartId?: string;\r\n /**\r\n * Session ID for authenticated checkout.\r\n * Pass this when the user is logged in.\r\n */\r\n sessionId?: string;\r\n}\r\n\r\n/**\r\n * Checkout resource for payment processing\r\n *\r\n * Handles both Stripe and Paytrail payment providers.\r\n */\r\nexport function createCheckoutResource(fetcher: Fetcher) {\r\n /**\r\n * Build headers with cart/session context\r\n */\r\n function buildCheckoutHeaders(options?: CheckoutOptions): Record<string, string> {\r\n const headers: Record<string, string> = {};\r\n if (options?.cartId) {\r\n headers[\"x-cart-id\"] = options.cartId;\r\n }\r\n if (options?.sessionId) {\r\n headers[\"x-session-id\"] = options.sessionId;\r\n }\r\n return headers;\r\n }\r\n\r\n /**\r\n * Build checkout request body\r\n */\r\n function buildCheckoutBody(params: CheckoutParams) {\r\n return {\r\n orderId: params.orderId,\r\n chosenShipmentMethod: params.shipmentMethod,\r\n customerData: params.customerData,\r\n successUrl: params.successUrl,\r\n cancelUrl: params.cancelUrl,\r\n };\r\n }\r\n\r\n return {\r\n /**\r\n * Create a Stripe checkout session.\r\n *\r\n * Redirects the user to Stripe's hosted checkout page.\r\n * Cart items are validated and stock is reserved on the server.\r\n *\r\n * @param params - Checkout parameters (customer data, shipping, URLs)\r\n * @param options - Checkout options including cart/session context\r\n * @returns URL to redirect user to Stripe checkout\r\n * @throws ValidationError for invalid data or empty cart\r\n * @throws StorefrontError for inventory issues\r\n *\r\n * @example Basic usage with redirect\r\n * ```typescript\r\n * const { url } = await client.checkout.stripe({\r\n * customerData: {\r\n * first_name: \"John\",\r\n * last_name: \"Doe\",\r\n * email: \"john@example.com\",\r\n * address: \"123 Main St\",\r\n * postal_code: \"00100\",\r\n * city: \"Helsinki\",\r\n * phone: \"+358401234567\"\r\n * },\r\n * shipmentMethod: {\r\n * shipmentMethodId: \"ship_123\",\r\n * pickupId: null\r\n * },\r\n * orderId: \"order_abc123\",\r\n * successUrl: \"https://mystore.com/success\",\r\n * cancelUrl: \"https://mystore.com/cancel\"\r\n * }, {\r\n * cartId: \"cart_xyz\", // For guest users\r\n * sessionId: \"sess_123\" // For logged-in users\r\n * });\r\n *\r\n * // Redirect to Stripe\r\n * window.location.href = url;\r\n * ```\r\n */\r\n async stripe(\r\n params: CheckoutParams,\r\n options?: CheckoutOptions\r\n ): Promise<StripeCheckoutResponse> {\r\n const headers = buildCheckoutHeaders(options);\r\n const body = buildCheckoutBody(params);\r\n\r\n return fetcher.request<StripeCheckoutResponse>(\r\n \"/api/storefront/v1/payments/stripe/checkout\",\r\n {\r\n method: \"POST\",\r\n body,\r\n headers: {\r\n ...options?.headers,\r\n ...headers,\r\n },\r\n ...options,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Create a Paytrail checkout session.\r\n *\r\n * Returns payment providers for Finnish payment methods.\r\n * Cart items are validated and stock is reserved on the server.\r\n *\r\n * @param params - Checkout parameters (customer data, shipping, URLs)\r\n * @param options - Checkout options including cart/session context\r\n * @returns Paytrail response with available payment providers\r\n * @throws ValidationError for invalid data or empty cart\r\n * @throws StorefrontError for inventory issues\r\n *\r\n * @example Display payment providers\r\n * ```typescript\r\n * const response = await client.checkout.paytrail({\r\n * customerData: {\r\n * first_name: \"Matti\",\r\n * last_name: \"Meikäläinen\",\r\n * email: \"matti@example.fi\",\r\n * address: \"Mannerheimintie 1\",\r\n * postal_code: \"00100\",\r\n * city: \"Helsinki\",\r\n * phone: \"+358401234567\"\r\n * },\r\n * shipmentMethod: {\r\n * shipmentMethodId: \"ship_123\",\r\n * pickupId: \"pickup_456\" // For pickup points\r\n * },\r\n * orderId: \"order_abc123\",\r\n * successUrl: \"https://mystore.com/success\",\r\n * cancelUrl: \"https://mystore.com/cancel\"\r\n * }, {\r\n * cartId: \"cart_xyz\"\r\n * });\r\n *\r\n * // Group providers by type\r\n * const banks = response.providers.filter(p => p.group === \"bank\");\r\n * const mobile = response.providers.filter(p => p.group === \"mobile\");\r\n * const cards = response.providers.filter(p => p.group === \"creditcard\");\r\n * ```\r\n *\r\n * @example Submit payment form\r\n * ```typescript\r\n * const provider = response.providers.find(p => p.id === \"nordea\");\r\n *\r\n * // Create and submit a form\r\n * const form = document.createElement(\"form\");\r\n * form.method = \"POST\";\r\n * form.action = provider.url;\r\n *\r\n * provider.parameters.forEach(({ name, value }) => {\r\n * const input = document.createElement(\"input\");\r\n * input.type = \"hidden\";\r\n * input.name = name;\r\n * input.value = value;\r\n * form.appendChild(input);\r\n * });\r\n *\r\n * document.body.appendChild(form);\r\n * form.submit();\r\n * ```\r\n */\r\n async paytrail(\r\n params: CheckoutParams,\r\n options?: CheckoutOptions\r\n ): Promise<PaytrailCheckoutResponse> {\r\n const headers = buildCheckoutHeaders(options);\r\n const body = buildCheckoutBody(params);\r\n\r\n return fetcher.request<PaytrailCheckoutResponse>(\r\n \"/api/storefront/v1/payments/paytrail/checkout\",\r\n {\r\n method: \"POST\",\r\n body,\r\n headers: {\r\n ...options?.headers,\r\n ...headers,\r\n },\r\n ...options,\r\n }\r\n );\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the checkout resource\r\n */\r\nexport type CheckoutResource = ReturnType<typeof createCheckoutResource>;\r\n","import type { StorefrontClientConfig } from \"./types/index.js\";\nimport { createFetcher } from \"./utils/fetch.js\";\nimport { createStoreResource, type StoreResource } from \"./resources/store.js\";\nimport {\n createProductsResource,\n type ProductsResource,\n} from \"./resources/products.js\";\nimport {\n createCategoriesResource,\n type CategoriesResource,\n} from \"./resources/categories.js\";\nimport { createCartResource, type CartResource } from \"./resources/cart.js\";\nimport {\n createShippingResource,\n type ShippingResource,\n} from \"./resources/shipping.js\";\nimport {\n createCustomerResource,\n type CustomerResource,\n} from \"./resources/customer.js\";\nimport {\n createOrderResource,\n type OrderResource,\n} from \"./resources/order.js\";\nimport {\n createCheckoutResource,\n type CheckoutResource,\n} from \"./resources/checkout.js\";\n\n/**\n * The Storefront API client\n */\nexport interface StorefrontClient {\n /**\n * The base URL for API requests\n */\n readonly baseUrl: string;\n\n /**\n * Store configuration resource\n */\n readonly store: StoreResource;\n\n /**\n * Products resource\n */\n readonly products: ProductsResource;\n\n /**\n * Categories resource\n */\n readonly categories: CategoriesResource;\n\n /**\n * Cart resource\n */\n readonly cart: CartResource;\n\n /**\n * Shipping resource\n */\n readonly shipping: ShippingResource;\n\n /**\n * Customer authentication and account management resource\n */\n readonly customer: CustomerResource;\n\n /**\n * Order resource for fetching order details\n */\n readonly order: OrderResource;\n\n /**\n * Checkout resource for payment processing\n */\n readonly checkout: CheckoutResource;\n}\n\n/**\n * Create a new Storefront API client\n */\nexport function createStorefrontClient(config: StorefrontClientConfig): StorefrontClient {\n if (!config.apiKey) {\n throw new Error(\"apiKey is required\");\n }\n if (!config.baseUrl) {\n throw new Error(\"baseUrl is required\");\n }\n\n // Ensure baseUrl doesn't have trailing slash\n const baseUrl = config.baseUrl.replace(/\\/$/, \"\");\n\n // Create the fetcher for making authenticated requests\n const fetcher = createFetcher({\n apiKey: config.apiKey,\n baseUrl,\n timeout: config.timeout,\n });\n\n return {\n baseUrl,\n store: createStoreResource(fetcher),\n products: createProductsResource(fetcher),\n categories: createCategoriesResource(fetcher),\n cart: createCartResource(fetcher),\n shipping: createShippingResource(fetcher),\n customer: createCustomerResource(fetcher),\n order: createOrderResource(fetcher),\n checkout: createCheckoutResource(fetcher),\n };\n}\n"],"mappings":";AAGO,IAAM,kBAAN,MAAM,yBAAwB,MAAM;AAAA,EAIzC,YAAY,SAAiB,QAAgB,MAAc;AACzD,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AAGZ,UAAM,mBAAmB;AAGzB,QAAI,iBAAiB,mBAAmB;AACtC,uBAAiB,kBAAkB,MAAM,gBAAe;AAAA,IAC1D;AAAA,EACF;AACF;AAKO,IAAM,YAAN,cAAwB,gBAA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IAClC,UAAU,uBAAuB,OAAO;AAAA,IACxC,YAAY,yBAAyB,OAAO;AAAA,IAC5C,MAAM,mBAAmB,OAAO;AAAA,IAChC,UAAU,uBAAuB,OAAO;AAAA,IACxC,UAAU,uBAAuB,OAAO;AAAA,IACxC,OAAO,oBAAoB,OAAO;AAAA,IAClC,UAAU,uBAAuB,OAAO;AAAA,EAC1C;AACF;","names":["isOnSale","originalPrice","effectivePrice","calculatedItems"]}
|
|
1
|
+
{"version":3,"sources":["../src/utils/errors.ts","../src/utils/fetch.ts","../src/resources/store.ts","../src/resources/products.ts","../src/resources/categories.ts","../src/utils/pricing.ts","../src/utils/cart-calculations.ts","../src/resources/cart.ts","../src/resources/shipping.ts","../src/resources/customer.ts","../src/resources/order.ts","../src/resources/checkout.ts","../src/resources/discount-code.ts","../src/client.ts","../src/utils/discount.ts"],"sourcesContent":["/**\n * Base error class for all Storefront API errors\n */\nexport class StorefrontError extends Error {\n public readonly status: number;\n public readonly code: string;\n\n constructor(message: string, status: number, code: string) {\n super(message);\n this.name = \"StorefrontError\";\n this.status = status;\n this.code = code;\n\n // Maintains proper stack trace in V8 environments\n const ErrorWithCapture = Error as typeof Error & {\n captureStackTrace?: (target: object, constructor: Function) => void;\n };\n if (ErrorWithCapture.captureStackTrace) {\n ErrorWithCapture.captureStackTrace(this, StorefrontError);\n }\n }\n}\n\n/**\n * Error thrown when API returns 401 Unauthorized\n */\nexport class AuthError extends StorefrontError {\n constructor(message: string = \"Invalid or missing API key\") {\n super(message, 401, \"UNAUTHORIZED\");\n this.name = \"AuthError\";\n }\n}\n\n/**\n * Error thrown when API returns 429 Too Many Requests\n */\nexport class RateLimitError extends StorefrontError {\n public readonly retryAfter: number | null;\n\n constructor(message: string = \"Rate limit exceeded\", retryAfter: number | null = null) {\n super(message, 429, \"RATE_LIMIT_EXCEEDED\");\n this.name = \"RateLimitError\";\n this.retryAfter = retryAfter;\n }\n}\n\n/**\n * Error thrown when a requested resource is not found (404)\n */\nexport class NotFoundError extends StorefrontError {\n constructor(message: string = \"Resource not found\") {\n super(message, 404, \"NOT_FOUND\");\n this.name = \"NotFoundError\";\n }\n}\n\n/**\n * Error thrown when request validation fails (400)\n */\nexport class ValidationError extends StorefrontError {\n constructor(message: string = \"Validation failed\") {\n super(message, 400, \"VALIDATION_ERROR\");\n this.name = \"ValidationError\";\n }\n}\n\n/**\n * Error thrown when login fails due to unverified email\n * Contains customerId for resending verification email\n */\nexport class VerificationRequiredError extends StorefrontError {\n public readonly requiresVerification: true = true;\n public readonly customerId: string;\n\n constructor(message: string, customerId: string) {\n super(message, 403, \"VERIFICATION_REQUIRED\");\n this.name = \"VerificationRequiredError\";\n this.customerId = customerId;\n }\n}\n\n","import type { FetchOptions } from \"../types/index.js\";\r\nimport {\r\n StorefrontError,\r\n RateLimitError,\r\n VerificationRequiredError,\r\n} from \"./errors.js\";\r\n\r\n// SDK version - will be replaced during build or read from package.json\r\nconst SDK_VERSION = \"0.1.0\";\r\n\r\nexport interface FetcherConfig {\r\n apiKey: string;\r\n baseUrl: string;\r\n timeout?: number;\r\n}\r\n\r\nexport interface RequestOptions extends FetchOptions {\r\n method?: \"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\";\r\n body?: unknown;\r\n params?: Record<string, string | number | boolean | undefined>;\r\n}\r\n\r\n/**\r\n * Fetcher instance type returned by createFetcher\r\n */\r\nexport type Fetcher = ReturnType<typeof createFetcher>;\r\n\r\n/**\r\n * Create a configured fetcher instance for making API requests\r\n */\r\nexport function createFetcher(config: FetcherConfig) {\r\n const { apiKey, baseUrl, timeout = 30000 } = config;\r\n\r\n /**\r\n * Make an authenticated request to the Storefront API\r\n */\r\n async function request<T>(endpoint: string, options: RequestOptions = {}): Promise<T> {\r\n const { method = \"GET\", body, params, signal, headers = {}, cache, ...frameworkOptions } = options;\r\n\r\n // Build URL with query parameters\r\n // Ensure baseUrl ends with / for proper URL resolution\r\n const normalizedBase = baseUrl.endsWith(\"/\") ? baseUrl : `${baseUrl}/`;\r\n // Remove leading slash from endpoint to avoid URL resolution issues\r\n const normalizedEndpoint = endpoint.startsWith(\"/\") ? endpoint.slice(1) : endpoint;\r\n const url = new URL(normalizedEndpoint, normalizedBase);\r\n\r\n if (params) {\r\n for (const [key, value] of Object.entries(params)) {\r\n if (value !== undefined) {\r\n url.searchParams.set(key, String(value));\r\n }\r\n }\r\n }\r\n\r\n // Create abort controller for timeout\r\n const controller = new AbortController();\r\n const timeoutId = setTimeout(() => controller.abort(), timeout);\r\n\r\n // Combine signals if provided\r\n const combinedSignal = signal\r\n ? AbortSignal.any([signal, controller.signal])\r\n : controller.signal;\r\n\r\n try {\r\n const fetchOptions: RequestInit & Record<string, unknown> = {\r\n method,\r\n headers: {\r\n \"Content-Type\": \"application/json\",\r\n \"x-api-key\": apiKey,\r\n \"x-sdk-version\": SDK_VERSION,\r\n ...headers,\r\n },\r\n body: body ? JSON.stringify(body) : undefined,\r\n signal: combinedSignal,\r\n cache,\r\n // Spread framework-specific options (e.g., Next.js `next`, or any other)\r\n ...frameworkOptions,\r\n };\r\n\r\n const response = await fetch(url.toString(), fetchOptions);\r\n\r\n clearTimeout(timeoutId);\r\n\r\n // Handle error responses\r\n if (!response.ok) {\r\n await handleErrorResponse(response);\r\n }\r\n\r\n // Parse response\r\n const data = await response.json();\r\n return data as T;\r\n } catch (error) {\r\n clearTimeout(timeoutId);\r\n\r\n // Re-throw SDK errors\r\n if (error instanceof StorefrontError) {\r\n throw error;\r\n }\r\n\r\n // Handle abort/timeout\r\n if (error instanceof Error && error.name === \"AbortError\") {\r\n throw new StorefrontError(\"Request timed out\", 408, \"TIMEOUT\");\r\n }\r\n\r\n // Handle network errors\r\n throw new StorefrontError(\r\n error instanceof Error ? error.message : \"Network error\",\r\n 0,\r\n \"NETWORK_ERROR\"\r\n );\r\n }\r\n }\r\n\r\n return { request };\r\n}\r\n\r\n/**\r\n * Error response JSON structure\r\n */\r\ninterface ErrorResponseJson {\r\n error?: string;\r\n code?: string;\r\n requiresVerification?: boolean;\r\n customerId?: string;\r\n}\r\n\r\n/**\r\n * Handle non-2xx responses and throw appropriate errors\r\n */\r\nasync function handleErrorResponse(response: Response): Promise<never> {\r\n let errorData: ErrorResponseJson = {};\r\n\r\n try {\r\n const json: unknown = await response.json();\r\n if (json && typeof json === \"object\") {\r\n errorData = json as ErrorResponseJson;\r\n }\r\n } catch {\r\n // Response body is not JSON\r\n }\r\n\r\n const message = errorData.error || response.statusText || \"Request failed\";\r\n\r\n // Check for verification required error (can be 400 or 403)\r\n if (errorData.requiresVerification && errorData.customerId) {\r\n throw new VerificationRequiredError(message, errorData.customerId);\r\n }\r\n\r\n // Use API-provided code if available, otherwise use default for status\r\n const code = errorData.code;\r\n\r\n switch (response.status) {\r\n case 401:\r\n throw new StorefrontError(message, 401, code || \"UNAUTHORIZED\");\r\n\r\n case 404:\r\n throw new StorefrontError(message, 404, code || \"NOT_FOUND\");\r\n\r\n case 429: {\r\n const retryAfter = response.headers.get(\"Retry-After\");\r\n const error = new RateLimitError(message, retryAfter ? parseInt(retryAfter, 10) : null);\r\n if (code) {\r\n // Override code if API provided one\r\n (error as { code: string }).code = code;\r\n }\r\n throw error;\r\n }\r\n\r\n case 400:\r\n throw new StorefrontError(message, 400, code || \"VALIDATION_ERROR\");\r\n\r\n default:\r\n throw new StorefrontError(message, response.status, code || \"API_ERROR\");\r\n }\r\n}\r\n","import type { FetchOptions, StoreConfig } from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Store resource for fetching store configuration\r\n */\r\nexport function createStoreResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Get the complete store configuration including settings, SEO, payments, campaigns, and features.\r\n *\r\n * @example Basic usage\r\n * ```typescript\r\n * const config = await client.store.getConfig();\r\n * console.log(config.store.name);\r\n * console.log(config.seo.seoTitle);\r\n * console.log(config.campaigns);\r\n * ```\r\n *\r\n * @example Next.js - with caching\r\n * ```typescript\r\n * const config = await client.store.getConfig({\r\n * next: { revalidate: 300, tags: ['store-config'] }\r\n * });\r\n * ```\r\n *\r\n * @example Nuxt - wrap with useAsyncData\r\n * ```typescript\r\n * const { data: config } = await useAsyncData(\r\n * 'store-config',\r\n * () => client.store.getConfig()\r\n * );\r\n * ```\r\n *\r\n * @example Standard fetch caching\r\n * ```typescript\r\n * const config = await client.store.getConfig({\r\n * cache: 'force-cache'\r\n * });\r\n * ```\r\n */\r\n async getConfig(options?: FetchOptions): Promise<StoreConfig> {\r\n return fetcher.request<StoreConfig>(\"/api/storefront/v1/store-config\", {\r\n ...options,\r\n });\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the store resource\r\n */\r\nexport type StoreResource = ReturnType<typeof createStoreResource>;\r\n","import type {\r\n FetchOptions,\r\n Product,\r\n ProductDetail,\r\n ProductListResponse,\r\n ProductCountResponse,\r\n ProductListParams,\r\n} from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Products resource for fetching product data\r\n */\r\nexport function createProductsResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Get latest products ordered by creation date (newest first).\r\n *\r\n * @param take - Number of products to return (required, must be >= 1)\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Array of products\r\n *\r\n * @example Basic usage\r\n * ```typescript\r\n * const products = await client.products.latest(6);\r\n * ```\r\n *\r\n * @example Next.js - with caching\r\n * ```typescript\r\n * const products = await client.products.latest(6, {\r\n * next: { revalidate: 3600, tags: ['products'] }\r\n * });\r\n * ```\r\n */\r\n async latest(take: number, options?: FetchOptions): Promise<Product[]> {\r\n return fetcher.request<Product[]>(\"/api/storefront/v1/latest-products\", {\r\n params: { take },\r\n ...options,\r\n });\r\n },\r\n\r\n /**\r\n * Get a single product by its URL slug.\r\n *\r\n * @param slug - Product URL slug\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Full product details including categories and variations\r\n * @throws NotFoundError if product doesn't exist or is not visible\r\n *\r\n * @example Basic usage\r\n * ```typescript\r\n * const product = await client.products.getBySlug('my-product');\r\n * console.log(product.name, product.categories);\r\n * ```\r\n *\r\n * @example Next.js - with caching\r\n * ```typescript\r\n * const product = await client.products.getBySlug('my-product', {\r\n * next: { revalidate: 3600, tags: ['product', 'my-product'] }\r\n * });\r\n * ```\r\n */\r\n async getBySlug(\r\n slug: string,\r\n options?: FetchOptions\r\n ): Promise<ProductDetail> {\r\n return fetcher.request<ProductDetail>(\r\n `/api/storefront/v1/product/${encodeURIComponent(slug)}`,\r\n {\r\n ...options,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Get total product count, optionally filtered by category.\r\n *\r\n * @param slugs - Optional category slugs to filter by\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Object with count property\r\n *\r\n * @example Get total count\r\n * ```typescript\r\n * const { count } = await client.products.count();\r\n * console.log(`Total products: ${count}`);\r\n * ```\r\n *\r\n * @example Get count for specific category\r\n * ```typescript\r\n * const { count } = await client.products.count(['shoes']);\r\n * console.log(`Products in shoes: ${count}`);\r\n * ```\r\n */\r\n async count(\r\n slugs?: string[],\r\n options?: FetchOptions\r\n ): Promise<ProductCountResponse> {\r\n const searchParams = new URLSearchParams();\r\n if (slugs?.length) {\r\n slugs.forEach((s) => searchParams.append(\"slugs\", s));\r\n }\r\n const query = searchParams.toString();\r\n const endpoint = `/api/storefront/v1/products-count${query ? `?${query}` : \"\"}`;\r\n\r\n return fetcher.request<ProductCountResponse>(endpoint, {\r\n ...options,\r\n });\r\n },\r\n\r\n /**\r\n * Get sorted products with pagination.\r\n * Uses optimized sorting with pre-computed effective prices.\r\n *\r\n * @param params - Query parameters (slugs, page, pageSize, sort)\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Products list with totalCount for pagination\r\n *\r\n * @example Basic usage\r\n * ```typescript\r\n * const { products, totalCount } = await client.products.sorted({\r\n * page: 1,\r\n * pageSize: 12,\r\n * sort: 'newest'\r\n * });\r\n * ```\r\n *\r\n * @example Filter by category\r\n * ```typescript\r\n * const { products, totalCount } = await client.products.sorted({\r\n * slugs: ['shoes', 'clothing'],\r\n * page: 1,\r\n * pageSize: 24,\r\n * sort: 'price_asc'\r\n * });\r\n * ```\r\n *\r\n * @example Real-time data (no cache)\r\n * ```typescript\r\n * const data = await client.products.sorted(\r\n * { page: 1, pageSize: 12 },\r\n * { cache: 'no-store' }\r\n * );\r\n * ```\r\n */\r\n async sorted(\r\n params: ProductListParams = {},\r\n options?: FetchOptions\r\n ): Promise<ProductListResponse> {\r\n const searchParams = new URLSearchParams();\r\n if (params.page) searchParams.set(\"page\", params.page.toString());\r\n if (params.pageSize)\r\n searchParams.set(\"pageSize\", params.pageSize.toString());\r\n if (params.sort) searchParams.set(\"sort\", params.sort);\r\n if (params.slugs?.length) {\r\n params.slugs.forEach((s) => searchParams.append(\"slugs\", s));\r\n }\r\n const query = searchParams.toString();\r\n const endpoint = `/api/storefront/v1/sorted-products${query ? `?${query}` : \"\"}`;\r\n\r\n return fetcher.request<ProductListResponse>(endpoint, {\r\n ...options,\r\n });\r\n },\r\n\r\n /**\r\n * Get filtered products with pagination.\r\n * Similar to sorted() but without totalCount in response.\r\n * Useful for sitemaps and bulk fetches.\r\n *\r\n * @param params - Query parameters (slugs, page, pageSize, sort)\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Products list with category name\r\n *\r\n * @example Fetch all products for sitemap\r\n * ```typescript\r\n * const { products } = await client.products.filtered({\r\n * slugs: ['all-products'],\r\n * page: 1,\r\n * pageSize: 1000\r\n * });\r\n * ```\r\n */\r\n async filtered(\r\n params: ProductListParams = {},\r\n options?: FetchOptions\r\n ): Promise<Omit<ProductListResponse, \"totalCount\">> {\r\n const searchParams = new URLSearchParams();\r\n if (params.page) searchParams.set(\"page\", params.page.toString());\r\n if (params.pageSize)\r\n searchParams.set(\"pageSize\", params.pageSize.toString());\r\n if (params.sort) searchParams.set(\"sort\", params.sort);\r\n if (params.slugs?.length) {\r\n params.slugs.forEach((s) => searchParams.append(\"slugs\", s));\r\n }\r\n const query = searchParams.toString();\r\n const endpoint = `/api/storefront/v1/filtered-products${query ? `?${query}` : \"\"}`;\r\n\r\n return fetcher.request<Omit<ProductListResponse, \"totalCount\">>(\r\n endpoint,\r\n {\r\n ...options,\r\n }\r\n );\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the products resource\r\n */\r\nexport type ProductsResource = ReturnType<typeof createProductsResource>;\r\n","import type { FetchOptions, Category, CategoryResponse } from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Categories resource for fetching category data\r\n */\r\nexport function createCategoriesResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Get all top-level categories with nested children.\r\n * Returns a hierarchical tree of categories (up to 5 levels deep).\r\n *\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Array of top-level categories with nested children\r\n *\r\n * @example Basic usage\r\n * ```typescript\r\n * const categories = await client.categories.list();\r\n * categories.forEach(cat => {\r\n * console.log(cat.name, cat.children.length);\r\n * });\r\n * ```\r\n *\r\n * @example Next.js - with caching\r\n * ```typescript\r\n * const categories = await client.categories.list({\r\n * next: { revalidate: 3600, tags: ['categories'] }\r\n * });\r\n * ```\r\n */\r\n async list(options?: FetchOptions): Promise<Category[]> {\r\n return fetcher.request<Category[]>(\"/api/storefront/v1/categories\", {\r\n ...options,\r\n });\r\n },\r\n\r\n /**\r\n * Get a single category by its URL slug.\r\n *\r\n * @param slug - Category URL slug\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Category data\r\n * @throws NotFoundError if category doesn't exist\r\n *\r\n * @example Basic usage\r\n * ```typescript\r\n * const { category } = await client.categories.getBySlug('shoes');\r\n * console.log(category.name);\r\n * ```\r\n *\r\n * @example Next.js - with caching\r\n * ```typescript\r\n * const { category } = await client.categories.getBySlug('shoes', {\r\n * next: { revalidate: 86400, tags: ['category', 'shoes'] }\r\n * });\r\n * ```\r\n */\r\n async getBySlug(\r\n slug: string,\r\n options?: FetchOptions\r\n ): Promise<CategoryResponse> {\r\n return fetcher.request<CategoryResponse>(\r\n `/api/storefront/v1/categories/${encodeURIComponent(slug)}`,\r\n {\r\n ...options,\r\n }\r\n );\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the categories resource\r\n */\r\nexport type CategoriesResource = ReturnType<typeof createCategoriesResource>;\r\n","/**\r\n * Pricing Utilities\r\n *\r\n * Helper functions for calculating prices with sale logic.\r\n */\r\n\r\nimport type { ProductDetail, ProductVariation } from \"../types/products.js\";\r\nimport type { PriceInfo } from \"../types/cart.js\";\r\n\r\n/**\r\n * Check if a sale is currently active based on start and end dates.\r\n *\r\n * @param startDate - Sale start date (ISO string, Date, null, or undefined)\r\n * @param endDate - Sale end date (ISO string, Date, null, or undefined)\r\n * @returns true if the sale is currently active\r\n *\r\n * @example\r\n * ```typescript\r\n * // No dates = always active\r\n * isSaleActive(null, null); // true\r\n *\r\n * // Only start date = active if past start\r\n * isSaleActive(\"2024-01-01\", null); // true if today >= Jan 1\r\n *\r\n * // Both dates = active if within range\r\n * isSaleActive(\"2024-01-01\", \"2024-12-31\"); // true if within range\r\n * ```\r\n */\r\nexport function isSaleActive(\r\n startDate: Date | string | null | undefined,\r\n endDate: Date | string | null | undefined\r\n): boolean {\r\n // If no dates are set, sale is considered active\r\n if (!startDate && !endDate) {\r\n return true;\r\n }\r\n\r\n const now = new Date();\r\n const start = startDate ? new Date(startDate) : null;\r\n const end = endDate ? new Date(endDate) : null;\r\n\r\n // If only start date is set\r\n if (start && !end) {\r\n return now >= start;\r\n }\r\n\r\n // If only end date is set\r\n if (!start && end) {\r\n return now <= end;\r\n }\r\n\r\n // If both dates are set\r\n if (start && end) {\r\n return now >= start && now <= end;\r\n }\r\n\r\n return true;\r\n}\r\n\r\n/**\r\n * Get price information for a product or variation.\r\n * Returns the effective price (sale or regular) and sale status.\r\n * All prices are in cents.\r\n *\r\n * @param product - The product to get price info for\r\n * @param variation - Optional variation (takes precedence over product price)\r\n * @returns Price information with effective price, original price, and sale status\r\n *\r\n * @example\r\n * ```typescript\r\n * // Product without variation\r\n * const priceInfo = getPriceInfo(product);\r\n * console.log(priceInfo.effectivePrice); // 1990 (cents)\r\n * console.log(priceInfo.isOnSale); // true\r\n *\r\n * // Product with selected variation\r\n * const priceInfo = getPriceInfo(product, selectedVariation);\r\n * ```\r\n */\r\nexport function getPriceInfo(\r\n product: ProductDetail,\r\n variation?: ProductVariation\r\n): PriceInfo {\r\n if (variation) {\r\n // Use variation pricing\r\n const isOnSale =\r\n isSaleActive(variation.saleStartDate, variation.saleEndDate) &&\r\n variation.salePrice !== null;\r\n\r\n const originalPrice = variation.price ?? product.price;\r\n const effectivePrice = isOnSale\r\n ? (variation.salePrice ?? originalPrice)\r\n : originalPrice;\r\n\r\n return {\r\n effectivePrice,\r\n originalPrice,\r\n isOnSale,\r\n salePercent: isOnSale ? (variation.salePercent ?? null) : null,\r\n };\r\n }\r\n\r\n // Use product pricing\r\n const isOnSale =\r\n isSaleActive(product.saleStartDate, product.saleEndDate) &&\r\n product.salePrice !== null;\r\n\r\n const originalPrice = product.price;\r\n const effectivePrice = isOnSale\r\n ? (product.salePrice ?? originalPrice)\r\n : originalPrice;\r\n\r\n return {\r\n effectivePrice,\r\n originalPrice,\r\n isOnSale,\r\n salePercent: isOnSale ? (product.salePercent ?? null) : null,\r\n };\r\n}\r\n","/**\r\n * Cart Calculation Utilities\r\n *\r\n * Functions for calculating cart totals with campaign discounts.\r\n */\r\n\r\nimport type { CartItem } from \"../types/cart.js\";\r\nimport type { Campaign } from \"../types/storeconfig.js\";\r\nimport type {\r\n CalculatedCartItem,\r\n CartCalculationResult,\r\n} from \"../types/cart.js\";\r\nimport { getPriceInfo } from \"./pricing.js\";\r\n\r\n/**\r\n * Internal type for tracking eligible units in Buy X Pay Y campaigns\r\n */\r\ninterface EligibleUnit {\r\n price: number;\r\n productId: string;\r\n variationId?: string;\r\n originalItem: CartItem;\r\n}\r\n\r\n/**\r\n * Calculate cart totals with campaign discounts applied.\r\n *\r\n * Supports BUY_X_PAY_Y campaigns: Buy X items, pay for Y (e.g., Buy 3 Pay 2 = 1 free item)\r\n *\r\n * @param items - Cart items to calculate\r\n * @param campaigns - Active campaigns to apply\r\n * @returns Calculation result with totals and savings\r\n *\r\n * @example\r\n * ```typescript\r\n * const result = calculateCartWithCampaigns(cartItems, activeCampaigns);\r\n *\r\n * console.log(result.cartTotal); // 4990 (cents)\r\n * console.log(result.totalSavings); // 1990 (cents)\r\n *\r\n * // Render calculated items\r\n * result.calculatedItems.forEach(({ item, paidQuantity, freeQuantity }) => {\r\n * console.log(`${item.product.name}: ${paidQuantity} paid, ${freeQuantity} free`);\r\n * });\r\n * ```\r\n */\r\nexport function calculateCartWithCampaigns(\r\n items: CartItem[],\r\n campaigns: Campaign[]\r\n): CartCalculationResult {\r\n // Find applicable campaigns\r\n const buyXPayYCampaign = campaigns.find(\r\n (c) => c.type === \"BUY_X_PAY_Y\" && c.isActive\r\n );\r\n\r\n // Calculate original total (without campaign discounts)\r\n const originalTotal = items.reduce((total, { product, variation, cartQuantity }) => {\r\n const priceInfo = getPriceInfo(product, variation);\r\n return total + priceInfo.effectivePrice * cartQuantity;\r\n }, 0);\r\n\r\n // No Buy X Pay Y campaign - return items as-is\r\n if (!buyXPayYCampaign?.BuyXPayYCampaign) {\r\n const calculatedItems = items.map((item) => ({\r\n item,\r\n paidQuantity: item.cartQuantity,\r\n freeQuantity: 0,\r\n totalQuantity: item.cartQuantity,\r\n }));\r\n\r\n return {\r\n calculatedItems,\r\n cartTotal: originalTotal,\r\n originalTotal,\r\n totalSavings: 0,\r\n };\r\n }\r\n\r\n // Apply Buy X Pay Y campaign\r\n const { buyQuantity, payQuantity, applicableCategories } =\r\n buyXPayYCampaign.BuyXPayYCampaign;\r\n const applicableCategoryIds = new Set(\r\n applicableCategories.map((c) => c.id)\r\n );\r\n\r\n // Find all individual units eligible for the campaign\r\n const eligibleUnits: EligibleUnit[] = items.flatMap((item) => {\r\n const { product, variation } = item;\r\n const itemCategories = product.categories?.map((cat) => cat.id) || [];\r\n\r\n // Check if any of the product's categories are in the campaign's list\r\n const isEligible = itemCategories.some((id) =>\r\n applicableCategoryIds.has(id)\r\n );\r\n\r\n if (isEligible) {\r\n const priceInfo = getPriceInfo(product, variation);\r\n\r\n // Create an entry for each single unit of the item\r\n return Array.from({ length: item.cartQuantity }, () => ({\r\n price: priceInfo.effectivePrice,\r\n productId: product.id,\r\n variationId: variation?.id,\r\n originalItem: item,\r\n }));\r\n }\r\n\r\n return [];\r\n });\r\n\r\n // Not enough eligible items - return original quantities\r\n if (eligibleUnits.length < buyQuantity) {\r\n const calculatedItems = items.map((item) => ({\r\n item,\r\n paidQuantity: item.cartQuantity,\r\n freeQuantity: 0,\r\n totalQuantity: item.cartQuantity,\r\n }));\r\n\r\n return {\r\n calculatedItems,\r\n cartTotal: originalTotal,\r\n originalTotal,\r\n totalSavings: 0,\r\n };\r\n }\r\n\r\n // Sort by price to find the cheapest items to make free\r\n eligibleUnits.sort((a, b) => a.price - b.price);\r\n\r\n const numToMakeFree = buyQuantity - payQuantity;\r\n const itemsToMakeFree = eligibleUnits.slice(0, numToMakeFree);\r\n\r\n // Calculate total savings from free items\r\n const totalSavings = itemsToMakeFree.reduce(\r\n (sum, item) => sum + item.price,\r\n 0\r\n );\r\n\r\n // Create a map to count how many units of each product/variation should be free\r\n const freeCountMap = new Map<string, number>();\r\n for (const freebie of itemsToMakeFree) {\r\n const key = `${freebie.productId}${freebie.variationId ? `_${freebie.variationId}` : \"\"}`;\r\n freeCountMap.set(key, (freeCountMap.get(key) || 0) + 1);\r\n }\r\n\r\n // Calculate paid and free quantities for each item\r\n const calculatedItems: CalculatedCartItem[] = items.map((item) => {\r\n const key = `${item.product.id}${item.variation?.id ? `_${item.variation.id}` : \"\"}`;\r\n const freeQuantity = freeCountMap.get(key) || 0;\r\n const paidQuantity = item.cartQuantity - freeQuantity;\r\n\r\n return {\r\n item,\r\n paidQuantity: Math.max(0, paidQuantity),\r\n freeQuantity,\r\n totalQuantity: item.cartQuantity,\r\n };\r\n });\r\n\r\n // Calculate final cart total after Buy X Pay Y discounts\r\n const cartTotal = originalTotal - totalSavings;\r\n\r\n return {\r\n calculatedItems,\r\n cartTotal,\r\n originalTotal,\r\n totalSavings,\r\n };\r\n}\r\n","/**\r\n * Cart Resource\r\n *\r\n * Methods for managing the shopping cart stored in Redis.\r\n * Supports both guest carts (via cartId) and authenticated user carts (via sessionId).\r\n */\r\n\r\nimport type {\r\n FetchOptions,\r\n CartResponse,\r\n CartValidationResponse,\r\n CartSessionOptions,\r\n AddToCartParams,\r\n UpdateCartQuantityParams,\r\n RemoveFromCartParams,\r\n CartItem,\r\n Campaign,\r\n} from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\nimport { calculateCartWithCampaigns } from \"../utils/cart-calculations.js\";\r\n\r\n/**\r\n * Build headers object for cart operations\r\n */\r\nfunction buildCartHeaders(options?: CartSessionOptions): Record<string, string> {\r\n const headers: Record<string, string> = {};\r\n if (options?.cartId) {\r\n headers[\"x-cart-id\"] = options.cartId;\r\n }\r\n if (options?.sessionId) {\r\n headers[\"x-session-id\"] = options.sessionId;\r\n }\r\n return headers;\r\n}\r\n\r\n/**\r\n * Cart resource for managing shopping cart\r\n */\r\nexport function createCartResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Fetch the current cart contents.\r\n *\r\n * @param options - Cart session options (cartId for guests, sessionId for logged-in users)\r\n * @param fetchOptions - Fetch options (caching, headers, etc.)\r\n * @returns Cart items and cartId (for guests)\r\n *\r\n * @example Guest user\r\n * ```typescript\r\n * const cartId = localStorage.getItem('cart-id');\r\n * const { items, cartId: newCartId } = await client.cart.get({ cartId });\r\n * ```\r\n *\r\n * @example Logged-in user\r\n * ```typescript\r\n * const { items } = await client.cart.get({ sessionId });\r\n * ```\r\n */\r\n async get(\r\n options?: CartSessionOptions,\r\n fetchOptions?: FetchOptions\r\n ): Promise<CartResponse> {\r\n return fetcher.request<CartResponse>(\"/api/storefront/v1/cart\", {\r\n method: \"GET\",\r\n headers: buildCartHeaders(options),\r\n ...fetchOptions,\r\n });\r\n },\r\n\r\n /**\r\n * Add an item to the cart.\r\n * If the item already exists, quantity is incremented.\r\n *\r\n * @param params - Add to cart parameters\r\n * @param fetchOptions - Fetch options\r\n * @returns Updated cart with new cartId for guests\r\n * @throws ValidationError if quantity exceeds available stock\r\n *\r\n * @example Add product\r\n * ```typescript\r\n * const { items, cartId } = await client.cart.addItem({\r\n * cartId: existingCartId,\r\n * productId: 'prod_123',\r\n * quantity: 2\r\n * });\r\n * // Save cartId for future requests\r\n * localStorage.setItem('cart-id', cartId);\r\n * ```\r\n *\r\n * @example Add product with variation\r\n * ```typescript\r\n * const { items, cartId } = await client.cart.addItem({\r\n * cartId,\r\n * productId: 'prod_123',\r\n * variationId: 'var_456',\r\n * quantity: 1\r\n * });\r\n * ```\r\n */\r\n async addItem(\r\n params: AddToCartParams,\r\n fetchOptions?: FetchOptions\r\n ): Promise<CartResponse> {\r\n const { cartId, sessionId, ...body } = params;\r\n return fetcher.request<CartResponse>(\"/api/storefront/v1/cart\", {\r\n method: \"POST\",\r\n headers: buildCartHeaders({ sessionId }),\r\n body: {\r\n cartId,\r\n ...body,\r\n },\r\n ...fetchOptions,\r\n });\r\n },\r\n\r\n /**\r\n * Update item quantity by delta (atomic operation).\r\n * Use positive delta to increase, negative to decrease.\r\n * Minimum quantity is 1 (use removeItem to delete).\r\n *\r\n * @param params - Update quantity parameters\r\n * @param fetchOptions - Fetch options\r\n * @returns Updated cart\r\n * @throws NotFoundError if item not in cart or quantity would go below 1\r\n *\r\n * @example Increment quantity\r\n * ```typescript\r\n * const { items } = await client.cart.updateQuantity({\r\n * cartId,\r\n * productId: 'prod_123',\r\n * delta: 1\r\n * });\r\n * ```\r\n *\r\n * @example Decrement quantity\r\n * ```typescript\r\n * const { items } = await client.cart.updateQuantity({\r\n * cartId,\r\n * productId: 'prod_123',\r\n * variationId: 'var_456',\r\n * delta: -1\r\n * });\r\n * ```\r\n */\r\n async updateQuantity(\r\n params: UpdateCartQuantityParams,\r\n fetchOptions?: FetchOptions\r\n ): Promise<CartResponse> {\r\n const { cartId, sessionId, ...body } = params;\r\n return fetcher.request<CartResponse>(\"/api/storefront/v1/cart\", {\r\n method: \"PATCH\",\r\n headers: buildCartHeaders({ sessionId }),\r\n body: {\r\n cartId,\r\n ...body,\r\n },\r\n ...fetchOptions,\r\n });\r\n },\r\n\r\n /**\r\n * Remove an item from the cart.\r\n *\r\n * @param params - Remove from cart parameters\r\n * @param fetchOptions - Fetch options\r\n * @returns Updated cart\r\n *\r\n * @example Remove product\r\n * ```typescript\r\n * const { items } = await client.cart.removeItem({\r\n * cartId,\r\n * productId: 'prod_123'\r\n * });\r\n * ```\r\n *\r\n * @example Remove variation\r\n * ```typescript\r\n * const { items } = await client.cart.removeItem({\r\n * cartId,\r\n * productId: 'prod_123',\r\n * variationId: 'var_456'\r\n * });\r\n * ```\r\n */\r\n async removeItem(\r\n params: RemoveFromCartParams,\r\n fetchOptions?: FetchOptions\r\n ): Promise<CartResponse> {\r\n const { cartId, sessionId, ...body } = params;\r\n return fetcher.request<CartResponse>(\"/api/storefront/v1/cart\", {\r\n method: \"DELETE\",\r\n headers: buildCartHeaders({ sessionId }),\r\n body: {\r\n cartId,\r\n ...body,\r\n },\r\n ...fetchOptions,\r\n });\r\n },\r\n\r\n /**\r\n * Validate cart before checkout.\r\n * Checks product availability, stock levels, and prices.\r\n * Auto-fixes issues (removes unavailable items, adjusts quantities).\r\n *\r\n * Campaign conflict detection:\r\n * - SDK calculates if BuyXPayY campaigns apply using calculateCartWithCampaigns()\r\n * - Sends x-campaigns-apply header to backend\r\n * - If campaigns apply AND discount code exists, backend removes it\r\n * - Returns changes.discountCouponRemoved = true\r\n *\r\n * @param options - Cart session options\r\n * @param cartItems - Current cart items for campaign calculation\r\n * @param campaigns - Active campaigns for conflict check\r\n * @param fetchOptions - Fetch options\r\n * @returns Validated cart with change metadata\r\n *\r\n * @example Validate before checkout\r\n * ```typescript\r\n * const result = await client.cart.validate(\r\n * { cartId },\r\n * cartItems,\r\n * storeConfig.campaigns\r\n * );\r\n *\r\n * if (result.hasChanges) {\r\n * if (result.changes.discountCouponRemoved) {\r\n * notify(\"Alennuskoodi poistettu - kampanja-alennus aktivoitui\");\r\n * }\r\n * // Handle other changes...\r\n * }\r\n * ```\r\n */\r\n async validate(\r\n options?: CartSessionOptions,\r\n cartItems?: CartItem[],\r\n campaigns?: Campaign[],\r\n fetchOptions?: FetchOptions\r\n ): Promise<CartValidationResponse> {\r\n // Calculate if campaigns apply to current cart (client-side, instant)\r\n let campaignsApply = false;\r\n\r\n if (cartItems && campaigns && cartItems.length > 0) {\r\n const campaignResult = calculateCartWithCampaigns(cartItems, campaigns);\r\n campaignsApply = campaignResult.totalSavings > 0;\r\n }\r\n\r\n // Build headers with campaign info\r\n const headers = {\r\n ...buildCartHeaders(options),\r\n \"x-campaigns-apply\": campaignsApply ? \"true\" : \"false\",\r\n };\r\n\r\n return fetcher.request<CartValidationResponse>(\r\n \"/api/storefront/v1/cart/validate\",\r\n {\r\n method: \"GET\",\r\n headers,\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the cart resource\r\n */\r\nexport type CartResource = ReturnType<typeof createCartResource>;\r\n","/**\r\n * Shipping Resource\r\n *\r\n * Methods for fetching shipment methods and pickup locations.\r\n */\r\n\r\nimport type {\r\n FetchOptions,\r\n ShipmentMethodsResponse,\r\n CartItem,\r\n Campaign,\r\n} from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\nimport { calculateCartWithCampaigns } from \"../utils/cart-calculations.js\";\r\n\r\n/**\r\n * Calculate total cart weight from cart items\r\n */\r\nfunction calculateCartWeight(items: CartItem[]): number {\r\n return items.reduce((total, item) => {\r\n const itemWeight = item.variation?.weight ?? item.product.weight ?? 0.5;\r\n return total + itemWeight * item.cartQuantity;\r\n }, 0);\r\n}\r\n\r\n/**\r\n * Calculate total cart value in cents from cart items\r\n * Uses sale price if available, otherwise regular price\r\n */\r\nfunction calculateCartTotal(items: CartItem[]): number {\r\n return items.reduce((total, item) => {\r\n // Use variation price if exists, otherwise product price\r\n // Prefer salePrice over regular price\r\n const itemPrice = item.variation\r\n ? (item.variation.salePrice ?? item.variation.price)\r\n : (item.product.salePrice ?? item.product.price);\r\n return total + itemPrice * item.cartQuantity;\r\n }, 0);\r\n}\r\n\r\n/**\r\n * Options for fetching shipment methods with weight-based filtering\r\n */\r\nexport interface GetShippingOptionsParams extends FetchOptions {\r\n /** Cart items - weight and total will be calculated automatically */\r\n cartItems?: CartItem[];\r\n /** Active campaigns - used to calculate cart total with discounts for free shipping */\r\n campaigns?: Campaign[];\r\n /** Discount amount in cents (from discount code) - subtracted from cart total for free shipping threshold */\r\n discountAmount?: number;\r\n /** Country code (default: \"FI\") */\r\n country?: string;\r\n}\r\n\r\n/**\r\n * Shipping resource for fetching shipment methods and pickup locations\r\n */\r\nexport function createShippingResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Get shipping options for a specific postal code.\r\n * Returns pickup points and home delivery options in a unified format.\r\n *\r\n * **Pickup points are returned first** as they are more popular in Finland.\r\n *\r\n * @param postalCode - Customer's postal code (e.g., \"00100\")\r\n * @param options - Fetch options including optional cartItems for weight-based filtering\r\n * @returns Unified shipping options (pickupPoints sorted by distance, homeDelivery sorted by price)\r\n *\r\n * @example\r\n * ```typescript\r\n * const { pickupPoints, homeDelivery } = await client.shipping.getOptions(\"00100\");\r\n *\r\n * // Show pickup points (more popular in Finland)\r\n * pickupPoints.forEach(point => {\r\n * console.log(`${point.name} - ${point.carrier}`);\r\n * console.log(` ${point.address}, ${point.city}`);\r\n * console.log(` ${(point.distance! / 1000).toFixed(1)} km away`);\r\n * console.log(` Price: ${point.price / 100}€`);\r\n * });\r\n *\r\n * // Show home delivery options\r\n * homeDelivery.forEach(option => {\r\n * console.log(`${option.name}: ${option.price / 100}€`);\r\n * if (option.estimatedDelivery) {\r\n * console.log(` Delivery: ${option.estimatedDelivery} days`);\r\n * }\r\n * });\r\n * ```\r\n *\r\n * @example Weight-based filtering\r\n * ```typescript\r\n * const options = await client.shipping.getOptions(\"00100\", {\r\n * cartItems: cartItems\r\n * });\r\n * // Only shows methods that support the cart's total weight\r\n * ```\r\n *\r\n * @example International shipping\r\n * ```typescript\r\n * const options = await client.shipping.getOptions(\"112 22\", {\r\n * country: \"SE\"\r\n * });\r\n * ```\r\n */\r\n async getOptions(\r\n postalCode: string,\r\n options?: GetShippingOptionsParams\r\n ): Promise<ShipmentMethodsResponse> {\r\n const params = new URLSearchParams();\r\n\r\n if (options?.cartItems?.length) {\r\n const cartWeight = calculateCartWeight(options.cartItems);\r\n params.set(\"cartWeight\", cartWeight.toString());\r\n\r\n // Send cart total for free shipping calculation\r\n // Use calculateCartWithCampaigns if campaigns provided (accounts for campaign discounts)\r\n const cartTotal = options.campaigns\r\n ? calculateCartWithCampaigns(options.cartItems, options.campaigns).cartTotal\r\n : calculateCartTotal(options.cartItems);\r\n\r\n // Subtract discount code amount if provided (ensures free shipping threshold uses total after discount)\r\n const finalCartTotal = options.discountAmount\r\n ? Math.max(0, cartTotal - options.discountAmount)\r\n : cartTotal;\r\n\r\n params.set(\"cartTotal\", finalCartTotal.toString());\r\n }\r\n\r\n if (options?.country) {\r\n params.set(\"country\", options.country);\r\n }\r\n\r\n const queryString = params.toString();\r\n const url = `/api/storefront/v1/shipment-methods/${encodeURIComponent(postalCode)}${queryString ? `?${queryString}` : \"\"}`;\r\n\r\n return fetcher.request<ShipmentMethodsResponse>(url, {\r\n method: \"GET\",\r\n ...options,\r\n });\r\n },\r\n\r\n /**\r\n * @deprecated Use getOptions() instead. This method is kept for backwards compatibility.\r\n */\r\n async getWithLocations(\r\n postalCode: string,\r\n options?: GetShippingOptionsParams\r\n ): Promise<ShipmentMethodsResponse> {\r\n return this.getOptions(postalCode, options);\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the shipping resource\r\n */\r\nexport type ShippingResource = ReturnType<typeof createShippingResource>;\r\n","/**\r\n * Customer Resource\r\n *\r\n * Methods for customer authentication and account management.\r\n * Supports session-based authentication with the x-session-id header.\r\n */\r\n\r\nimport type {\r\n FetchOptions,\r\n RegisterData,\r\n RegisterResponse,\r\n LoginOptions,\r\n LoginResponse,\r\n LogoutResponse,\r\n GetUserResponse,\r\n VerifyEmailResponse,\r\n ResendVerificationResponse,\r\n UpdateProfileData,\r\n UpdateProfileResponse,\r\n DeleteAccountResponse,\r\n GetOrdersResponse,\r\n WishlistResponse,\r\n AddToWishlistResponse,\r\n RemoveFromWishlistResponse,\r\n ForgotPasswordResponse,\r\n ResetPasswordResponse,\r\n} from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Build headers for authenticated customer requests\r\n */\r\nfunction buildSessionHeaders(sessionId: string): Record<string, string> {\r\n return { \"x-session-id\": sessionId };\r\n}\r\n\r\n/**\r\n * Customer resource for authentication and account management\r\n */\r\nexport function createCustomerResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Register a new customer account.\r\n * A verification email is sent automatically by the server.\r\n * The customer must verify their email before logging in.\r\n *\r\n * @param data - Registration data (firstName, lastName, email, password)\r\n * @param fetchOptions - Fetch options\r\n * @returns Created customer data and success message\r\n *\r\n * @example\r\n * ```typescript\r\n * const { customer, message } = await client.customer.register({\r\n * firstName: 'John',\r\n * lastName: 'Doe',\r\n * email: 'john@example.com',\r\n * password: 'securePassword123'\r\n * });\r\n *\r\n * // Verification email is sent automatically by the server\r\n * console.log('Account created:', message);\r\n * ```\r\n */\r\n async register(\r\n data: RegisterData,\r\n fetchOptions?: FetchOptions\r\n ): Promise<RegisterResponse> {\r\n return fetcher.request<RegisterResponse>(\r\n \"/api/storefront/v1/customer/(auth)/register\",\r\n {\r\n method: \"POST\",\r\n body: data,\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Log in an existing customer.\r\n * Returns a session ID that must be stored and passed to authenticated endpoints.\r\n *\r\n * @param email - Customer's email address\r\n * @param password - Customer's password\r\n * @param options - Login options (optional cartId for cart merging)\r\n * @param fetchOptions - Fetch options\r\n * @returns Session ID and customer data\r\n * @throws ValidationError if email is not verified (check error for requiresVerification)\r\n *\r\n * @example\r\n * ```typescript\r\n * try {\r\n * const { sessionId, customer, expiresAt } = await client.customer.login(\r\n * 'john@example.com',\r\n * 'securePassword123',\r\n * { cartId: guestCartId } // Optional: merge guest cart\r\n * );\r\n *\r\n * // Store sessionId in a cookie\r\n * cookies().set('session-id', sessionId, {\r\n * httpOnly: true,\r\n * expires: new Date(expiresAt)\r\n * });\r\n * } catch (error) {\r\n * if (error.requiresVerification) {\r\n * // Prompt user to verify email\r\n * await client.customer.resendVerification(error.customerId);\r\n * }\r\n * }\r\n * ```\r\n */\r\n async login(\r\n email: string,\r\n password: string,\r\n options?: LoginOptions,\r\n fetchOptions?: FetchOptions\r\n ): Promise<LoginResponse> {\r\n const headers: Record<string, string> = {};\r\n if (options?.cartId) {\r\n headers[\"x-cart-id\"] = options.cartId;\r\n }\r\n\r\n return fetcher.request<LoginResponse>(\r\n \"/api/storefront/v1/customer/(auth)/login\",\r\n {\r\n method: \"POST\",\r\n body: { email, password },\r\n headers,\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Log out the current customer and invalidate their session.\r\n * If the customer had items in their cart, they are migrated to a new guest cart.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param fetchOptions - Fetch options\r\n * @returns Logout confirmation with optional new guest cart ID\r\n *\r\n * @example\r\n * ```typescript\r\n * const { cartId } = await client.customer.logout(sessionId);\r\n *\r\n * // Clear session cookie\r\n * cookies().delete('session-id');\r\n *\r\n * // If cart was migrated, store the new guest cart ID\r\n * if (cartId) {\r\n * cookies().set('cart-id', cartId);\r\n * }\r\n * ```\r\n */\r\n async logout(\r\n sessionId: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<LogoutResponse> {\r\n return fetcher.request<LogoutResponse>(\r\n \"/api/storefront/v1/customer/(auth)/logout\",\r\n {\r\n method: \"POST\",\r\n headers: buildSessionHeaders(sessionId),\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Get the currently authenticated customer's profile.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param fetchOptions - Fetch options\r\n * @returns Current customer data\r\n * @throws AuthError if session is invalid or expired\r\n *\r\n * @example\r\n * ```typescript\r\n * const sessionId = cookies().get('session-id')?.value;\r\n * if (sessionId) {\r\n * const { customer } = await client.customer.getUser(sessionId);\r\n * console.log(`Welcome back, ${customer.firstName}!`);\r\n * }\r\n * ```\r\n */\r\n async getUser(\r\n sessionId: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<GetUserResponse> {\r\n return fetcher.request<GetUserResponse>(\r\n \"/api/storefront/v1/customer/(auth)/get-user\",\r\n {\r\n method: \"GET\",\r\n headers: buildSessionHeaders(sessionId),\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Verify a customer's email address using the token sent during registration.\r\n *\r\n * @param token - Email verification token\r\n * @param fetchOptions - Fetch options\r\n * @returns Verification confirmation\r\n * @throws ValidationError if token is invalid or expired\r\n *\r\n * @example\r\n * ```typescript\r\n * // Token comes from the verification email link\r\n * const token = searchParams.get('token');\r\n *\r\n * const { message } = await client.customer.verifyEmail(token);\r\n * console.log(message); // \"Email verified successfully. You can now log in.\"\r\n * ```\r\n */\r\n async verifyEmail(\r\n token: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<VerifyEmailResponse> {\r\n return fetcher.request<VerifyEmailResponse>(\r\n \"/api/storefront/v1/customer/(auth)/verify-email\",\r\n {\r\n method: \"GET\",\r\n params: { token },\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Resend the verification email for an unverified customer.\r\n * A new verification email is sent automatically by the server.\r\n *\r\n * @param customerId - The customer's ID (from failed login response)\r\n * @param fetchOptions - Fetch options\r\n * @returns Success message\r\n * @throws ValidationError if customer is already verified or not found\r\n *\r\n * @example\r\n * ```typescript\r\n * // After login fails with requiresVerification\r\n * const { message } = await client.customer.resendVerification(customerId);\r\n *\r\n * // Verification email is sent automatically by the server\r\n * console.log(message); // \"Verification email sent.\"\r\n * ```\r\n */\r\n async resendVerification(\r\n customerId: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<ResendVerificationResponse> {\r\n return fetcher.request<ResendVerificationResponse>(\r\n \"/api/storefront/v1/customer/(auth)/resend-verification\",\r\n {\r\n method: \"POST\",\r\n body: { customerId },\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Request a password reset for a customer account.\r\n * The server sends a password reset email directly to the customer.\r\n * Returns success even if email doesn't exist (to prevent email enumeration).\r\n *\r\n * Note: The reset token is never exposed to the client for security.\r\n * The email is sent server-side with the reset link.\r\n *\r\n * @param email - Customer's email address\r\n * @param fetchOptions - Fetch options\r\n * @returns Generic success message (same whether email exists or not)\r\n *\r\n * @example\r\n * ```typescript\r\n * const response = await client.customer.forgotPassword('john@example.com');\r\n *\r\n * // Always show same message to user (email sent server-side)\r\n * console.log(response.message);\r\n * // \"If an account exists with that email, password reset instructions have been sent.\"\r\n * ```\r\n */\r\n async forgotPassword(\r\n email: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<ForgotPasswordResponse> {\r\n return fetcher.request<ForgotPasswordResponse>(\r\n \"/api/storefront/v1/customer/(auth)/forgot-password\",\r\n {\r\n method: \"POST\",\r\n body: { email },\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Reset a customer's password using a valid reset token.\r\n * The token is sent via email by the forgotPassword endpoint.\r\n * After successful reset, all existing sessions are invalidated.\r\n *\r\n * @param token - Password reset token (from email link)\r\n * @param password - New password (minimum 8 characters)\r\n * @param fetchOptions - Fetch options\r\n * @returns Success confirmation\r\n * @throws ValidationError if token is invalid or expired\r\n *\r\n * @example\r\n * ```typescript\r\n * // Token comes from the reset email link\r\n * const token = searchParams.get('token');\r\n *\r\n * try {\r\n * const { message } = await client.customer.resetPassword(token, newPassword);\r\n * console.log(message); // \"Password reset successful...\"\r\n *\r\n * // Redirect to login page\r\n * redirect('/login?reset=success');\r\n * } catch (error) {\r\n * if (error instanceof ValidationError) {\r\n * // Token invalid or expired\r\n * console.error('Please request a new password reset');\r\n * }\r\n * }\r\n * ```\r\n */\r\n async resetPassword(\r\n token: string,\r\n password: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<ResetPasswordResponse> {\r\n return fetcher.request<ResetPasswordResponse>(\r\n \"/api/storefront/v1/customer/(auth)/reset-password\",\r\n {\r\n method: \"POST\",\r\n body: { token, password },\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n // =========================================================================\r\n // Profile Management Methods\r\n // =========================================================================\r\n\r\n /**\r\n * Update the authenticated customer's profile.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param data - Profile data to update (firstName, lastName, email)\r\n * @param fetchOptions - Fetch options\r\n * @returns Updated customer data\r\n * @throws AuthError if session is invalid\r\n * @throws ValidationError if email is already taken by another customer\r\n *\r\n * @example\r\n * ```typescript\r\n * const { customer } = await client.customer.updateProfile(sessionId, {\r\n * firstName: 'Jane',\r\n * lastName: 'Smith',\r\n * email: 'jane.smith@example.com'\r\n * });\r\n *\r\n * console.log('Profile updated:', customer.email);\r\n * ```\r\n */\r\n async updateProfile(\r\n sessionId: string,\r\n data: UpdateProfileData,\r\n fetchOptions?: FetchOptions\r\n ): Promise<UpdateProfileResponse> {\r\n return fetcher.request<UpdateProfileResponse>(\r\n \"/api/storefront/v1/customer/edit-user\",\r\n {\r\n method: \"PATCH\",\r\n headers: buildSessionHeaders(sessionId),\r\n body: data,\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Delete the authenticated customer's account.\r\n * This action is permanent and cannot be undone.\r\n * All associated data (sessions, wishlist, etc.) will be deleted.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param fetchOptions - Fetch options\r\n * @returns Deletion confirmation\r\n * @throws AuthError if session is invalid\r\n *\r\n * @example\r\n * ```typescript\r\n * // Confirm with user before calling\r\n * if (confirm('Are you sure you want to delete your account?')) {\r\n * await client.customer.deleteAccount(sessionId);\r\n *\r\n * // Clear session cookie\r\n * cookies().delete('session-id');\r\n *\r\n * // Redirect to home page\r\n * redirect('/');\r\n * }\r\n * ```\r\n */\r\n async deleteAccount(\r\n sessionId: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<DeleteAccountResponse> {\r\n return fetcher.request<DeleteAccountResponse>(\r\n \"/api/storefront/v1/customer/delete-user\",\r\n {\r\n method: \"DELETE\",\r\n headers: buildSessionHeaders(sessionId),\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Get the customer's order history.\r\n * Returns all orders with line items and product details.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param customerId - The customer's ID\r\n * @param fetchOptions - Fetch options\r\n * @returns List of customer orders\r\n *\r\n * @example\r\n * ```typescript\r\n * const { orders } = await client.customer.getOrders(sessionId, customerId);\r\n *\r\n * orders.forEach(order => {\r\n * console.log(`Order #${order.orderNumber}: ${order.status}`);\r\n * order.OrderLineItems.forEach(item => {\r\n * console.log(` - ${item.name} x${item.quantity}`);\r\n * });\r\n * });\r\n * ```\r\n */\r\n async getOrders(\r\n sessionId: string,\r\n customerId: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<GetOrdersResponse> {\r\n return fetcher.request<GetOrdersResponse>(\r\n `/api/storefront/v1/customer/get-orders/${customerId}`,\r\n {\r\n method: \"GET\",\r\n headers: buildSessionHeaders(sessionId),\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n // =========================================================================\r\n // Wishlist (Nested Resource)\r\n // =========================================================================\r\n\r\n /**\r\n * Wishlist management methods.\r\n * Access via `client.customer.wishlist.get()`, `.add()`, `.remove()`.\r\n */\r\n wishlist: {\r\n /**\r\n * Get the customer's wishlist.\r\n * Returns all wishlist items with product and variation details.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param fetchOptions - Fetch options\r\n * @returns Wishlist items with product details\r\n * @throws AuthError if session is invalid\r\n *\r\n * @example\r\n * ```typescript\r\n * const { items } = await client.customer.wishlist.get(sessionId);\r\n *\r\n * items.forEach(item => {\r\n * console.log(`${item.product.name} - $${item.product.price / 100}`);\r\n * if (item.variation) {\r\n * const options = item.variation.options\r\n * .map(o => `${o.optionType.name}: ${o.value}`)\r\n * .join(', ');\r\n * console.log(` Variant: ${options}`);\r\n * }\r\n * });\r\n * ```\r\n */\r\n async get(\r\n sessionId: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<WishlistResponse> {\r\n return fetcher.request<WishlistResponse>(\r\n \"/api/storefront/v1/customer/wishlist\",\r\n {\r\n method: \"GET\",\r\n headers: buildSessionHeaders(sessionId),\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Add a product to the customer's wishlist.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param productId - The product ID to add\r\n * @param variationId - Optional variation ID (for products with variations)\r\n * @param fetchOptions - Fetch options\r\n * @returns Success message\r\n * @throws AuthError if session is invalid\r\n * @throws ValidationError if product already in wishlist\r\n *\r\n * @example\r\n * ```typescript\r\n * // Add a simple product\r\n * await client.customer.wishlist.add(sessionId, 'prod_123');\r\n *\r\n * // Add a product with a specific variation\r\n * await client.customer.wishlist.add(sessionId, 'prod_123', 'var_456');\r\n * ```\r\n */\r\n async add(\r\n sessionId: string,\r\n productId: string,\r\n variationId?: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<AddToWishlistResponse> {\r\n return fetcher.request<AddToWishlistResponse>(\r\n \"/api/storefront/v1/customer/wishlist\",\r\n {\r\n method: \"POST\",\r\n headers: buildSessionHeaders(sessionId),\r\n body: { productId, variationId },\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Remove a product from the customer's wishlist.\r\n *\r\n * @param sessionId - The customer's session ID\r\n * @param productId - The product ID to remove\r\n * @param variationId - Optional variation ID (must match if item was added with variation)\r\n * @param fetchOptions - Fetch options\r\n * @returns Success message\r\n * @throws AuthError if session is invalid\r\n * @throws NotFoundError if item not in wishlist\r\n *\r\n * @example\r\n * ```typescript\r\n * // Remove a simple product\r\n * await client.customer.wishlist.remove(sessionId, 'prod_123');\r\n *\r\n * // Remove a specific variation\r\n * await client.customer.wishlist.remove(sessionId, 'prod_123', 'var_456');\r\n * ```\r\n */\r\n async remove(\r\n sessionId: string,\r\n productId: string,\r\n variationId?: string,\r\n fetchOptions?: FetchOptions\r\n ): Promise<RemoveFromWishlistResponse> {\r\n return fetcher.request<RemoveFromWishlistResponse>(\r\n \"/api/storefront/v1/customer/wishlist\",\r\n {\r\n method: \"DELETE\",\r\n headers: buildSessionHeaders(sessionId),\r\n body: { productId, variationId },\r\n ...fetchOptions,\r\n }\r\n );\r\n },\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the customer resource\r\n */\r\nexport type CustomerResource = ReturnType<typeof createCustomerResource>;\r\n","import type { FetchOptions, Order } from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Order resource for fetching order details\r\n *\r\n * Used for order confirmation pages and viewing order details.\r\n * For customer order history, use the customer.getOrders() method instead.\r\n */\r\nexport function createOrderResource(fetcher: Fetcher) {\r\n return {\r\n /**\r\n * Get order details by ID.\r\n *\r\n * Retrieves complete order information including line items,\r\n * customer data, and shipment method with tracking info.\r\n *\r\n * @param orderId - The order ID to fetch\r\n * @param options - Fetch options (caching, headers, etc.)\r\n * @returns Complete order details\r\n * @throws NotFoundError if order doesn't exist or belongs to different store\r\n *\r\n * @example Basic usage (order confirmation page)\r\n * ```typescript\r\n * const order = await client.order.get(orderId);\r\n * console.log(`Order #${order.orderNumber} - ${order.status}`);\r\n * console.log(`Total: ${order.totalAmount / 100} EUR`);\r\n * ```\r\n *\r\n * @example Next.js - with caching\r\n * ```typescript\r\n * const order = await client.order.get(orderId, {\r\n * next: { revalidate: 60, tags: ['order', orderId] }\r\n * });\r\n * ```\r\n *\r\n * @example Display line items\r\n * ```typescript\r\n * const order = await client.order.get(orderId);\r\n * order.OrderLineItems.forEach(item => {\r\n * if (item.itemType !== 'SHIPPING') {\r\n * console.log(`${item.name} x${item.quantity} = ${item.totalAmount / 100} EUR`);\r\n * }\r\n * });\r\n * ```\r\n *\r\n * @example Show tracking info\r\n * ```typescript\r\n * const order = await client.order.get(orderId);\r\n * if (order.orderShipmentMethod?.trackingNumber) {\r\n * console.log(`Tracking: ${order.orderShipmentMethod.trackingNumber}`);\r\n * order.orderShipmentMethod.trackingUrls?.forEach(url => {\r\n * console.log(`Track at: ${url}`);\r\n * });\r\n * }\r\n * ```\r\n */\r\n async get(orderId: string, options?: FetchOptions): Promise<Order> {\r\n return fetcher.request<Order>(\r\n `/api/storefront/v1/order/${encodeURIComponent(orderId)}`,\r\n {\r\n ...options,\r\n }\r\n );\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the order resource\r\n */\r\nexport type OrderResource = ReturnType<typeof createOrderResource>;\r\n","import type {\r\n FetchOptions,\r\n CheckoutParams,\r\n StripeCheckoutResponse,\r\n PaytrailCheckoutResponse,\r\n} from \"../types/index.js\";\r\nimport type { Fetcher } from \"../utils/fetch.js\";\r\n\r\n/**\r\n * Extended options for checkout requests\r\n *\r\n * Checkout requires cart and session context via headers.\r\n */\r\nexport interface CheckoutOptions extends FetchOptions {\r\n /**\r\n * Cart ID for guest checkout.\r\n * Pass this when the user is not logged in.\r\n */\r\n cartId?: string;\r\n /**\r\n * Session ID for authenticated checkout.\r\n * Pass this when the user is logged in.\r\n */\r\n sessionId?: string;\r\n}\r\n\r\n/**\r\n * Checkout resource for payment processing\r\n *\r\n * Handles both Stripe and Paytrail payment providers.\r\n */\r\nexport function createCheckoutResource(fetcher: Fetcher) {\r\n /**\r\n * Build headers with cart/session context\r\n */\r\n function buildCheckoutHeaders(options?: CheckoutOptions): Record<string, string> {\r\n const headers: Record<string, string> = {};\r\n if (options?.cartId) {\r\n headers[\"x-cart-id\"] = options.cartId;\r\n }\r\n if (options?.sessionId) {\r\n headers[\"x-session-id\"] = options.sessionId;\r\n }\r\n return headers;\r\n }\r\n\r\n /**\r\n * Build checkout request body\r\n */\r\n function buildCheckoutBody(params: CheckoutParams) {\r\n return {\r\n orderId: params.orderId,\r\n chosenShipmentMethod: params.shipmentMethod,\r\n customerData: params.customerData,\r\n successUrl: params.successUrl,\r\n cancelUrl: params.cancelUrl,\r\n };\r\n }\r\n\r\n return {\r\n /**\r\n * Create a Stripe checkout session.\r\n *\r\n * Redirects the user to Stripe's hosted checkout page.\r\n * Cart items are validated and stock is reserved on the server.\r\n *\r\n * @param params - Checkout parameters (customer data, shipping, URLs)\r\n * @param options - Checkout options including cart/session context\r\n * @returns URL to redirect user to Stripe checkout\r\n * @throws ValidationError for invalid data or empty cart\r\n * @throws StorefrontError for inventory issues\r\n *\r\n * @example Basic usage with redirect\r\n * ```typescript\r\n * const { url } = await client.checkout.stripe({\r\n * customerData: {\r\n * first_name: \"John\",\r\n * last_name: \"Doe\",\r\n * email: \"john@example.com\",\r\n * address: \"123 Main St\",\r\n * postal_code: \"00100\",\r\n * city: \"Helsinki\",\r\n * phone: \"+358401234567\"\r\n * },\r\n * shipmentMethod: {\r\n * shipmentMethodId: \"ship_123\",\r\n * pickupId: null\r\n * },\r\n * orderId: \"order_abc123\",\r\n * successUrl: \"https://mystore.com/success\",\r\n * cancelUrl: \"https://mystore.com/cancel\"\r\n * }, {\r\n * cartId: \"cart_xyz\", // For guest users\r\n * sessionId: \"sess_123\" // For logged-in users\r\n * });\r\n *\r\n * // Redirect to Stripe\r\n * window.location.href = url;\r\n * ```\r\n */\r\n async stripe(\r\n params: CheckoutParams,\r\n options?: CheckoutOptions\r\n ): Promise<StripeCheckoutResponse> {\r\n const headers = buildCheckoutHeaders(options);\r\n const body = buildCheckoutBody(params);\r\n\r\n return fetcher.request<StripeCheckoutResponse>(\r\n \"/api/storefront/v1/payments/stripe/checkout\",\r\n {\r\n method: \"POST\",\r\n body,\r\n headers: {\r\n ...options?.headers,\r\n ...headers,\r\n },\r\n ...options,\r\n }\r\n );\r\n },\r\n\r\n /**\r\n * Create a Paytrail checkout session.\r\n *\r\n * Returns payment providers for Finnish payment methods.\r\n * Cart items are validated and stock is reserved on the server.\r\n *\r\n * @param params - Checkout parameters (customer data, shipping, URLs)\r\n * @param options - Checkout options including cart/session context\r\n * @returns Paytrail response with available payment providers\r\n * @throws ValidationError for invalid data or empty cart\r\n * @throws StorefrontError for inventory issues\r\n *\r\n * @example Display payment providers\r\n * ```typescript\r\n * const response = await client.checkout.paytrail({\r\n * customerData: {\r\n * first_name: \"Matti\",\r\n * last_name: \"Meikäläinen\",\r\n * email: \"matti@example.fi\",\r\n * address: \"Mannerheimintie 1\",\r\n * postal_code: \"00100\",\r\n * city: \"Helsinki\",\r\n * phone: \"+358401234567\"\r\n * },\r\n * shipmentMethod: {\r\n * shipmentMethodId: \"ship_123\",\r\n * pickupId: \"pickup_456\" // For pickup points\r\n * },\r\n * orderId: \"order_abc123\",\r\n * successUrl: \"https://mystore.com/success\",\r\n * cancelUrl: \"https://mystore.com/cancel\"\r\n * }, {\r\n * cartId: \"cart_xyz\"\r\n * });\r\n *\r\n * // Group providers by type\r\n * const banks = response.providers.filter(p => p.group === \"bank\");\r\n * const mobile = response.providers.filter(p => p.group === \"mobile\");\r\n * const cards = response.providers.filter(p => p.group === \"creditcard\");\r\n * ```\r\n *\r\n * @example Submit payment form\r\n * ```typescript\r\n * const provider = response.providers.find(p => p.id === \"nordea\");\r\n *\r\n * // Create and submit a form\r\n * const form = document.createElement(\"form\");\r\n * form.method = \"POST\";\r\n * form.action = provider.url;\r\n *\r\n * provider.parameters.forEach(({ name, value }) => {\r\n * const input = document.createElement(\"input\");\r\n * input.type = \"hidden\";\r\n * input.name = name;\r\n * input.value = value;\r\n * form.appendChild(input);\r\n * });\r\n *\r\n * document.body.appendChild(form);\r\n * form.submit();\r\n * ```\r\n */\r\n async paytrail(\r\n params: CheckoutParams,\r\n options?: CheckoutOptions\r\n ): Promise<PaytrailCheckoutResponse> {\r\n const headers = buildCheckoutHeaders(options);\r\n const body = buildCheckoutBody(params);\r\n\r\n return fetcher.request<PaytrailCheckoutResponse>(\r\n \"/api/storefront/v1/payments/paytrail/checkout\",\r\n {\r\n method: \"POST\",\r\n body,\r\n headers: {\r\n ...options?.headers,\r\n ...headers,\r\n },\r\n ...options,\r\n }\r\n );\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Type for the checkout resource\r\n */\r\nexport type CheckoutResource = ReturnType<typeof createCheckoutResource>;\r\n","/**\n * Discount Code Resource\n *\n * Provides methods for managing discount codes in the cart.\n */\n\nimport type {\n ApplyDiscountParams,\n ApplyDiscountResponse,\n GetDiscountParams,\n GetDiscountResponse,\n RemoveDiscountParams,\n RemoveDiscountResponse,\n} from \"../types/index.js\";\nimport type { Fetcher } from \"../utils/fetch.js\";\nimport { calculateCartWithCampaigns } from \"../utils/cart-calculations.js\";\nimport { StorefrontError } from \"../utils/errors.js\";\nimport { getPriceInfo } from \"../utils/pricing.js\";\n\n/**\n * Creates the discount code resource with methods for managing discount codes.\n */\nexport function createDiscountCodeResource(fetcher: Fetcher) {\n return {\n /**\n * Apply a discount code to the cart\n *\n * Checks for BuyXPayY campaign conflict before calling API.\n * Discount codes cannot be used when a campaign discount is active.\n *\n * @param params - Parameters including code, session info, and cart/campaign data for conflict check\n * @returns Applied discount details\n * @throws {StorefrontError} With code \"CAMPAIGN_ACTIVE\" if a BuyXPayY campaign is active\n *\n * @example\n * ```typescript\n * const result = await client.discountCode.apply({\n * code: \"SUMMER20\",\n * cartId: cartId,\n * cartItems: cart.items,\n * campaigns: storeConfig.campaigns,\n * });\n * ```\n */\n async apply(params: ApplyDiscountParams): Promise<ApplyDiscountResponse> {\n const { code, cartId, sessionId, cartItems, campaigns } = params;\n\n // Check for campaign conflict BEFORE calling API\n if (cartItems && campaigns && cartItems.length > 0) {\n const campaignResult = calculateCartWithCampaigns(cartItems, campaigns);\n if (campaignResult.totalSavings > 0) {\n throw new StorefrontError(\n \"Alennuskoodia ei voi käyttää kun kampanja-alennus on voimassa\",\n 400,\n \"CAMPAIGN_ACTIVE\"\n );\n }\n }\n\n // Calculate cart total from items using effective price (handles sale prices)\n const cartTotal = cartItems\n ? cartItems.reduce((sum, item) => {\n const priceInfo = getPriceInfo(item.product, item.variation);\n return sum + priceInfo.effectivePrice * item.cartQuantity;\n }, 0)\n : 0;\n\n return fetcher.request<ApplyDiscountResponse>(\"/api/storefront/v1/discount-code/apply\", {\n method: \"POST\",\n body: { code, cartTotal },\n headers: {\n ...(cartId && { \"x-cart-id\": cartId }),\n ...(sessionId && { \"x-session-id\": sessionId }),\n },\n });\n },\n\n /**\n * Get the currently applied discount code\n *\n * @param params - Session info (cartId or sessionId)\n * @returns Current discount or null if none applied\n *\n * @example\n * ```typescript\n * const { discount } = await client.discountCode.get({ cartId });\n * if (discount) {\n * console.log(`Code ${discount.code}: ${discount.discountValue}${discount.discountType === 'PERCENTAGE' ? '%' : '¢'} off`);\n * }\n * ```\n */\n async get(params: GetDiscountParams = {}): Promise<GetDiscountResponse> {\n const { cartId, sessionId } = params;\n\n return fetcher.request<GetDiscountResponse>(\"/api/storefront/v1/discount-code/apply\", {\n method: \"GET\",\n headers: {\n ...(cartId && { \"x-cart-id\": cartId }),\n ...(sessionId && { \"x-session-id\": sessionId }),\n },\n });\n },\n\n /**\n * Remove the currently applied discount code\n *\n * @param params - Session info (cartId or sessionId)\n * @returns Success status\n *\n * @example\n * ```typescript\n * await client.discountCode.remove({ cartId });\n * ```\n */\n async remove(params: RemoveDiscountParams = {}): Promise<RemoveDiscountResponse> {\n const { cartId, sessionId } = params;\n\n return fetcher.request<RemoveDiscountResponse>(\"/api/storefront/v1/discount-code/apply\", {\n method: \"DELETE\",\n headers: {\n ...(cartId && { \"x-cart-id\": cartId }),\n ...(sessionId && { \"x-session-id\": sessionId }),\n },\n });\n },\n };\n}\n\n/**\n * Type for the discount code resource\n */\nexport type DiscountCodeResource = ReturnType<typeof createDiscountCodeResource>;\n","import type { StorefrontClientConfig } from \"./types/index.js\";\nimport { createFetcher } from \"./utils/fetch.js\";\nimport { createStoreResource, type StoreResource } from \"./resources/store.js\";\nimport {\n createProductsResource,\n type ProductsResource,\n} from \"./resources/products.js\";\nimport {\n createCategoriesResource,\n type CategoriesResource,\n} from \"./resources/categories.js\";\nimport { createCartResource, type CartResource } from \"./resources/cart.js\";\nimport {\n createShippingResource,\n type ShippingResource,\n} from \"./resources/shipping.js\";\nimport {\n createCustomerResource,\n type CustomerResource,\n} from \"./resources/customer.js\";\nimport {\n createOrderResource,\n type OrderResource,\n} from \"./resources/order.js\";\nimport {\n createCheckoutResource,\n type CheckoutResource,\n} from \"./resources/checkout.js\";\nimport {\n createDiscountCodeResource,\n type DiscountCodeResource,\n} from \"./resources/discount-code.js\";\n\n/**\n * The Storefront API client\n */\nexport interface StorefrontClient {\n /**\n * The base URL for API requests\n */\n readonly baseUrl: string;\n\n /**\n * Store configuration resource\n */\n readonly store: StoreResource;\n\n /**\n * Products resource\n */\n readonly products: ProductsResource;\n\n /**\n * Categories resource\n */\n readonly categories: CategoriesResource;\n\n /**\n * Cart resource\n */\n readonly cart: CartResource;\n\n /**\n * Shipping resource\n */\n readonly shipping: ShippingResource;\n\n /**\n * Customer authentication and account management resource\n */\n readonly customer: CustomerResource;\n\n /**\n * Order resource for fetching order details\n */\n readonly order: OrderResource;\n\n /**\n * Checkout resource for payment processing\n */\n readonly checkout: CheckoutResource;\n\n /**\n * Discount code resource for applying/removing discount codes\n */\n readonly discountCode: DiscountCodeResource;\n}\n\n/**\n * Create a new Storefront API client\n */\nexport function createStorefrontClient(config: StorefrontClientConfig): StorefrontClient {\n if (!config.apiKey) {\n throw new Error(\"apiKey is required\");\n }\n if (!config.baseUrl) {\n throw new Error(\"baseUrl is required\");\n }\n\n // Ensure baseUrl doesn't have trailing slash\n const baseUrl = config.baseUrl.replace(/\\/$/, \"\");\n\n // Create the fetcher for making authenticated requests\n const fetcher = createFetcher({\n apiKey: config.apiKey,\n baseUrl,\n timeout: config.timeout,\n });\n\n return {\n baseUrl,\n store: createStoreResource(fetcher),\n products: createProductsResource(fetcher),\n categories: createCategoriesResource(fetcher),\n cart: createCartResource(fetcher),\n shipping: createShippingResource(fetcher),\n customer: createCustomerResource(fetcher),\n order: createOrderResource(fetcher),\n checkout: createCheckoutResource(fetcher),\n discountCode: createDiscountCodeResource(fetcher),\n };\n}\n","/**\r\n * Discount Code Utilities\r\n *\r\n * Helper functions for working with discount codes.\r\n */\r\n\r\nimport type { AppliedDiscount } from \"../types/discount-code.js\";\r\nimport type { DiscountRemovalReason } from \"../types/cart.js\";\r\n\r\n// =============================================================================\r\n// Format Options\r\n// =============================================================================\r\n\r\n/**\r\n * Options for formatting discount values\r\n */\r\nexport interface FormatDiscountOptions {\r\n /**\r\n * Currency symbol to use for fixed amount discounts\r\n * @default \"€\"\r\n */\r\n currencySymbol?: string;\r\n\r\n /**\r\n * Whether to show the currency symbol before or after the value\r\n * @default \"after\"\r\n */\r\n currencyPosition?: \"before\" | \"after\";\r\n\r\n /**\r\n * Number of decimal places for fixed amount\r\n * @default 2\r\n */\r\n decimals?: number;\r\n\r\n /**\r\n * Whether to include the minus sign prefix\r\n * @default true\r\n */\r\n showMinus?: boolean;\r\n}\r\n\r\n// =============================================================================\r\n// Discount Formatting\r\n// =============================================================================\r\n\r\n/**\r\n * Format a discount value for display.\r\n *\r\n * @param discount - The applied discount (or just type and value)\r\n * @param options - Formatting options\r\n * @returns Formatted discount string (e.g., \"-20%\" or \"-5,00 €\")\r\n *\r\n * @example\r\n * ```typescript\r\n * // Percentage discount\r\n * formatDiscountValue({ discountType: \"PERCENTAGE\", discountValue: 20 });\r\n * // Returns: \"-20%\"\r\n *\r\n * // Fixed amount discount (value in cents)\r\n * formatDiscountValue({ discountType: \"FIXED_AMOUNT\", discountValue: 500 });\r\n * // Returns: \"-5,00 €\"\r\n *\r\n * // Custom currency\r\n * formatDiscountValue(\r\n * { discountType: \"FIXED_AMOUNT\", discountValue: 1000 },\r\n * { currencySymbol: \"$\", currencyPosition: \"before\" }\r\n * );\r\n * // Returns: \"-$10.00\"\r\n * ```\r\n */\r\nexport function formatDiscountValue(\r\n discount: Pick<AppliedDiscount, \"discountType\" | \"discountValue\">,\r\n options: FormatDiscountOptions = {}\r\n): string {\r\n const {\r\n currencySymbol = \"€\",\r\n currencyPosition = \"after\",\r\n decimals = 2,\r\n showMinus = true,\r\n } = options;\r\n\r\n const prefix = showMinus ? \"-\" : \"\";\r\n\r\n if (discount.discountType === \"PERCENTAGE\") {\r\n return `${prefix}${discount.discountValue}%`;\r\n }\r\n\r\n // FIXED_AMOUNT: discountValue is in cents, convert to major units\r\n const amount = (discount.discountValue / 100).toFixed(decimals);\r\n // Replace dot with comma for Finnish locale\r\n const formattedAmount = amount.replace(\".\", \",\");\r\n\r\n if (currencyPosition === \"before\") {\r\n return `${prefix}${currencySymbol}${formattedAmount}`;\r\n }\r\n\r\n return `${prefix}${formattedAmount} ${currencySymbol}`;\r\n}\r\n\r\n// =============================================================================\r\n// Discount Calculation\r\n// =============================================================================\r\n\r\n/**\r\n * Calculate the discount amount in cents.\r\n *\r\n * @param subtotal - Cart subtotal in cents (before discount)\r\n * @param discount - The applied discount\r\n * @returns Discount amount in cents (always positive)\r\n *\r\n * @example\r\n * ```typescript\r\n * // 20% off 100€ subtotal\r\n * calculateDiscountAmount(10000, { discountType: \"PERCENTAGE\", discountValue: 20 });\r\n * // Returns: 2000 (20€ in cents)\r\n *\r\n * // Fixed 5€ discount\r\n * calculateDiscountAmount(10000, { discountType: \"FIXED_AMOUNT\", discountValue: 500 });\r\n * // Returns: 500 (5€ in cents)\r\n *\r\n * // Fixed discount larger than subtotal (capped)\r\n * calculateDiscountAmount(300, { discountType: \"FIXED_AMOUNT\", discountValue: 500 });\r\n * // Returns: 300 (capped to subtotal)\r\n * ```\r\n */\r\nexport function calculateDiscountAmount(\r\n subtotal: number,\r\n discount: Pick<AppliedDiscount, \"discountType\" | \"discountValue\">\r\n): number {\r\n if (discount.discountType === \"PERCENTAGE\") {\r\n return Math.round((subtotal * discount.discountValue) / 100);\r\n }\r\n\r\n // FIXED_AMOUNT: cap at subtotal (can't discount more than the total)\r\n return Math.min(discount.discountValue, subtotal);\r\n}\r\n\r\n// =============================================================================\r\n// Error Messages\r\n// =============================================================================\r\n\r\n/**\r\n * Supported locales for error messages\r\n */\r\nexport type DiscountMessageLocale = \"fi\" | \"en\";\r\n\r\n/**\r\n * Error messages for discount removal reasons\r\n */\r\nconst REMOVAL_MESSAGES: Record<DiscountRemovalReason, Record<DiscountMessageLocale, string>> = {\r\n CAMPAIGN_ACTIVE: {\r\n fi: \"Alennuskoodi poistettu - kampanja-alennus aktivoitui\",\r\n en: \"Discount code removed - campaign discount activated\",\r\n },\r\n MIN_ORDER_NOT_MET: {\r\n fi: \"Alennuskoodi poistettu - ostoskorin summa alittaa minimitilauksen\",\r\n en: \"Discount code removed - cart total below minimum order\",\r\n },\r\n CODE_INVALID: {\r\n fi: \"Alennuskoodi poistettu - koodi ei ole enää voimassa\",\r\n en: \"Discount code removed - code is no longer valid\",\r\n },\r\n};\r\n\r\n/**\r\n * Default removal message when reason is unknown\r\n */\r\nconst DEFAULT_REMOVAL_MESSAGE: Record<DiscountMessageLocale, string> = {\r\n fi: \"Alennuskoodi poistettu\",\r\n en: \"Discount code removed\",\r\n};\r\n\r\n/**\r\n * Get a user-friendly message for discount removal reason.\r\n *\r\n * @param reason - The removal reason from cart validation\r\n * @param locale - Locale for the message (fi or en)\r\n * @returns Localized user-friendly message\r\n *\r\n * @example\r\n * ```typescript\r\n * getDiscountRemovalMessage(\"CAMPAIGN_ACTIVE\", \"fi\");\r\n * // Returns: \"Alennuskoodi poistettu - kampanja-alennus aktivoitui\"\r\n *\r\n * getDiscountRemovalMessage(\"MIN_ORDER_NOT_MET\", \"en\");\r\n * // Returns: \"Discount code removed - cart total below minimum order\"\r\n * ```\r\n */\r\nexport function getDiscountRemovalMessage(\r\n reason: DiscountRemovalReason | undefined,\r\n locale: DiscountMessageLocale = \"fi\"\r\n): string {\r\n if (!reason) {\r\n return DEFAULT_REMOVAL_MESSAGE[locale];\r\n }\r\n\r\n return REMOVAL_MESSAGES[reason]?.[locale] ?? DEFAULT_REMOVAL_MESSAGE[locale];\r\n}\r\n\r\n// =============================================================================\r\n// Apply Error Messages\r\n// =============================================================================\r\n\r\n/**\r\n * Error codes from discount code apply endpoint\r\n */\r\nexport type DiscountApplyErrorCode =\r\n | \"NOT_FOUND\"\r\n | \"INACTIVE\"\r\n | \"NOT_STARTED\"\r\n | \"EXPIRED\"\r\n | \"MAX_USES_REACHED\"\r\n | \"MIN_ORDER_NOT_MET\"\r\n | \"CAMPAIGN_ACTIVE\";\r\n\r\n/**\r\n * Error messages for discount apply errors\r\n */\r\nconst APPLY_ERROR_MESSAGES: Record<DiscountApplyErrorCode, Record<DiscountMessageLocale, string>> = {\r\n NOT_FOUND: {\r\n fi: \"Alennuskoodia ei löydy\",\r\n en: \"Discount code not found\",\r\n },\r\n INACTIVE: {\r\n fi: \"Alennuskoodi ei ole käytössä\",\r\n en: \"Discount code is not active\",\r\n },\r\n NOT_STARTED: {\r\n fi: \"Alennuskoodi ei ole vielä voimassa\",\r\n en: \"Discount code is not yet valid\",\r\n },\r\n EXPIRED: {\r\n fi: \"Alennuskoodi on vanhentunut\",\r\n en: \"Discount code has expired\",\r\n },\r\n MAX_USES_REACHED: {\r\n fi: \"Alennuskoodi on käytetty loppuun\",\r\n en: \"Discount code usage limit reached\",\r\n },\r\n MIN_ORDER_NOT_MET: {\r\n fi: \"Ostoskorin summa alittaa alennuskoodin minimitilauksen\",\r\n en: \"Cart total is below the minimum order for this code\",\r\n },\r\n CAMPAIGN_ACTIVE: {\r\n fi: \"Alennuskoodia ei voi käyttää kun kampanja-alennus on voimassa\",\r\n en: \"Discount code cannot be used when a campaign discount is active\",\r\n },\r\n};\r\n\r\n/**\r\n * Default apply error message when code is unknown\r\n */\r\nconst DEFAULT_APPLY_ERROR: Record<DiscountMessageLocale, string> = {\r\n fi: \"Alennuskoodin käyttö epäonnistui\",\r\n en: \"Failed to apply discount code\",\r\n};\r\n\r\n/**\r\n * Get a user-friendly message for discount apply error.\r\n *\r\n * @param errorCode - The error code from apply endpoint\r\n * @param locale - Locale for the message (fi or en)\r\n * @returns Localized user-friendly message\r\n *\r\n * @example\r\n * ```typescript\r\n * getDiscountApplyErrorMessage(\"EXPIRED\", \"fi\");\r\n * // Returns: \"Alennuskoodi on vanhentunut\"\r\n * ```\r\n */\r\nexport function getDiscountApplyErrorMessage(\r\n errorCode: DiscountApplyErrorCode | string | undefined,\r\n locale: DiscountMessageLocale = \"fi\"\r\n): string {\r\n if (!errorCode) {\r\n return DEFAULT_APPLY_ERROR[locale];\r\n }\r\n\r\n const messages = APPLY_ERROR_MESSAGES[errorCode as DiscountApplyErrorCode];\r\n return messages?.[locale] ?? DEFAULT_APPLY_ERROR[locale];\r\n}\r\n"],"mappings":";AAGO,IAAM,kBAAN,MAAM,yBAAwB,MAAM;AAAA,EAIzC,YAAY,SAAiB,QAAgB,MAAc;AACzD,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AAGZ,UAAM,mBAAmB;AAGzB,QAAI,iBAAiB,mBAAmB;AACtC,uBAAiB,kBAAkB,MAAM,gBAAe;AAAA,IAC1D;AAAA,EACF;AACF;AAKO,IAAM,YAAN,cAAwB,gBAAgB;AAAA,EAC7C,YAAY,UAAkB,8BAA8B;AAC1D,UAAM,SAAS,KAAK,cAAc;AAClC,SAAK,OAAO;AAAA,EACd;AACF;AAKO,IAAM,iBAAN,cAA6B,gBAAgB;AAAA,EAGlD,YAAY,UAAkB,uBAAuB,aAA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