@shoppexio/storefront 1.0.107 → 1.0.108

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/customer.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  customerWarrantyListSchema,
14
14
  external_exports,
15
15
  storefrontStorageKey
16
- } from "./chunk-P7MN6RXP.js";
16
+ } from "./chunk-HMEEWD3P.js";
17
17
 
18
18
  // ../contracts/src/customer-portal-wire.ts
19
19
  var nullableStringSchema = external_exports.string().nullable();
@@ -135,7 +135,17 @@ var customerPortalSubscriptionBillingHistorySchema = external_exports.object({
135
135
  status: external_exports.string(),
136
136
  gateway: external_exports.string(),
137
137
  created_at: external_exports.string(),
138
- completed_at: external_exports.string()
138
+ completed_at: external_exports.string(),
139
+ // What the invoice billed, and the plan change it paid for
140
+ // (SubscriptionService.getBillingHistory, BillingHistoryPlanChangeSchema).
141
+ kind: external_exports.enum(["first_order", "renewal", "plan_change"]),
142
+ plan_change: external_exports.object({
143
+ from_plan_name: external_exports.string(),
144
+ to_plan_name: external_exports.string(),
145
+ source: external_exports.enum(["buyer", "merchant"]),
146
+ days_left: external_exports.number().nullable(),
147
+ days_total: external_exports.number().nullable()
148
+ }).nullable()
139
149
  }))
140
150
  });
141
151
  var customerPortalSubscriptionCancelSchema = external_exports.object({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../contracts/src/customer-portal-wire.ts","../../sdk/src/headless-customer.ts"],"sourcesContent":["import { z } from 'zod';\nimport { customerPortalBrandingSchema } from './customer-account-wire.js';\n\n// The buyer account wire the storefront SDK validates lives in\n// ./customer-account-wire so storefront bundles do not ship the portal-only\n// schemas below. This module re-exports it: portal consumers keep one import.\nexport {\n customerLoyaltyRedeemSchema,\n customerLoyaltySchema,\n customerPortalAffiliateCreateLinkSchema,\n customerPortalAffiliateSummarySchema,\n customerPortalDashboardInvoiceSchema,\n customerPortalDashboardSchema,\n customerPortalInvoiceDetailSchema,\n customerPortalNotificationPreferencesSchema,\n customerPortalOrderReviewSchema,\n customerPortalPaginatedInvoiceSchema,\n customerPortalPaginatedInvoicesSchema,\n customerPortalRewardActivityItemSchema,\n customerPortalRewardsSchema,\n customerPortalSubscriptionSummarySchema,\n customerWarrantyClaimSchema,\n customerWarrantyListSchema,\n} from './customer-account-wire.js';\nexport type {\n CustomerLoyaltyRedeemWire,\n CustomerLoyaltyWire,\n CustomerPortalAffiliateCreateLinkWire,\n CustomerPortalAffiliateSummaryWire,\n CustomerPortalDashboardWire,\n CustomerPortalInvoiceDetailWire,\n CustomerPortalInvoiceShippingWire,\n CustomerPortalNotificationPreferencesWire,\n CustomerPortalOrderReviewWire,\n CustomerPortalPaginatedInvoicesWire,\n CustomerPortalRewardActivityItemWire,\n CustomerPortalRewardsWire,\n CustomerPortalSubscriptionSummaryWire,\n CustomerWarrantyClaimWire,\n CustomerWarrantyListWire,\n} from './customer-account-wire.js';\n\nconst nullableStringSchema = z.string().nullable();\n\nexport const customerPortalMeSchema = z.object({\n customer: z.object({\n id: nullableStringSchema,\n email: z.string(),\n name: z.string(),\n avatar_url: nullableStringSchema,\n joined_at: nullableStringSchema,\n }),\n shop: z.object({\n id: z.string(),\n slug: z.string(),\n name: z.string(),\n currency: z.string(),\n branding: customerPortalBrandingSchema,\n }),\n token: z.null(),\n});\n\nexport const customerPortalWalletTopupQuoteSchema = z.object({\n quote: z.object({\n enabled: z.boolean(),\n currency: z.string(),\n min_amount: z.string(),\n max_amount: nullableStringSchema,\n bonus_tiers: z.array(z.object({\n min_amount: z.string(),\n bonus_percent: z.number(),\n })),\n }),\n});\n\nexport const customerPortalWalletTopupResultSchema = z.object({\n invoice_id: z.string(),\n url: z.string(),\n});\n\nexport const customerPortalAffiliateStatsSchema = z.object({\n window_days: z.number(),\n totals: z.object({\n clicks: z.number(),\n add_to_carts: z.number(),\n checkouts_started: z.number(),\n sales: z.number(),\n }),\n per_link: z.array(z.object({\n link_id: z.string(),\n code: z.string(),\n label: nullableStringSchema,\n clicks: z.number(),\n add_to_carts: z.number(),\n checkouts_started: z.number(),\n })),\n daily: z.array(z.object({\n date: z.string(),\n clicks: z.number(),\n add_to_carts: z.number(),\n checkouts_started: z.number(),\n })),\n});\n\n// ---------------------------------------------------------------------------\n// Headless customer-portal action contracts\n// ---------------------------------------------------------------------------\n\nexport const customerPortalProfileUpdateSchema = z.object({\n customer: z.object({\n id: z.string(),\n email: z.string(),\n name: z.string(),\n joined_at: nullableStringSchema,\n }),\n});\n\nexport const customerPortalAvatarSchema = z.object({\n avatar_url: nullableStringSchema,\n});\n\nexport const customerPortalEmailPreferencesSchema = z.object({\n global_unsubscribed: z.boolean(),\n lists: z.array(z.object({\n id: z.string(),\n name: z.string(),\n description: nullableStringSchema,\n subscribed: z.boolean(),\n })),\n});\n\nexport const customerPortalEmailPreferencesUpdateSchema = z.object({\n updated: z.boolean(),\n});\n\nexport const customerPortalFavoritesSchema = z.object({\n favorites: z.array(z.object({\n product_uniqid: z.string(),\n title: z.string(),\n slug: nullableStringSchema,\n image_url: nullableStringSchema,\n price_display: z.number(),\n unavailable: z.boolean(),\n created_at: z.string(),\n })),\n});\n\nexport const customerPortalFavoriteMutationSchema = z.union([\n z.object({ added: z.literal(true) }),\n z.object({ removed: z.literal(true) }),\n]);\n\nexport const customerPortalLicenseResetSchema = z.object({\n license: z.object({\n uniqid: z.string(),\n hardware_id: nullableStringSchema,\n }),\n});\n\nexport const customerPortalLicenseRenewalSchema = z.object({\n invoice_id: z.string(),\n checkout_url: z.string(),\n preferred_gateways: z.array(z.string()),\n license: z.object({\n uniqid: z.string(),\n product_title: z.string(),\n }),\n});\n\nexport const customerPortalSubscriptionBillingHistorySchema = z.object({\n invoices: z.array(z.object({\n id: z.string(),\n uniqid: z.string(),\n total: z.string(),\n currency: z.string(),\n status: z.string(),\n gateway: z.string(),\n created_at: z.string(),\n completed_at: z.string(),\n })),\n});\n\nexport const customerPortalSubscriptionCancelSchema = z.object({\n subscription: z.object({\n id: z.string(),\n status: z.string(),\n cancel_at_period_end: z.boolean(),\n cancel_reason: nullableStringSchema,\n canceled_at: nullableStringSchema,\n }),\n});\n\nexport const customerPortalSubscriptionStatusSchema = z.object({\n subscription: z.object({\n id: z.string(),\n status: z.string(),\n }),\n});\n\nexport const customerPortalSupportTicketDetailSchema = z.object({\n ticket: z.object({\n uniqid: z.string(),\n title: z.string(),\n status: z.string(),\n invoice_id: nullableStringSchema,\n created_at: z.string(),\n updated_at: z.string(),\n messages: z.array(z.object({\n id: z.string(),\n role: z.enum(['CUSTOMER', 'SHOP', 'SYSTEM']),\n message: z.string(),\n created_at: z.string(),\n })),\n }),\n});\n\nexport const customerPortalSupportCreateSchema = z.object({\n uniqid: z.string(),\n});\n\nconst customerResellerTierSchema = z.object({\n id: z.string(),\n name: nullableStringSchema,\n discount_percent: z.number().nullable(),\n});\n\nconst customerResellerRelationshipSchema = z.object({\n id: z.string(),\n status: z.enum(['INVITED', 'APPLIED', 'ACTIVE', 'SUSPENDED', 'REJECTED']),\n tier: customerResellerTierSchema.nullable(),\n application_note: nullableStringSchema,\n lifetime_revenue: z.string(),\n lifetime_orders: z.number(),\n approved_at: nullableStringSchema,\n created_at: z.string(),\n});\n\nexport const customerResellerSummarySchema = z.object({\n program_enabled: z.boolean(),\n api_enabled: z.boolean(),\n portal_purchasing_enabled: z.boolean(),\n enrollment_mode: z.enum(['MANUAL', 'APPLICATION', 'OPEN']),\n application_message: nullableStringSchema,\n require_application_note: z.boolean(),\n reseller: customerResellerRelationshipSchema.nullable(),\n});\n\nexport const customerResellerEnrollmentSchema = z.object({\n reseller: customerResellerRelationshipSchema,\n});\n\nconst customerResellerAppliedOverrideSchema = z.enum(['variant', 'product', 'tier']);\n\nconst customerResellerCatalogVariantSchema = z.object({\n variant_id: z.string(),\n title: z.string(),\n stock: z.number(),\n orderable: z.boolean(),\n base_price: z.string(),\n unit_price: z.string(),\n discount_percent: z.number(),\n applied_override: customerResellerAppliedOverrideSchema,\n});\n\n/**\n * A product custom field a wholesale order line answers in `items[].custom_fields`,\n * keyed by `name`. `format` is the check the server applies when there is no `regex`.\n */\nexport const customerResellerCustomFieldSchema = z.object({\n name: z.string(),\n type: z.string(),\n required: z.boolean(),\n placeholder: z.string(),\n default_value: z.string(),\n regex: nullableStringSchema,\n min_length: z.number().nullable(),\n format: z.enum(['number', 'discord_invite', 'url']).nullable(),\n /** Only on a `select`: the answer must be one of these labels. */\n options: z.array(z.string()).optional(),\n});\n\nexport const customerResellerCatalogSchema = z.object({\n tier: customerResellerTierSchema,\n catalog: z.object({\n currency: z.string(),\n total: z.number(),\n page: z.number(),\n per_page: z.number(),\n items: z.array(z.object({\n product_id: z.string(),\n uniqid: z.string(),\n title: z.string(),\n type: z.string(),\n stock: z.number(),\n orderable: z.boolean(),\n volume_discount_enabled: z.boolean(),\n base_price: z.string(),\n unit_price: z.string(),\n discount_percent: z.number(),\n applied_override: customerResellerAppliedOverrideSchema,\n /** Optional: a backend released before reseller custom fields does not send it. */\n custom_fields: z.array(customerResellerCustomFieldSchema).optional(),\n variants: z.array(customerResellerCatalogVariantSchema),\n })),\n }),\n});\n\nexport const customerResellerQuoteSchema = z.object({\n quote: z.object({\n currency: z.string(),\n tier: customerResellerTierSchema,\n items: z.array(z.object({\n product_id: z.string(),\n product_title: z.string(),\n product_type: z.string(),\n variant_id: nullableStringSchema,\n variant_title: nullableStringSchema,\n quantity: z.number(),\n base_price: z.string(),\n discount_percent: z.number(),\n unit_price: z.string(),\n line_total: z.string(),\n applied_override: customerResellerAppliedOverrideSchema,\n volume_discount_applied: z.string(),\n })),\n subtotal: z.string(),\n volume_discount_total: z.string(),\n total: z.string(),\n savings: z.string(),\n }),\n});\n\nexport const customerResellerOrdersSchema = z.object({\n orders: z.object({\n total: z.number(),\n page: z.number(),\n per_page: z.number(),\n items: z.array(z.object({\n uniqid: z.string(),\n status: z.string(),\n currency: z.string(),\n total: z.string(),\n item_count: z.number(),\n created_at: z.string(),\n })),\n }),\n});\n\nexport const customerResellerOrderSchema = z.object({\n order: z.object({\n uniqid: z.string(),\n status: z.string(),\n currency: z.string(),\n total: z.string(),\n item_count: z.number(),\n created_at: z.string(),\n tier_name: z.string(),\n tier_discount_percent: z.number(),\n partially_delivered: z.boolean(),\n refunded_amount: nullableStringSchema,\n lines: z.array(z.object({\n product_id: nullableStringSchema,\n product_title: z.string(),\n variant_id: nullableStringSchema,\n variant_title: nullableStringSchema,\n quantity: z.number(),\n unit_price: z.string(),\n total: z.string(),\n delivered: z.boolean(),\n delivered_at: nullableStringSchema,\n serials: z.array(z.string()),\n })),\n }),\n});\n\nexport const customerResellerWalletSchema = z.object({\n wallet: z.object({\n currency: z.string(),\n balance: z.string(),\n hold_balance: z.string(),\n available: z.string(),\n is_active: z.boolean(),\n }),\n});\n\nexport const customerResellerApiKeysSchema = z.object({\n api_keys: z.array(z.object({\n id: z.string(),\n name: z.string(),\n key_last4: z.string(),\n last_used_at: nullableStringSchema,\n revoked_at: nullableStringSchema,\n created_at: z.string(),\n })),\n});\n\nexport const customerResellerTopupSchema = z.object({\n topup: z.object({\n uniqid: z.string(),\n url: z.string(),\n }),\n});\n\nexport type CustomerPortalMeWire = z.infer<typeof customerPortalMeSchema>;\nexport type CustomerPortalAffiliateStatsWire = z.infer<typeof customerPortalAffiliateStatsSchema>;\nexport type CustomerPortalWalletTopupQuoteWire = z.infer<typeof customerPortalWalletTopupQuoteSchema>;\nexport type CustomerPortalWalletTopupResultWire = z.infer<typeof customerPortalWalletTopupResultSchema>;\nexport type CustomerPortalProfileUpdateWire = z.infer<typeof customerPortalProfileUpdateSchema>;\nexport type CustomerPortalAvatarWire = z.infer<typeof customerPortalAvatarSchema>;\nexport type CustomerPortalEmailPreferencesWire = z.infer<typeof customerPortalEmailPreferencesSchema>;\nexport type CustomerPortalEmailPreferencesUpdateWire = z.infer<typeof customerPortalEmailPreferencesUpdateSchema>;\nexport type CustomerPortalFavoritesWire = z.infer<typeof customerPortalFavoritesSchema>;\nexport type CustomerPortalFavoriteMutationWire = z.infer<typeof customerPortalFavoriteMutationSchema>;\nexport type CustomerPortalLicenseResetWire = z.infer<typeof customerPortalLicenseResetSchema>;\nexport type CustomerPortalLicenseRenewalWire = z.infer<typeof customerPortalLicenseRenewalSchema>;\nexport type CustomerPortalSubscriptionBillingHistoryWire = z.infer<typeof customerPortalSubscriptionBillingHistorySchema>;\nexport type CustomerPortalSubscriptionCancelWire = z.infer<typeof customerPortalSubscriptionCancelSchema>;\nexport type CustomerPortalSubscriptionStatusWire = z.infer<typeof customerPortalSubscriptionStatusSchema>;\nexport type CustomerPortalSupportTicketDetailWire = z.infer<typeof customerPortalSupportTicketDetailSchema>;\nexport type CustomerPortalSupportCreateWire = z.infer<typeof customerPortalSupportCreateSchema>;\nexport type CustomerResellerSummaryWire = z.infer<typeof customerResellerSummarySchema>;\nexport type CustomerResellerEnrollmentWire = z.infer<typeof customerResellerEnrollmentSchema>;\nexport type CustomerResellerCatalogWire = z.infer<typeof customerResellerCatalogSchema>;\nexport type CustomerResellerQuoteWire = z.infer<typeof customerResellerQuoteSchema>;\nexport type CustomerResellerOrdersWire = z.infer<typeof customerResellerOrdersSchema>;\nexport type CustomerResellerOrderWire = z.infer<typeof customerResellerOrderSchema>;\nexport type CustomerResellerWalletWire = z.infer<typeof customerResellerWalletSchema>;\nexport type CustomerResellerApiKeysWire = z.infer<typeof customerResellerApiKeysSchema>;\nexport type CustomerResellerTopupWire = z.infer<typeof customerResellerTopupSchema>;\n","/**\n * Browser client for a customer account hosted outside Shoppex.\n *\n * The publishable key identifies the merchant and the dashboard origin\n * allowlist authorizes the browser origin. OTP verification returns a separate\n * short-lived `hcs_` token; the SDK never exposes Shoppex's BetterAuth token.\n */\nimport {\n customerLoyaltyRedeemSchema,\n customerLoyaltySchema,\n customerPortalAffiliateSummarySchema,\n customerPortalAffiliateStatsSchema,\n customerPortalAffiliateCreateLinkSchema,\n customerPortalAvatarSchema,\n customerPortalDashboardSchema,\n customerPortalEmailPreferencesSchema,\n customerPortalEmailPreferencesUpdateSchema,\n customerPortalFavoriteMutationSchema,\n customerPortalFavoritesSchema,\n customerPortalInvoiceDetailSchema,\n customerPortalLicenseResetSchema,\n customerPortalLicenseRenewalSchema,\n customerPortalMeSchema,\n customerPortalNotificationPreferencesSchema,\n customerPortalOrderReviewSchema,\n customerPortalPaginatedInvoicesSchema,\n customerPortalProfileUpdateSchema,\n customerPortalSubscriptionBillingHistorySchema,\n customerPortalSubscriptionCancelSchema,\n customerPortalSubscriptionStatusSchema,\n customerPortalSupportCreateSchema,\n customerPortalSupportTicketDetailSchema,\n customerResellerApiKeysSchema,\n customerResellerCatalogSchema,\n customerResellerEnrollmentSchema,\n customerResellerOrderSchema,\n customerResellerOrdersSchema,\n customerResellerQuoteSchema,\n customerResellerSummarySchema,\n customerResellerWalletSchema,\n customerWarrantyClaimSchema,\n customerWarrantyListSchema,\n type CustomerLoyaltyRedeemWire,\n type CustomerLoyaltyWire,\n type CustomerPortalAffiliateSummaryWire,\n type CustomerPortalAffiliateStatsWire,\n type CustomerPortalAffiliateCreateLinkWire,\n type CustomerPortalAvatarWire,\n type CustomerPortalDashboardWire,\n type CustomerPortalEmailPreferencesUpdateWire,\n type CustomerPortalEmailPreferencesWire,\n type CustomerPortalFavoriteMutationWire,\n type CustomerPortalFavoritesWire,\n type CustomerPortalLicenseResetWire,\n type CustomerPortalLicenseRenewalWire,\n type CustomerPortalNotificationPreferencesWire,\n type CustomerPortalOrderReviewWire,\n type CustomerPortalProfileUpdateWire,\n type CustomerPortalSubscriptionBillingHistoryWire,\n type CustomerPortalSubscriptionCancelWire,\n type CustomerPortalSubscriptionStatusWire,\n type CustomerPortalSupportCreateWire,\n type CustomerPortalSupportTicketDetailWire,\n type CustomerResellerApiKeysWire,\n type CustomerResellerCatalogWire,\n type CustomerResellerEnrollmentWire,\n type CustomerResellerOrderWire,\n type CustomerResellerOrdersWire,\n type CustomerResellerQuoteWire,\n type CustomerResellerSummaryWire,\n type CustomerResellerWalletWire,\n type CustomerWarrantyClaimWire,\n type CustomerWarrantyListWire,\n} from '@shoppex/contracts/customer-portal-wire';\nimport { storefrontStorageKey } from '@shoppex/contracts/storefront-storage-key';\n\nconst DEFAULT_API_ORIGIN = 'https://api.shoppex.io';\nconst SESSION_STORAGE_PREFIX = 'shoppex_headless_customer_session:';\n\ninterface CustomerPayloadSchema<T> {\n safeParse(value: unknown): { success: true; data: T } | { success: false };\n}\n\ninterface ApiEnvelope<T> {\n status: number;\n data: T | null;\n error: string | null;\n message?: string | null;\n error_code?: string | null;\n}\n\ninterface StoredSession {\n accessToken: string;\n expiresAt: string;\n savedAt: number;\n}\n\nexport interface HeadlessCustomerClientConfig {\n /** Shop slug or Shoppex storefront domain. */\n shop: string;\n /** Existing Headless Checkout publishable key (`pk_live_` / `pk_test_`). */\n publishableKey: string;\n /** API origin override. Defaults to https://api.shoppex.io. */\n apiBaseUrl?: string;\n /** Optional fetch override for tests or compatible runtimes. */\n fetchImpl?: typeof fetch;\n /** Optional session storage override. Defaults to browser sessionStorage. */\n storage?: Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;\n /** Optional persistent storage override. Defaults to browser localStorage. */\n persistentStorage?: Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;\n}\n\nexport interface HeadlessCustomerSession {\n accessToken: string;\n expiresAt: string;\n}\n\nexport interface HeadlessCustomerVerifyOptions {\n /** Persist the customer session across browser restarts for up to 30 days. */\n rememberMe?: boolean;\n}\n\nexport interface HeadlessCustomerOrdersQuery {\n page?: number;\n limit?: number;\n status?: string;\n search?: string;\n}\n\nexport interface HeadlessCustomerDownload {\n blob: Blob;\n filename: string | null;\n contentType: string | null;\n}\n\ntype HeadlessCustomerDashboardDeliverable =\n CustomerPortalDashboardWire['deliverables'][number] & {\n /** Pass this value with `invoice_uniqid` to `customer.download()`. */\n downloadIndex?: number | null;\n };\n\nexport type HeadlessCustomerDashboard = Omit<CustomerPortalDashboardWire, 'deliverables'> & {\n deliverables: HeadlessCustomerDashboardDeliverable[];\n};\nexport type HeadlessCustomerProfileUpdate = CustomerPortalProfileUpdateWire;\nexport type HeadlessCustomerAvatar = CustomerPortalAvatarWire;\nexport type HeadlessCustomerEmailPreferences = CustomerPortalEmailPreferencesWire;\nexport type HeadlessCustomerEmailPreferencesUpdate = CustomerPortalEmailPreferencesUpdateWire;\nexport type HeadlessCustomerNotificationPreferences = CustomerPortalNotificationPreferencesWire;\n/**\n * `reviewer_name` and `anonymous` come with the backend of #3697, which deploys\n * after this SDK version is on npm (a theme-runtime pin is published before its\n * release PR). Until that deploy the API answers without them, so they are\n * optional here; tighten back to `CustomerPortalOrderReviewWire` once it shipped.\n */\nexport type HeadlessCustomerOrderReview = Omit<CustomerPortalOrderReviewWire, 'reviewer_name' | 'anonymous'>\n & Partial<Pick<CustomerPortalOrderReviewWire, 'reviewer_name' | 'anonymous'>>;\nconst orderReviewSchema = customerPortalOrderReviewSchema.partial({ reviewer_name: true, anonymous: true });\nexport type HeadlessCustomerFavorites = CustomerPortalFavoritesWire;\nexport type HeadlessCustomerFavoriteMutation = CustomerPortalFavoriteMutationWire;\nexport type HeadlessCustomerAffiliate = CustomerPortalAffiliateSummaryWire;\nexport type HeadlessCustomerAffiliateStats = CustomerPortalAffiliateStatsWire;\nexport type HeadlessCustomerAffiliateLink = CustomerPortalAffiliateCreateLinkWire;\nexport type HeadlessCustomerTicket = CustomerPortalSupportTicketDetailWire;\nexport type HeadlessCustomerTicketCreateResult = CustomerPortalSupportCreateWire;\nexport type HeadlessCustomerLicenseReset = CustomerPortalLicenseResetWire;\nexport type HeadlessCustomerLicenseRenewal = CustomerPortalLicenseRenewalWire;\nexport type HeadlessCustomerSubscriptionBillingHistory = CustomerPortalSubscriptionBillingHistoryWire;\nexport type HeadlessCustomerSubscriptionCancel = CustomerPortalSubscriptionCancelWire;\nexport type HeadlessCustomerSubscriptionStatus = CustomerPortalSubscriptionStatusWire;\nexport type HeadlessCustomerLoyalty = CustomerLoyaltyWire;\nexport type HeadlessCustomerLoyaltyRedeem = CustomerLoyaltyRedeemWire;\nexport type HeadlessCustomerWarranties = CustomerWarrantyListWire;\nexport type HeadlessCustomerWarrantyClaim = CustomerWarrantyClaimWire;\nexport type HeadlessCustomerReseller = CustomerResellerSummaryWire;\nexport type HeadlessCustomerResellerEnrollment = CustomerResellerEnrollmentWire;\nexport type HeadlessCustomerResellerCatalog = CustomerResellerCatalogWire;\nexport type HeadlessCustomerResellerQuote = CustomerResellerQuoteWire;\nexport type HeadlessCustomerResellerOrders = CustomerResellerOrdersWire;\nexport type HeadlessCustomerResellerOrder = CustomerResellerOrderWire;\nexport type HeadlessCustomerResellerWallet = CustomerResellerWalletWire;\nexport type HeadlessCustomerResellerApiKeys = CustomerResellerApiKeysWire;\n\nexport interface HeadlessCustomerTicketInput {\n title?: string;\n message: string;\n invoiceId?: string;\n}\n\nexport interface HeadlessCustomerOrderReviewInput {\n score: 1 | 3 | 5;\n message: string;\n /**\n * Post without the buyer's name. Omitted = anonymous; pass `false` once the\n * buyer saw `orderReview().reviewer_name` and chose to show it (an API that\n * answers no `reviewer_name` saves the review anonymously either way).\n */\n anonymous?: boolean;\n}\n\nexport interface HeadlessCustomerAffiliateLinkInput {\n code: string;\n label: string;\n requestedRevenuePercent?: number | null;\n requestedCustomerDiscountPercent?: number | null;\n}\n\nexport interface HeadlessCustomerSubscriptionCancelOptions {\n cancelAtPeriodEnd?: boolean;\n reason?: string | null;\n}\n\n/**\n * A buyer pause: one of the dashboard's `pause_options.lengths[].days`, and a reason\n * (`taking_a_break`, `too_expensive`, `not_using`, `not_working`, `other`) when\n * `pause_options.reason_enabled`. Without `lengthDays` the backend pauses for the shop's longest pause.\n */\nexport interface HeadlessCustomerSubscriptionPauseOptions {\n lengthDays?: 7 | 14 | 30 | 60 | 90;\n reason?: 'taking_a_break' | 'too_expensive' | 'not_using' | 'not_working' | 'other' | null;\n}\n\nexport interface HeadlessCustomerEmailPreferencesPatch {\n globalUnsubscribed?: boolean;\n listSubscriptions?: Array<{ listId: string; subscribed: boolean }>;\n}\n\nexport interface HeadlessCustomerNotificationPreferencesPatch {\n orderCreatedEmails?: boolean;\n orderCompletedEmails?: boolean;\n paymentIssueEmails?: boolean;\n}\n\nexport interface HeadlessCustomerResellerCatalogQuery {\n search?: string;\n page?: number;\n perPage?: number;\n}\n\nexport interface HeadlessCustomerResellerOrdersQuery {\n page?: number;\n perPage?: number;\n}\n\nexport interface HeadlessCustomerResellerOrderItem {\n productId: string;\n variantId?: string;\n quantity: number;\n}\n\n/** Public DTOs mirror the producer-owned schemas imported above. Passing each\n * schema into `request<T>` makes TypeScript reject drift in required fields. */\nexport interface HeadlessCustomerMe {\n customer: {\n id: string | null;\n email: string;\n name: string;\n avatar_url: string | null;\n joined_at: string | null;\n };\n shop: {\n id: string;\n slug: string;\n name: string;\n currency: string;\n branding: {\n logo_url: string | null;\n primary_color: string;\n secondary_color: string;\n accent_color: string;\n };\n };\n}\n\ntype HeadlessCustomerMeWire = HeadlessCustomerMe & { token: string | null };\n\nexport interface HeadlessCustomerOrderSummary {\n uniqid: string;\n status: string;\n total: string;\n totalDisplay: string | null;\n currency: string;\n createdAt: string;\n lineItems: Array<{\n productTitle: string | null;\n quantity: number;\n product: {\n attachment_imageId: { cloudflareImageId: string | null } | null;\n } | null;\n }>;\n}\n\nexport interface HeadlessCustomerOrders {\n invoices: HeadlessCustomerOrderSummary[];\n pagination: {\n page: number;\n limit: number;\n total: number;\n has_more: boolean;\n };\n}\n\nexport interface HeadlessCustomerPayment {\n gateway: string;\n displayName: string | null;\n cryptoGateway?: string | null;\n blockchain: string | null;\n cryptoAddress: string | null;\n apmMethod: string | null;\n}\n\nexport interface HeadlessCustomerOrder {\n id: string;\n uniqid: string;\n status: string;\n statusDetails: string | null;\n total: string;\n totalDisplay: string | null;\n subtotal: string;\n discount: string;\n discountDisplay: string | null;\n tax: string;\n taxPercentage: string;\n currency: string;\n createdAt: string;\n updatedAt: string;\n gatewayUpdatedAt: string | null;\n customFields: Record<string, unknown> | null;\n balancePaidAmount: string;\n currentPaymentAttemptId: string | null;\n lineItems: Array<{\n id: string;\n productTitle: string;\n productType: string;\n variantTitle: string | null;\n unitPrice: string;\n quantity: number;\n total: string;\n deliveryText: string | null;\n deliverySummary: {\n codes: string[];\n links: Array<{\n label: string;\n value: string;\n /** External URL for non-Shoppex links. Portal-only download URLs are removed. */\n href?: string | null;\n /** Pass this value to `customer.download(orderId, downloadIndex)`. */\n downloadIndex?: number | null;\n }>;\n notes: string[];\n serials: Array<{ value: string; is_replacement: boolean; is_replaced: boolean }>;\n } | null;\n deliveredAt: string | null;\n deliveryStatus: 'PENDING' | 'AWAITING_FULFILLMENT' | 'DELIVERED' | 'FAILED';\n customFields: Record<string, unknown> | null;\n product: {\n uniqid: string;\n slug: string | null;\n serviceText: string | null;\n attachment_imageId: { cloudflareImageId: string | null } | null;\n } | null;\n }>;\n currentPayment: HeadlessCustomerPayment | null;\n payments: HeadlessCustomerPayment[];\n}\n\n/**\n * `code: 'RESPONSE_CONTRACT_VIOLATION'` (status 2xx) on `redeemLoyaltyPoints`\n * means the server completed the call and withheld its answer. Re-read the\n * account (`loyalty()`) and show that; do not report a failure or call again.\n */\nexport class HeadlessCustomerError extends Error {\n constructor(\n public readonly status: number,\n message: string,\n public readonly code?: string | null,\n ) {\n super(message);\n this.name = 'HeadlessCustomerError';\n }\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction parseStoredSession(value: string | null): StoredSession | null {\n if (!value) return null;\n try {\n const parsed: unknown = JSON.parse(value);\n if (\n !isRecord(parsed)\n || typeof parsed.accessToken !== 'string'\n || !parsed.accessToken.startsWith('hcs_')\n || typeof parsed.expiresAt !== 'string'\n || typeof parsed.savedAt !== 'number'\n || !Number.isFinite(parsed.savedAt)\n ) {\n return null;\n }\n const expiresAtMs = Date.parse(parsed.expiresAt);\n if (!Number.isFinite(expiresAtMs) || expiresAtMs <= Date.now()) return null;\n return { accessToken: parsed.accessToken, expiresAt: parsed.expiresAt, savedAt: parsed.savedAt };\n } catch {\n return null;\n }\n}\n\nfunction readFilename(header: string | null): string | null {\n if (!header) return null;\n const utf8Match = header.match(/filename\\*=UTF-8''([^;]+)/i);\n if (utf8Match?.[1]) {\n try {\n return decodeURIComponent(utf8Match[1]);\n } catch {\n return utf8Match[1];\n }\n }\n return header.match(/filename=\"([^\"]+)\"/i)?.[1] ?? null;\n}\n\nfunction readPortalDownloadIndex(href: string | null | undefined): number | null {\n // Only relative URLs are owned by the Shoppex customer portal. An external\n // site may legitimately use the same pathname and must remain an external link.\n if (!href?.startsWith('/api/customer/')) return null;\n try {\n const url = new URL(href, 'https://headless-customer.invalid');\n if (!/^\\/api\\/customer\\/invoice\\/[^/]+\\/download$/.test(url.pathname)) return null;\n const rawIndex = url.searchParams.get('file_index');\n if (rawIndex === null || !/^\\d+$/.test(rawIndex)) return null;\n const index = Number(rawIndex);\n return Number.isSafeInteger(index) ? index : null;\n } catch {\n return null;\n }\n}\n\nfunction readBrowserStorage(name: 'sessionStorage' | 'localStorage'):\n Pick<Storage, 'getItem' | 'setItem' | 'removeItem'> | null {\n try {\n return typeof window === 'undefined' ? null : window[name];\n } catch {\n return null;\n }\n}\n\nexport class HeadlessCustomerClient {\n private readonly base: string;\n private readonly shop: string;\n private readonly publishableKey: string;\n private readonly fetchImpl: typeof fetch;\n private readonly storage: Pick<Storage, 'getItem' | 'setItem' | 'removeItem'> | null;\n private readonly persistentStorage: Pick<Storage, 'getItem' | 'setItem' | 'removeItem'> | null;\n private readonly storageKey: string;\n private memorySession: StoredSession | null = null;\n\n constructor(config: HeadlessCustomerClientConfig) {\n if (!config.shop.trim()) throw new Error('HeadlessCustomerClient requires a shop.');\n if (!config.publishableKey.trim()) {\n throw new Error('HeadlessCustomerClient requires a publishableKey.');\n }\n this.shop = config.shop.trim();\n this.publishableKey = config.publishableKey.trim();\n this.base = (config.apiBaseUrl ?? DEFAULT_API_ORIGIN).replace(/\\/+$/, '');\n this.fetchImpl = config.fetchImpl ?? globalThis.fetch?.bind(globalThis);\n if (!this.fetchImpl) throw new Error('No fetch implementation available; pass fetchImpl.');\n this.storage = config.storage ?? readBrowserStorage('sessionStorage');\n this.persistentStorage = config.persistentStorage ?? readBrowserStorage('localStorage');\n this.storageKey = `${SESSION_STORAGE_PREFIX}${this.shop}`;\n }\n\n getSession(): HeadlessCustomerSession | null {\n const candidates: StoredSession[] = this.memorySession ? [this.memorySession] : [];\n if (this.storage) {\n try {\n const stored = parseStoredSession(this.storage.getItem(storefrontStorageKey(this.storageKey)));\n if (stored) candidates.push(stored);\n } catch {\n // Continue with memory and persistent storage.\n }\n }\n if (this.persistentStorage) {\n try {\n const stored = parseStoredSession(this.persistentStorage.getItem(storefrontStorageKey(this.storageKey)));\n if (stored) candidates.push(stored);\n } catch {\n // Continue with the other available stores.\n }\n }\n\n const stored = candidates.sort((left, right) => right.savedAt - left.savedAt)[0] ?? null;\n\n if (!stored) {\n this.clearSession();\n return null;\n }\n this.memorySession = stored;\n return { accessToken: stored.accessToken, expiresAt: stored.expiresAt };\n }\n\n clearSession(): void {\n this.memorySession = null;\n try {\n this.storage?.removeItem(storefrontStorageKey(this.storageKey));\n } catch {\n // Privacy-restricted browsers may reject storage access. Memory is still cleared.\n }\n try {\n this.persistentStorage?.removeItem(storefrontStorageKey(this.storageKey));\n } catch {\n // The two stores are cleared independently so one rejected access cannot block the other.\n }\n }\n\n private saveSession(session: HeadlessCustomerSession, rememberMe: boolean): void {\n const storedSession: StoredSession = { ...session, savedAt: Date.now() };\n this.memorySession = storedSession;\n const target = rememberMe ? this.persistentStorage : this.storage;\n const other = rememberMe ? this.storage : this.persistentStorage;\n try {\n target?.setItem(storefrontStorageKey(this.storageKey), JSON.stringify(storedSession));\n } catch {\n // Keep the session for this client instance when browser storage is unavailable.\n }\n try {\n other?.removeItem(storefrontStorageKey(this.storageKey));\n } catch {\n // A stale session in the other storage cannot override the in-memory session.\n }\n }\n\n private url(path: string, query: Record<string, string | undefined> = {}): string {\n const url = new URL(`${this.base}/v1/customer${path}`);\n url.searchParams.set('shop', this.shop);\n for (const [key, value] of Object.entries(query)) {\n if (value !== undefined && value !== '') url.searchParams.set(key, value);\n }\n return url.toString();\n }\n\n private async request<T>(\n path: string,\n options: {\n method?: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';\n body?: unknown;\n formData?: FormData;\n authenticated?: boolean;\n schema?: CustomerPayloadSchema<T>;\n query?: Record<string, string | undefined>;\n } = {},\n ): Promise<T> {\n if (options.body !== undefined && options.formData !== undefined) {\n throw new Error('Customer requests cannot send JSON and FormData together.');\n }\n const session = options.authenticated ? this.getSession() : null;\n if (options.authenticated && !session) {\n throw new HeadlessCustomerError(401, 'Customer session is missing or expired.', 'UNAUTHORIZED');\n }\n\n const headers: Record<string, string> = {\n accept: 'application/json',\n 'x-shoppex-publishable-key': this.publishableKey,\n ...(options.body === undefined ? {} : { 'content-type': 'application/json' }),\n ...(session ? { authorization: `Bearer ${session.accessToken}` } : {}),\n };\n const requestBody = options.formData ?? (\n options.body === undefined ? undefined : JSON.stringify(options.body)\n );\n const response = await this.fetchImpl(this.url(path, options.query), {\n method: options.method ?? 'GET',\n headers,\n ...(requestBody === undefined ? {} : { body: requestBody }),\n cache: 'no-store',\n });\n\n let envelope: ApiEnvelope<unknown> | null = null;\n try {\n envelope = await response.json() as ApiEnvelope<unknown>;\n } catch {\n // Report a stable transport error below.\n }\n if (!response.ok || !envelope || envelope.error) {\n if (response.status === 401 && options.authenticated) this.clearSession();\n throw new HeadlessCustomerError(\n response.status,\n envelope?.error ?? `Request failed (${response.status})`,\n envelope?.error_code ?? null,\n );\n }\n\n if (!options.schema) return envelope.data as T;\n const parsed = options.schema.safeParse(envelope.data);\n if (!parsed.success) {\n throw new HeadlessCustomerError(response.status, 'Customer API response did not match the expected contract.');\n }\n return parsed.data;\n }\n\n private async requestFile(\n path: string,\n query: Record<string, string | undefined> = {},\n options: { rejectHtml?: boolean } = {},\n ): Promise<HeadlessCustomerDownload> {\n const session = this.getSession();\n if (!session) {\n throw new HeadlessCustomerError(401, 'Customer session is missing or expired.', 'UNAUTHORIZED');\n }\n\n const response = await this.fetchImpl(this.url(path, query), {\n method: 'GET',\n headers: {\n 'x-shoppex-publishable-key': this.publishableKey,\n authorization: `Bearer ${session.accessToken}`,\n },\n cache: 'no-store',\n });\n if (!response.ok) {\n if (response.status === 401) this.clearSession();\n let message = `Download failed (${response.status})`;\n try {\n const body = await response.json() as ApiEnvelope<unknown>;\n if (body.error) message = body.error;\n } catch {\n // Keep the stable status-based error.\n }\n throw new HeadlessCustomerError(response.status, message);\n }\n\n const contentType = response.headers.get('content-type');\n if (options.rejectHtml && contentType?.toLowerCase().startsWith('text/html')) {\n throw new HeadlessCustomerError(\n 502,\n 'Shoppex returned an unsafe aggregate download response.',\n 'UNSAFE_DOWNLOAD_RESPONSE',\n );\n }\n\n return {\n blob: await response.blob(),\n filename: readFilename(response.headers.get('content-disposition')),\n contentType,\n };\n }\n\n requestOtp(email: string): Promise<{ requested: boolean }> {\n return this.request('/auth/otp/request', {\n method: 'POST',\n body: { shop: this.shop, email },\n });\n }\n\n async verifyOtp(\n email: string,\n otp: string,\n options: HeadlessCustomerVerifyOptions = {},\n ): Promise<HeadlessCustomerSession> {\n const data = await this.request<{ access_token: string; expires_at: string }>('/auth/otp/verify', {\n method: 'POST',\n body: { shop: this.shop, email, otp, remember_me: options.rememberMe ?? false },\n });\n const expiresAtMs = typeof data?.expires_at === 'string' ? Date.parse(data.expires_at) : Number.NaN;\n if (\n typeof data?.access_token !== 'string'\n || !data.access_token.startsWith('hcs_')\n || typeof data.expires_at !== 'string'\n || !Number.isFinite(expiresAtMs)\n || expiresAtMs <= Date.now()\n ) {\n throw new HeadlessCustomerError(200, 'Customer API response did not match the expected contract.');\n }\n const session = { accessToken: data.access_token, expiresAt: data.expires_at };\n this.saveSession(session, options.rememberMe ?? false);\n return session;\n }\n\n async me(): Promise<HeadlessCustomerMe> {\n const data = await this.request<HeadlessCustomerMeWire>('/me', {\n authenticated: true,\n schema: customerPortalMeSchema,\n });\n if (data.token !== null) {\n // A raw BetterAuth token here would bypass the external route allowlist.\n // Reject the response instead of handing that credential to merchant JS.\n throw new HeadlessCustomerError(200, 'Customer API response did not match the expected contract.');\n }\n return { customer: data.customer, shop: data.shop };\n }\n\n async dashboard(): Promise<HeadlessCustomerDashboard> {\n const dashboard = await this.request<CustomerPortalDashboardWire>('/dashboard', {\n authenticated: true,\n schema: customerPortalDashboardSchema,\n });\n return {\n ...dashboard,\n deliverables: dashboard.deliverables.map((deliverable) => {\n const downloadIndex = readPortalDownloadIndex(deliverable.href);\n return downloadIndex === null\n ? deliverable\n : { ...deliverable, href: null, downloadIndex };\n }),\n };\n }\n\n updateProfile(input: { name: string }): Promise<HeadlessCustomerProfileUpdate> {\n return this.request('/profile', {\n method: 'POST',\n authenticated: true,\n body: { name: input.name },\n schema: customerPortalProfileUpdateSchema,\n });\n }\n\n updateAvatar(file: File): Promise<HeadlessCustomerAvatar> {\n const formData = new FormData();\n formData.append('file', file);\n return this.request('/profile/avatar', {\n method: 'POST',\n authenticated: true,\n formData,\n schema: customerPortalAvatarSchema,\n });\n }\n\n removeAvatar(): Promise<HeadlessCustomerAvatar> {\n return this.request('/profile/avatar', {\n method: 'DELETE',\n authenticated: true,\n schema: customerPortalAvatarSchema,\n });\n }\n\n emailPreferences(): Promise<HeadlessCustomerEmailPreferences> {\n return this.request('/email-marketing/preferences', {\n authenticated: true,\n schema: customerPortalEmailPreferencesSchema,\n });\n }\n\n updateEmailPreferences(\n patch: HeadlessCustomerEmailPreferencesPatch,\n ): Promise<HeadlessCustomerEmailPreferencesUpdate> {\n return this.request('/email-marketing/preferences', {\n method: 'PATCH',\n authenticated: true,\n body: {\n ...(patch.globalUnsubscribed === undefined\n ? {}\n : { global_unsubscribed: patch.globalUnsubscribed }),\n list_subscriptions: (patch.listSubscriptions ?? []).map((item) => ({\n list_id: item.listId,\n subscribed: item.subscribed,\n })),\n },\n schema: customerPortalEmailPreferencesUpdateSchema,\n });\n }\n\n notificationPreferences(): Promise<HeadlessCustomerNotificationPreferences> {\n return this.request('/notification-preferences', {\n authenticated: true,\n schema: customerPortalNotificationPreferencesSchema,\n });\n }\n\n updateNotificationPreferences(\n patch: HeadlessCustomerNotificationPreferencesPatch,\n ): Promise<HeadlessCustomerNotificationPreferences> {\n return this.request('/notification-preferences', {\n method: 'PATCH',\n authenticated: true,\n body: {\n ...(patch.orderCreatedEmails === undefined\n ? {}\n : { order_created_emails: patch.orderCreatedEmails }),\n ...(patch.orderCompletedEmails === undefined\n ? {}\n : { order_completed_emails: patch.orderCompletedEmails }),\n ...(patch.paymentIssueEmails === undefined\n ? {}\n : { payment_issue_emails: patch.paymentIssueEmails }),\n },\n schema: customerPortalNotificationPreferencesSchema,\n });\n }\n\n orders(options: HeadlessCustomerOrdersQuery = {}): Promise<HeadlessCustomerOrders> {\n return this.request<HeadlessCustomerOrders>('/invoices', {\n authenticated: true,\n schema: customerPortalPaginatedInvoicesSchema,\n query: {\n page: options.page === undefined ? undefined : String(options.page),\n limit: options.limit === undefined ? undefined : String(options.limit),\n status: options.status,\n q: options.search,\n },\n });\n }\n\n async order(id: string): Promise<HeadlessCustomerOrder> {\n const order = await this.request<HeadlessCustomerOrder>(`/invoice/${encodeURIComponent(id)}`, {\n authenticated: true,\n schema: customerPortalInvoiceDetailSchema,\n });\n return {\n ...order,\n lineItems: order.lineItems.map((lineItem) => ({\n ...lineItem,\n deliverySummary: lineItem.deliverySummary\n ? {\n ...lineItem.deliverySummary,\n links: lineItem.deliverySummary.links.map((link) => {\n const downloadIndex = readPortalDownloadIndex(link.href);\n return downloadIndex === null\n ? link\n : { ...link, href: null, downloadIndex };\n }),\n }\n : null,\n })),\n };\n }\n\n orderReview(orderId: string): Promise<HeadlessCustomerOrderReview> {\n return this.request(`/invoices/${encodeURIComponent(orderId)}/review`, {\n authenticated: true,\n schema: orderReviewSchema,\n });\n }\n\n submitOrderReview(\n orderId: string,\n input: HeadlessCustomerOrderReviewInput,\n ): Promise<HeadlessCustomerOrderReview> {\n return this.request(`/invoices/${encodeURIComponent(orderId)}/review`, {\n method: 'POST',\n authenticated: true,\n body: {\n score: input.score,\n message: input.message,\n ...(input.anonymous === undefined ? {} : { anonymous: input.anonymous }),\n },\n schema: orderReviewSchema,\n });\n }\n\n invoicePdf(orderId: string): Promise<HeadlessCustomerDownload> {\n return this.requestFile(`/invoices/${encodeURIComponent(orderId)}/pdf`);\n }\n\n async download(orderId: string, fileIndex: number): Promise<HeadlessCustomerDownload> {\n if (!Number.isSafeInteger(fileIndex) || fileIndex < 0) {\n throw new HeadlessCustomerError(\n 400,\n 'download requires a non-negative integer fileIndex from order().deliverySummary.links.',\n 'INVALID_FILE_INDEX',\n );\n }\n return this.requestFile(\n `/invoice/${encodeURIComponent(orderId)}/download`,\n { file_index: String(fileIndex) },\n { rejectHtml: true },\n );\n }\n\n resetLicenseHwid(licenseId: string): Promise<HeadlessCustomerLicenseReset> {\n return this.request(`/licenses/${encodeURIComponent(licenseId)}/reset-hwid`, {\n method: 'POST',\n authenticated: true,\n body: {},\n schema: customerPortalLicenseResetSchema,\n });\n }\n\n renewLicense(licenseId: string): Promise<HeadlessCustomerLicenseRenewal> {\n return this.request(`/licenses/${encodeURIComponent(licenseId)}/renew`, {\n method: 'POST',\n authenticated: true,\n // This established route requires shop in the body. The shared headless\n // gate independently verifies the same shop from the query and key.\n body: { shop: this.shop },\n schema: customerPortalLicenseRenewalSchema,\n });\n }\n\n subscriptionBillingHistory(\n subscriptionId: string,\n ): Promise<HeadlessCustomerSubscriptionBillingHistory> {\n return this.request(`/subscriptions/${encodeURIComponent(subscriptionId)}/billing-history`, {\n authenticated: true,\n schema: customerPortalSubscriptionBillingHistorySchema,\n });\n }\n\n cancelSubscription(\n subscriptionId: string,\n options: HeadlessCustomerSubscriptionCancelOptions = {},\n ): Promise<HeadlessCustomerSubscriptionCancel> {\n return this.request(`/subscriptions/${encodeURIComponent(subscriptionId)}/cancel`, {\n method: 'POST',\n authenticated: true,\n body: {\n ...(options.cancelAtPeriodEnd === undefined\n ? {}\n : { cancel_at_period_end: options.cancelAtPeriodEnd }),\n ...(options.reason === undefined ? {} : { reason: options.reason }),\n },\n schema: customerPortalSubscriptionCancelSchema,\n });\n }\n\n /** Pauses from `pause_options.starts_at`; a scheduled pause is called off with `resumeSubscription`. */\n pauseSubscription(\n subscriptionId: string,\n options: HeadlessCustomerSubscriptionPauseOptions = {},\n ): Promise<HeadlessCustomerSubscriptionStatus> {\n return this.request(`/subscriptions/${encodeURIComponent(subscriptionId)}/pause`, {\n method: 'POST',\n authenticated: true,\n body: {\n ...(options.lengthDays === undefined ? {} : { length_days: options.lengthDays }),\n ...(options.reason === undefined ? {} : { reason: options.reason }),\n },\n schema: customerPortalSubscriptionStatusSchema,\n });\n }\n\n resumeSubscription(subscriptionId: string): Promise<HeadlessCustomerSubscriptionStatus> {\n return this.request(`/subscriptions/${encodeURIComponent(subscriptionId)}/resume`, {\n method: 'POST',\n authenticated: true,\n body: {},\n schema: customerPortalSubscriptionStatusSchema,\n });\n }\n\n /** Takes back a cancellation scheduled for the period end (`actions.can_undo_cancel`). */\n undoSubscriptionCancel(subscriptionId: string): Promise<HeadlessCustomerSubscriptionCancel> {\n return this.request(`/subscriptions/${encodeURIComponent(subscriptionId)}/undo-cancel`, {\n method: 'POST',\n authenticated: true,\n body: {},\n schema: customerPortalSubscriptionCancelSchema,\n });\n }\n\n loyalty(): Promise<HeadlessCustomerLoyalty> {\n return this.request('/loyalty', {\n authenticated: true,\n schema: customerLoyaltySchema,\n });\n }\n\n redeemLoyaltyPoints(input: {\n points: number;\n idempotencyKey: string;\n }): Promise<HeadlessCustomerLoyaltyRedeem> {\n return this.request('/loyalty/redeem', {\n method: 'POST',\n authenticated: true,\n body: { points: input.points, idempotency_key: input.idempotencyKey },\n schema: customerLoyaltyRedeemSchema,\n });\n }\n\n warranties(invoiceId?: string): Promise<HeadlessCustomerWarranties> {\n return this.request('/warranties', {\n authenticated: true,\n query: { invoice: invoiceId },\n schema: customerWarrantyListSchema,\n });\n }\n\n claimWarranty(warrantyId: string, message?: string): Promise<HeadlessCustomerWarrantyClaim> {\n return this.request(`/warranties/${encodeURIComponent(warrantyId)}/claim`, {\n method: 'POST',\n authenticated: true,\n body: message ? { message } : {},\n schema: customerWarrantyClaimSchema,\n });\n }\n\n favorites(): Promise<HeadlessCustomerFavorites> {\n return this.request('/favorites', {\n authenticated: true,\n schema: customerPortalFavoritesSchema,\n });\n }\n\n addFavorite(productId: string): Promise<HeadlessCustomerFavoriteMutation> {\n return this.request(`/favorites/${encodeURIComponent(productId)}`, {\n method: 'PUT',\n authenticated: true,\n schema: customerPortalFavoriteMutationSchema,\n });\n }\n\n removeFavorite(productId: string): Promise<HeadlessCustomerFavoriteMutation> {\n return this.request(`/favorites/${encodeURIComponent(productId)}`, {\n method: 'DELETE',\n authenticated: true,\n schema: customerPortalFavoriteMutationSchema,\n });\n }\n\n affiliate(): Promise<HeadlessCustomerAffiliate> {\n return this.request('/affiliate', {\n authenticated: true,\n schema: customerPortalAffiliateSummarySchema,\n });\n }\n\n affiliateStats(input?: { days?: number }): Promise<HeadlessCustomerAffiliateStats> {\n return this.request('/affiliate/stats', {\n authenticated: true,\n schema: customerPortalAffiliateStatsSchema,\n query: input?.days === undefined ? {} : { days: String(input.days) },\n });\n }\n\n createAffiliateLink(\n input: HeadlessCustomerAffiliateLinkInput,\n ): Promise<HeadlessCustomerAffiliateLink> {\n return this.request('/affiliate/links', {\n method: 'POST',\n authenticated: true,\n body: {\n shop: this.shop,\n code: input.code,\n label: input.label,\n ...(input.requestedRevenuePercent === undefined\n ? {}\n : { requested_affiliate_revenue_percent: input.requestedRevenuePercent }),\n ...(input.requestedCustomerDiscountPercent === undefined\n ? {}\n : { requested_affiliate_customer_discount_percent: input.requestedCustomerDiscountPercent }),\n },\n schema: customerPortalAffiliateCreateLinkSchema,\n });\n }\n\n createTicket(input: HeadlessCustomerTicketInput): Promise<HeadlessCustomerTicketCreateResult> {\n return this.request('/tickets', {\n method: 'POST',\n authenticated: true,\n body: {\n ...(input.title === undefined ? {} : { title: input.title }),\n message: input.message,\n ...(input.invoiceId === undefined ? {} : { invoice_id: input.invoiceId }),\n },\n schema: customerPortalSupportCreateSchema,\n });\n }\n\n ticket(ticketId: string): Promise<HeadlessCustomerTicket> {\n return this.request(`/tickets/${encodeURIComponent(ticketId)}`, {\n authenticated: true,\n schema: customerPortalSupportTicketDetailSchema,\n });\n }\n\n async replyToTicket(ticketId: string, message: string): Promise<void> {\n await this.request<null>(`/tickets/${encodeURIComponent(ticketId)}/reply`, {\n method: 'POST',\n authenticated: true,\n body: { message },\n });\n }\n\n reseller(): Promise<HeadlessCustomerReseller> {\n return this.request('/reseller', {\n authenticated: true,\n schema: customerResellerSummarySchema,\n });\n }\n\n applyForReseller(note?: string): Promise<HeadlessCustomerResellerEnrollment> {\n return this.request('/reseller/apply', {\n method: 'POST',\n authenticated: true,\n body: note === undefined ? {} : { note },\n schema: customerResellerEnrollmentSchema,\n });\n }\n\n enrollAsReseller(): Promise<HeadlessCustomerResellerEnrollment> {\n return this.request('/reseller/enroll', {\n method: 'POST',\n authenticated: true,\n body: {},\n schema: customerResellerEnrollmentSchema,\n });\n }\n\n acceptResellerInvite(token: string): Promise<HeadlessCustomerResellerEnrollment> {\n return this.request('/reseller/accept-invite', {\n method: 'POST',\n authenticated: true,\n body: { token },\n schema: customerResellerEnrollmentSchema,\n });\n }\n\n resellerCatalog(\n options: HeadlessCustomerResellerCatalogQuery = {},\n ): Promise<HeadlessCustomerResellerCatalog> {\n return this.request('/reseller/catalog', {\n authenticated: true,\n query: {\n search: options.search,\n page: options.page === undefined ? undefined : String(options.page),\n per_page: options.perPage === undefined ? undefined : String(options.perPage),\n },\n schema: customerResellerCatalogSchema,\n });\n }\n\n quoteResellerOrder(\n items: HeadlessCustomerResellerOrderItem[],\n ): Promise<HeadlessCustomerResellerQuote> {\n return this.request('/reseller/orders/quote', {\n method: 'POST',\n authenticated: true,\n body: {\n items: items.map((item) => ({\n product_id: item.productId,\n ...(item.variantId === undefined ? {} : { variant_id: item.variantId }),\n quantity: item.quantity,\n })),\n },\n schema: customerResellerQuoteSchema,\n });\n }\n\n resellerOrders(\n options: HeadlessCustomerResellerOrdersQuery = {},\n ): Promise<HeadlessCustomerResellerOrders> {\n return this.request('/reseller/orders', {\n authenticated: true,\n query: {\n page: options.page === undefined ? undefined : String(options.page),\n per_page: options.perPage === undefined ? undefined : String(options.perPage),\n },\n schema: customerResellerOrdersSchema,\n });\n }\n\n resellerOrder(orderId: string): Promise<HeadlessCustomerResellerOrder> {\n return this.request(`/reseller/orders/${encodeURIComponent(orderId)}`, {\n authenticated: true,\n schema: customerResellerOrderSchema,\n });\n }\n\n resellerWallet(): Promise<HeadlessCustomerResellerWallet> {\n return this.request('/reseller/wallet', {\n authenticated: true,\n schema: customerResellerWalletSchema,\n });\n }\n\n resellerApiKeys(): Promise<HeadlessCustomerResellerApiKeys> {\n return this.request('/reseller/api-keys', {\n authenticated: true,\n schema: customerResellerApiKeysSchema,\n });\n }\n\n async logout(): Promise<void> {\n if (!this.getSession()) return;\n try {\n await this.request<null>('/auth/logout', { method: 'POST', authenticated: true });\n } catch (error) {\n if (error instanceof HeadlessCustomerError && error.status === 401) {\n // The server already considers the credential invalid. request() also\n // clears it, so logout is complete from the buyer's perspective.\n return;\n }\n // Keep the local token after a transient failure so the caller can retry\n // server-side revocation instead of leaving an unreachable live session.\n throw error;\n }\n this.clearSession();\n }\n}\n\nexport function createCustomerClient(config: HeadlessCustomerClientConfig): HeadlessCustomerClient {\n return new HeadlessCustomerClient(config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA0CA,IAAM,uBAAuB,iBAAE,OAAO,EAAE,SAAS;AAE1C,IAAM,yBAAyB,iBAAE,OAAO;AAAA,EAC7C,UAAU,iBAAE,OAAO;AAAA,IACjB,IAAI;AAAA,IACJ,OAAO,iBAAE,OAAO;AAAA,IAChB,MAAM,i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,IACV,CAAC;AAAA,EACH;AAAA,EAEA,eACE,UAA+C,CAAC,GACP;AACzC,WAAO,KAAK,QAAQ,oBAAoB;AAAA,MACtC,eAAe;AAAA,MACf,OAAO;AAAA,QACL,MAAM,QAAQ,SAAS,SAAY,SAAY,OAAO,QAAQ,IAAI;AAAA,QAClE,UAAU,QAAQ,YAAY,SAAY,SAAY,OAAO,QAAQ,OAAO;AAAA,MAC9E;AAAA,MACA,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AAAA,EAEA,cAAc,SAAyD;AACrE,WAAO,KAAK,QAAQ,oBAAoB,mBAAmB,OAAO,CAAC,IAAI;AAAA,MACrE,eAAe;AAAA,MACf,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AAAA,EAEA,iBAA0D;AACxD,WAAO,KAAK,QAAQ,oBAAoB;AAAA,MACtC,eAAe;AAAA,MACf,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AAAA,EAEA,kBAA4D;AAC1D,WAAO,KAAK,QAAQ,sBAAsB;AAAA,MACxC,eAAe;AAAA,MACf,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,SAAwB;AAC5B,QAAI,CAAC,KAAK,WAAW,EAAG;AACxB,QAAI;AACF,YAAM,KAAK,QAAc,gBAAgB,EAAE,QAAQ,QAAQ,eAAe,KAAK,CAAC;AAAA,IAClF,SAAS,OAAO;AACd,UAAI,iBAAiB,yBAAyB,MAAM,WAAW,KAAK;AAGlE;AAAA,MACF;AAGA,YAAM;AAAA,IACR;AACA,SAAK,aAAa;AAAA,EACpB;AACF;AAEO,SAAS,qBAAqB,QAA8D;AACjG,SAAO,IAAI,uBAAuB,MAAM;AAC1C;","names":["stored"]}
1
+ {"version":3,"sources":["../../contracts/src/customer-portal-wire.ts","../../sdk/src/headless-customer.ts"],"sourcesContent":["import { z } from 'zod';\nimport { customerPortalBrandingSchema } from './customer-account-wire.js';\n\n// The buyer account wire the storefront SDK validates lives in\n// ./customer-account-wire so storefront bundles do not ship the portal-only\n// schemas below. This module re-exports it: portal consumers keep one import.\nexport {\n customerLoyaltyRedeemSchema,\n customerLoyaltySchema,\n customerPortalAffiliateCreateLinkSchema,\n customerPortalAffiliateSummarySchema,\n customerPortalDashboardInvoiceSchema,\n customerPortalDashboardSchema,\n customerPortalInvoiceDetailSchema,\n customerPortalNotificationPreferencesSchema,\n customerPortalOrderReviewSchema,\n customerPortalPaginatedInvoiceSchema,\n customerPortalPaginatedInvoicesSchema,\n customerPortalRewardActivityItemSchema,\n customerPortalRewardsSchema,\n customerPortalSubscriptionSummarySchema,\n customerWarrantyClaimSchema,\n customerWarrantyListSchema,\n} from './customer-account-wire.js';\nexport type {\n CustomerLoyaltyRedeemWire,\n CustomerLoyaltyWire,\n CustomerPortalAffiliateCreateLinkWire,\n CustomerPortalAffiliateSummaryWire,\n CustomerPortalDashboardWire,\n CustomerPortalInvoiceDetailWire,\n CustomerPortalInvoiceShippingWire,\n CustomerPortalNotificationPreferencesWire,\n CustomerPortalOrderReviewWire,\n CustomerPortalPaginatedInvoicesWire,\n CustomerPortalRewardActivityItemWire,\n CustomerPortalRewardsWire,\n CustomerPortalSubscriptionSummaryWire,\n CustomerWarrantyClaimWire,\n CustomerWarrantyListWire,\n} from './customer-account-wire.js';\n\nconst nullableStringSchema = z.string().nullable();\n\nexport const customerPortalMeSchema = z.object({\n customer: z.object({\n id: nullableStringSchema,\n email: z.string(),\n name: z.string(),\n avatar_url: nullableStringSchema,\n joined_at: nullableStringSchema,\n }),\n shop: z.object({\n id: z.string(),\n slug: z.string(),\n name: z.string(),\n currency: z.string(),\n branding: customerPortalBrandingSchema,\n }),\n token: z.null(),\n});\n\nexport const customerPortalWalletTopupQuoteSchema = z.object({\n quote: z.object({\n enabled: z.boolean(),\n currency: z.string(),\n min_amount: z.string(),\n max_amount: nullableStringSchema,\n bonus_tiers: z.array(z.object({\n min_amount: z.string(),\n bonus_percent: z.number(),\n })),\n }),\n});\n\nexport const customerPortalWalletTopupResultSchema = z.object({\n invoice_id: z.string(),\n url: z.string(),\n});\n\nexport const customerPortalAffiliateStatsSchema = z.object({\n window_days: z.number(),\n totals: z.object({\n clicks: z.number(),\n add_to_carts: z.number(),\n checkouts_started: z.number(),\n sales: z.number(),\n }),\n per_link: z.array(z.object({\n link_id: z.string(),\n code: z.string(),\n label: nullableStringSchema,\n clicks: z.number(),\n add_to_carts: z.number(),\n checkouts_started: z.number(),\n })),\n daily: z.array(z.object({\n date: z.string(),\n clicks: z.number(),\n add_to_carts: z.number(),\n checkouts_started: z.number(),\n })),\n});\n\n// ---------------------------------------------------------------------------\n// Headless customer-portal action contracts\n// ---------------------------------------------------------------------------\n\nexport const customerPortalProfileUpdateSchema = z.object({\n customer: z.object({\n id: z.string(),\n email: z.string(),\n name: z.string(),\n joined_at: nullableStringSchema,\n }),\n});\n\nexport const customerPortalAvatarSchema = z.object({\n avatar_url: nullableStringSchema,\n});\n\nexport const customerPortalEmailPreferencesSchema = z.object({\n global_unsubscribed: z.boolean(),\n lists: z.array(z.object({\n id: z.string(),\n name: z.string(),\n description: nullableStringSchema,\n subscribed: z.boolean(),\n })),\n});\n\nexport const customerPortalEmailPreferencesUpdateSchema = z.object({\n updated: z.boolean(),\n});\n\nexport const customerPortalFavoritesSchema = z.object({\n favorites: z.array(z.object({\n product_uniqid: z.string(),\n title: z.string(),\n slug: nullableStringSchema,\n image_url: nullableStringSchema,\n price_display: z.number(),\n unavailable: z.boolean(),\n created_at: z.string(),\n })),\n});\n\nexport const customerPortalFavoriteMutationSchema = z.union([\n z.object({ added: z.literal(true) }),\n z.object({ removed: z.literal(true) }),\n]);\n\nexport const customerPortalLicenseResetSchema = z.object({\n license: z.object({\n uniqid: z.string(),\n hardware_id: nullableStringSchema,\n }),\n});\n\nexport const customerPortalLicenseRenewalSchema = z.object({\n invoice_id: z.string(),\n checkout_url: z.string(),\n preferred_gateways: z.array(z.string()),\n license: z.object({\n uniqid: z.string(),\n product_title: z.string(),\n }),\n});\n\nexport const customerPortalSubscriptionBillingHistorySchema = z.object({\n invoices: z.array(z.object({\n id: z.string(),\n uniqid: z.string(),\n total: z.string(),\n currency: z.string(),\n status: z.string(),\n gateway: z.string(),\n created_at: z.string(),\n completed_at: z.string(),\n // What the invoice billed, and the plan change it paid for\n // (SubscriptionService.getBillingHistory, BillingHistoryPlanChangeSchema).\n kind: z.enum(['first_order', 'renewal', 'plan_change']),\n plan_change: z.object({\n from_plan_name: z.string(),\n to_plan_name: z.string(),\n source: z.enum(['buyer', 'merchant']),\n days_left: z.number().nullable(),\n days_total: z.number().nullable(),\n }).nullable(),\n })),\n});\n\nexport const customerPortalSubscriptionCancelSchema = z.object({\n subscription: z.object({\n id: z.string(),\n status: z.string(),\n cancel_at_period_end: z.boolean(),\n cancel_reason: nullableStringSchema,\n canceled_at: nullableStringSchema,\n }),\n});\n\nexport const customerPortalSubscriptionStatusSchema = z.object({\n subscription: z.object({\n id: z.string(),\n status: z.string(),\n }),\n});\n\nexport const customerPortalSupportTicketDetailSchema = z.object({\n ticket: z.object({\n uniqid: z.string(),\n title: z.string(),\n status: z.string(),\n invoice_id: nullableStringSchema,\n created_at: z.string(),\n updated_at: z.string(),\n messages: z.array(z.object({\n id: z.string(),\n role: z.enum(['CUSTOMER', 'SHOP', 'SYSTEM']),\n message: z.string(),\n created_at: z.string(),\n })),\n }),\n});\n\nexport const customerPortalSupportCreateSchema = z.object({\n uniqid: z.string(),\n});\n\nconst customerResellerTierSchema = z.object({\n id: z.string(),\n name: nullableStringSchema,\n discount_percent: z.number().nullable(),\n});\n\nconst customerResellerRelationshipSchema = z.object({\n id: z.string(),\n status: z.enum(['INVITED', 'APPLIED', 'ACTIVE', 'SUSPENDED', 'REJECTED']),\n tier: customerResellerTierSchema.nullable(),\n application_note: nullableStringSchema,\n lifetime_revenue: z.string(),\n lifetime_orders: z.number(),\n approved_at: nullableStringSchema,\n created_at: z.string(),\n});\n\nexport const customerResellerSummarySchema = z.object({\n program_enabled: z.boolean(),\n api_enabled: z.boolean(),\n portal_purchasing_enabled: z.boolean(),\n enrollment_mode: z.enum(['MANUAL', 'APPLICATION', 'OPEN']),\n application_message: nullableStringSchema,\n require_application_note: z.boolean(),\n reseller: customerResellerRelationshipSchema.nullable(),\n});\n\nexport const customerResellerEnrollmentSchema = z.object({\n reseller: customerResellerRelationshipSchema,\n});\n\nconst customerResellerAppliedOverrideSchema = z.enum(['variant', 'product', 'tier']);\n\nconst customerResellerCatalogVariantSchema = z.object({\n variant_id: z.string(),\n title: z.string(),\n stock: z.number(),\n orderable: z.boolean(),\n base_price: z.string(),\n unit_price: z.string(),\n discount_percent: z.number(),\n applied_override: customerResellerAppliedOverrideSchema,\n});\n\n/**\n * A product custom field a wholesale order line answers in `items[].custom_fields`,\n * keyed by `name`. `format` is the check the server applies when there is no `regex`.\n */\nexport const customerResellerCustomFieldSchema = z.object({\n name: z.string(),\n type: z.string(),\n required: z.boolean(),\n placeholder: z.string(),\n default_value: z.string(),\n regex: nullableStringSchema,\n min_length: z.number().nullable(),\n format: z.enum(['number', 'discord_invite', 'url']).nullable(),\n /** Only on a `select`: the answer must be one of these labels. */\n options: z.array(z.string()).optional(),\n});\n\nexport const customerResellerCatalogSchema = z.object({\n tier: customerResellerTierSchema,\n catalog: z.object({\n currency: z.string(),\n total: z.number(),\n page: z.number(),\n per_page: z.number(),\n items: z.array(z.object({\n product_id: z.string(),\n uniqid: z.string(),\n title: z.string(),\n type: z.string(),\n stock: z.number(),\n orderable: z.boolean(),\n volume_discount_enabled: z.boolean(),\n base_price: z.string(),\n unit_price: z.string(),\n discount_percent: z.number(),\n applied_override: customerResellerAppliedOverrideSchema,\n /** Optional: a backend released before reseller custom fields does not send it. */\n custom_fields: z.array(customerResellerCustomFieldSchema).optional(),\n variants: z.array(customerResellerCatalogVariantSchema),\n })),\n }),\n});\n\nexport const customerResellerQuoteSchema = z.object({\n quote: z.object({\n currency: z.string(),\n tier: customerResellerTierSchema,\n items: z.array(z.object({\n product_id: z.string(),\n product_title: z.string(),\n product_type: z.string(),\n variant_id: nullableStringSchema,\n variant_title: nullableStringSchema,\n quantity: z.number(),\n base_price: z.string(),\n discount_percent: z.number(),\n unit_price: z.string(),\n line_total: z.string(),\n applied_override: customerResellerAppliedOverrideSchema,\n volume_discount_applied: z.string(),\n })),\n subtotal: z.string(),\n volume_discount_total: z.string(),\n total: z.string(),\n savings: z.string(),\n }),\n});\n\nexport const customerResellerOrdersSchema = z.object({\n orders: z.object({\n total: z.number(),\n page: z.number(),\n per_page: z.number(),\n items: z.array(z.object({\n uniqid: z.string(),\n status: z.string(),\n currency: z.string(),\n total: z.string(),\n item_count: z.number(),\n created_at: z.string(),\n })),\n }),\n});\n\nexport const customerResellerOrderSchema = z.object({\n order: z.object({\n uniqid: z.string(),\n status: z.string(),\n currency: z.string(),\n total: z.string(),\n item_count: z.number(),\n created_at: z.string(),\n tier_name: z.string(),\n tier_discount_percent: z.number(),\n partially_delivered: z.boolean(),\n refunded_amount: nullableStringSchema,\n lines: z.array(z.object({\n product_id: nullableStringSchema,\n product_title: z.string(),\n variant_id: nullableStringSchema,\n variant_title: nullableStringSchema,\n quantity: z.number(),\n unit_price: z.string(),\n total: z.string(),\n delivered: z.boolean(),\n delivered_at: nullableStringSchema,\n serials: z.array(z.string()),\n })),\n }),\n});\n\nexport const customerResellerWalletSchema = z.object({\n wallet: z.object({\n currency: z.string(),\n balance: z.string(),\n hold_balance: z.string(),\n available: z.string(),\n is_active: z.boolean(),\n }),\n});\n\nexport const customerResellerApiKeysSchema = z.object({\n api_keys: z.array(z.object({\n id: z.string(),\n name: z.string(),\n key_last4: z.string(),\n last_used_at: nullableStringSchema,\n revoked_at: nullableStringSchema,\n created_at: z.string(),\n })),\n});\n\nexport const customerResellerTopupSchema = z.object({\n topup: z.object({\n uniqid: z.string(),\n url: z.string(),\n }),\n});\n\nexport type CustomerPortalMeWire = z.infer<typeof customerPortalMeSchema>;\nexport type CustomerPortalAffiliateStatsWire = z.infer<typeof customerPortalAffiliateStatsSchema>;\nexport type CustomerPortalWalletTopupQuoteWire = z.infer<typeof customerPortalWalletTopupQuoteSchema>;\nexport type CustomerPortalWalletTopupResultWire = z.infer<typeof customerPortalWalletTopupResultSchema>;\nexport type CustomerPortalProfileUpdateWire = z.infer<typeof customerPortalProfileUpdateSchema>;\nexport type CustomerPortalAvatarWire = z.infer<typeof customerPortalAvatarSchema>;\nexport type CustomerPortalEmailPreferencesWire = z.infer<typeof customerPortalEmailPreferencesSchema>;\nexport type CustomerPortalEmailPreferencesUpdateWire = z.infer<typeof customerPortalEmailPreferencesUpdateSchema>;\nexport type CustomerPortalFavoritesWire = z.infer<typeof customerPortalFavoritesSchema>;\nexport type CustomerPortalFavoriteMutationWire = z.infer<typeof customerPortalFavoriteMutationSchema>;\nexport type CustomerPortalLicenseResetWire = z.infer<typeof customerPortalLicenseResetSchema>;\nexport type CustomerPortalLicenseRenewalWire = z.infer<typeof customerPortalLicenseRenewalSchema>;\nexport type CustomerPortalSubscriptionBillingHistoryWire = z.infer<typeof customerPortalSubscriptionBillingHistorySchema>;\nexport type CustomerPortalSubscriptionCancelWire = z.infer<typeof customerPortalSubscriptionCancelSchema>;\nexport type CustomerPortalSubscriptionStatusWire = z.infer<typeof customerPortalSubscriptionStatusSchema>;\nexport type CustomerPortalSupportTicketDetailWire = z.infer<typeof customerPortalSupportTicketDetailSchema>;\nexport type CustomerPortalSupportCreateWire = z.infer<typeof customerPortalSupportCreateSchema>;\nexport type CustomerResellerSummaryWire = z.infer<typeof customerResellerSummarySchema>;\nexport type CustomerResellerEnrollmentWire = z.infer<typeof customerResellerEnrollmentSchema>;\nexport type CustomerResellerCatalogWire = z.infer<typeof customerResellerCatalogSchema>;\nexport type CustomerResellerQuoteWire = z.infer<typeof customerResellerQuoteSchema>;\nexport type CustomerResellerOrdersWire = z.infer<typeof customerResellerOrdersSchema>;\nexport type CustomerResellerOrderWire = z.infer<typeof customerResellerOrderSchema>;\nexport type CustomerResellerWalletWire = z.infer<typeof customerResellerWalletSchema>;\nexport type CustomerResellerApiKeysWire = z.infer<typeof customerResellerApiKeysSchema>;\nexport type CustomerResellerTopupWire = z.infer<typeof customerResellerTopupSchema>;\n","/**\n * Browser client for a customer account hosted outside Shoppex.\n *\n * The publishable key identifies the merchant and the dashboard origin\n * allowlist authorizes the browser origin. OTP verification returns a separate\n * short-lived `hcs_` token; the SDK never exposes Shoppex's BetterAuth token.\n */\nimport {\n customerLoyaltyRedeemSchema,\n customerLoyaltySchema,\n customerPortalAffiliateSummarySchema,\n customerPortalAffiliateStatsSchema,\n customerPortalAffiliateCreateLinkSchema,\n customerPortalAvatarSchema,\n customerPortalDashboardSchema,\n customerPortalEmailPreferencesSchema,\n customerPortalEmailPreferencesUpdateSchema,\n customerPortalFavoriteMutationSchema,\n customerPortalFavoritesSchema,\n customerPortalInvoiceDetailSchema,\n customerPortalLicenseResetSchema,\n customerPortalLicenseRenewalSchema,\n customerPortalMeSchema,\n customerPortalNotificationPreferencesSchema,\n customerPortalOrderReviewSchema,\n customerPortalPaginatedInvoicesSchema,\n customerPortalProfileUpdateSchema,\n customerPortalSubscriptionBillingHistorySchema,\n customerPortalSubscriptionCancelSchema,\n customerPortalSubscriptionStatusSchema,\n customerPortalSupportCreateSchema,\n customerPortalSupportTicketDetailSchema,\n customerResellerApiKeysSchema,\n customerResellerCatalogSchema,\n customerResellerEnrollmentSchema,\n customerResellerOrderSchema,\n customerResellerOrdersSchema,\n customerResellerQuoteSchema,\n customerResellerSummarySchema,\n customerResellerWalletSchema,\n customerWarrantyClaimSchema,\n customerWarrantyListSchema,\n type CustomerLoyaltyRedeemWire,\n type CustomerLoyaltyWire,\n type CustomerPortalAffiliateSummaryWire,\n type CustomerPortalAffiliateStatsWire,\n type CustomerPortalAffiliateCreateLinkWire,\n type CustomerPortalAvatarWire,\n type CustomerPortalDashboardWire,\n type CustomerPortalEmailPreferencesUpdateWire,\n type CustomerPortalEmailPreferencesWire,\n type CustomerPortalFavoriteMutationWire,\n type CustomerPortalFavoritesWire,\n type CustomerPortalLicenseResetWire,\n type CustomerPortalLicenseRenewalWire,\n type CustomerPortalNotificationPreferencesWire,\n type CustomerPortalOrderReviewWire,\n type CustomerPortalProfileUpdateWire,\n type CustomerPortalSubscriptionBillingHistoryWire,\n type CustomerPortalSubscriptionCancelWire,\n type CustomerPortalSubscriptionStatusWire,\n type CustomerPortalSupportCreateWire,\n type CustomerPortalSupportTicketDetailWire,\n type CustomerResellerApiKeysWire,\n type CustomerResellerCatalogWire,\n type CustomerResellerEnrollmentWire,\n type CustomerResellerOrderWire,\n type CustomerResellerOrdersWire,\n type CustomerResellerQuoteWire,\n type CustomerResellerSummaryWire,\n type CustomerResellerWalletWire,\n type CustomerWarrantyClaimWire,\n type CustomerWarrantyListWire,\n} from '@shoppex/contracts/customer-portal-wire';\nimport { storefrontStorageKey } from '@shoppex/contracts/storefront-storage-key';\n\nconst DEFAULT_API_ORIGIN = 'https://api.shoppex.io';\nconst SESSION_STORAGE_PREFIX = 'shoppex_headless_customer_session:';\n\ninterface CustomerPayloadSchema<T> {\n safeParse(value: unknown): { success: true; data: T } | { success: false };\n}\n\ninterface ApiEnvelope<T> {\n status: number;\n data: T | null;\n error: string | null;\n message?: string | null;\n error_code?: string | null;\n}\n\ninterface StoredSession {\n accessToken: string;\n expiresAt: string;\n savedAt: number;\n}\n\nexport interface HeadlessCustomerClientConfig {\n /** Shop slug or Shoppex storefront domain. */\n shop: string;\n /** Existing Headless Checkout publishable key (`pk_live_` / `pk_test_`). */\n publishableKey: string;\n /** API origin override. Defaults to https://api.shoppex.io. */\n apiBaseUrl?: string;\n /** Optional fetch override for tests or compatible runtimes. */\n fetchImpl?: typeof fetch;\n /** Optional session storage override. Defaults to browser sessionStorage. */\n storage?: Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;\n /** Optional persistent storage override. Defaults to browser localStorage. */\n persistentStorage?: Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;\n}\n\nexport interface HeadlessCustomerSession {\n accessToken: string;\n expiresAt: string;\n}\n\nexport interface HeadlessCustomerVerifyOptions {\n /** Persist the customer session across browser restarts for up to 30 days. */\n rememberMe?: boolean;\n}\n\nexport interface HeadlessCustomerOrdersQuery {\n page?: number;\n limit?: number;\n status?: string;\n search?: string;\n}\n\nexport interface HeadlessCustomerDownload {\n blob: Blob;\n filename: string | null;\n contentType: string | null;\n}\n\ntype HeadlessCustomerDashboardDeliverable =\n CustomerPortalDashboardWire['deliverables'][number] & {\n /** Pass this value with `invoice_uniqid` to `customer.download()`. */\n downloadIndex?: number | null;\n };\n\nexport type HeadlessCustomerDashboard = Omit<CustomerPortalDashboardWire, 'deliverables'> & {\n deliverables: HeadlessCustomerDashboardDeliverable[];\n};\nexport type HeadlessCustomerProfileUpdate = CustomerPortalProfileUpdateWire;\nexport type HeadlessCustomerAvatar = CustomerPortalAvatarWire;\nexport type HeadlessCustomerEmailPreferences = CustomerPortalEmailPreferencesWire;\nexport type HeadlessCustomerEmailPreferencesUpdate = CustomerPortalEmailPreferencesUpdateWire;\nexport type HeadlessCustomerNotificationPreferences = CustomerPortalNotificationPreferencesWire;\n/**\n * `reviewer_name` and `anonymous` come with the backend of #3697, which deploys\n * after this SDK version is on npm (a theme-runtime pin is published before its\n * release PR). Until that deploy the API answers without them, so they are\n * optional here; tighten back to `CustomerPortalOrderReviewWire` once it shipped.\n */\nexport type HeadlessCustomerOrderReview = Omit<CustomerPortalOrderReviewWire, 'reviewer_name' | 'anonymous'>\n & Partial<Pick<CustomerPortalOrderReviewWire, 'reviewer_name' | 'anonymous'>>;\nconst orderReviewSchema = customerPortalOrderReviewSchema.partial({ reviewer_name: true, anonymous: true });\nexport type HeadlessCustomerFavorites = CustomerPortalFavoritesWire;\nexport type HeadlessCustomerFavoriteMutation = CustomerPortalFavoriteMutationWire;\nexport type HeadlessCustomerAffiliate = CustomerPortalAffiliateSummaryWire;\nexport type HeadlessCustomerAffiliateStats = CustomerPortalAffiliateStatsWire;\nexport type HeadlessCustomerAffiliateLink = CustomerPortalAffiliateCreateLinkWire;\nexport type HeadlessCustomerTicket = CustomerPortalSupportTicketDetailWire;\nexport type HeadlessCustomerTicketCreateResult = CustomerPortalSupportCreateWire;\nexport type HeadlessCustomerLicenseReset = CustomerPortalLicenseResetWire;\nexport type HeadlessCustomerLicenseRenewal = CustomerPortalLicenseRenewalWire;\nexport type HeadlessCustomerSubscriptionBillingHistory = CustomerPortalSubscriptionBillingHistoryWire;\nexport type HeadlessCustomerSubscriptionCancel = CustomerPortalSubscriptionCancelWire;\nexport type HeadlessCustomerSubscriptionStatus = CustomerPortalSubscriptionStatusWire;\nexport type HeadlessCustomerLoyalty = CustomerLoyaltyWire;\nexport type HeadlessCustomerLoyaltyRedeem = CustomerLoyaltyRedeemWire;\nexport type HeadlessCustomerWarranties = CustomerWarrantyListWire;\nexport type HeadlessCustomerWarrantyClaim = CustomerWarrantyClaimWire;\nexport type HeadlessCustomerReseller = CustomerResellerSummaryWire;\nexport type HeadlessCustomerResellerEnrollment = CustomerResellerEnrollmentWire;\nexport type HeadlessCustomerResellerCatalog = CustomerResellerCatalogWire;\nexport type HeadlessCustomerResellerQuote = CustomerResellerQuoteWire;\nexport type HeadlessCustomerResellerOrders = CustomerResellerOrdersWire;\nexport type HeadlessCustomerResellerOrder = CustomerResellerOrderWire;\nexport type HeadlessCustomerResellerWallet = CustomerResellerWalletWire;\nexport type HeadlessCustomerResellerApiKeys = CustomerResellerApiKeysWire;\n\nexport interface HeadlessCustomerTicketInput {\n title?: string;\n message: string;\n invoiceId?: string;\n}\n\nexport interface HeadlessCustomerOrderReviewInput {\n score: 1 | 3 | 5;\n message: string;\n /**\n * Post without the buyer's name. Omitted = anonymous; pass `false` once the\n * buyer saw `orderReview().reviewer_name` and chose to show it (an API that\n * answers no `reviewer_name` saves the review anonymously either way).\n */\n anonymous?: boolean;\n}\n\nexport interface HeadlessCustomerAffiliateLinkInput {\n code: string;\n label: string;\n requestedRevenuePercent?: number | null;\n requestedCustomerDiscountPercent?: number | null;\n}\n\nexport interface HeadlessCustomerSubscriptionCancelOptions {\n cancelAtPeriodEnd?: boolean;\n reason?: string | null;\n}\n\n/**\n * A buyer pause: one of the dashboard's `pause_options.lengths[].days`, and a reason\n * (`taking_a_break`, `too_expensive`, `not_using`, `not_working`, `other`) when\n * `pause_options.reason_enabled`. Without `lengthDays` the backend pauses for the shop's longest pause.\n */\nexport interface HeadlessCustomerSubscriptionPauseOptions {\n lengthDays?: 7 | 14 | 30 | 60 | 90;\n reason?: 'taking_a_break' | 'too_expensive' | 'not_using' | 'not_working' | 'other' | null;\n}\n\nexport interface HeadlessCustomerEmailPreferencesPatch {\n globalUnsubscribed?: boolean;\n listSubscriptions?: Array<{ listId: string; subscribed: boolean }>;\n}\n\nexport interface HeadlessCustomerNotificationPreferencesPatch {\n orderCreatedEmails?: boolean;\n orderCompletedEmails?: boolean;\n paymentIssueEmails?: boolean;\n}\n\nexport interface HeadlessCustomerResellerCatalogQuery {\n search?: string;\n page?: number;\n perPage?: number;\n}\n\nexport interface HeadlessCustomerResellerOrdersQuery {\n page?: number;\n perPage?: number;\n}\n\nexport interface HeadlessCustomerResellerOrderItem {\n productId: string;\n variantId?: string;\n quantity: number;\n}\n\n/** Public DTOs mirror the producer-owned schemas imported above. Passing each\n * schema into `request<T>` makes TypeScript reject drift in required fields. */\nexport interface HeadlessCustomerMe {\n customer: {\n id: string | null;\n email: string;\n name: string;\n avatar_url: string | null;\n joined_at: string | null;\n };\n shop: {\n id: string;\n slug: string;\n name: string;\n currency: string;\n branding: {\n logo_url: string | null;\n primary_color: string;\n secondary_color: string;\n accent_color: string;\n };\n };\n}\n\ntype HeadlessCustomerMeWire = HeadlessCustomerMe & { token: string | null };\n\nexport interface HeadlessCustomerOrderSummary {\n uniqid: string;\n status: string;\n total: string;\n totalDisplay: string | null;\n currency: string;\n createdAt: string;\n lineItems: Array<{\n productTitle: string | null;\n quantity: number;\n product: {\n attachment_imageId: { cloudflareImageId: string | null } | null;\n } | null;\n }>;\n}\n\nexport interface HeadlessCustomerOrders {\n invoices: HeadlessCustomerOrderSummary[];\n pagination: {\n page: number;\n limit: number;\n total: number;\n has_more: boolean;\n };\n}\n\nexport interface HeadlessCustomerPayment {\n gateway: string;\n displayName: string | null;\n cryptoGateway?: string | null;\n blockchain: string | null;\n cryptoAddress: string | null;\n apmMethod: string | null;\n}\n\nexport interface HeadlessCustomerOrder {\n id: string;\n uniqid: string;\n status: string;\n statusDetails: string | null;\n total: string;\n totalDisplay: string | null;\n subtotal: string;\n discount: string;\n discountDisplay: string | null;\n tax: string;\n taxPercentage: string;\n currency: string;\n createdAt: string;\n updatedAt: string;\n gatewayUpdatedAt: string | null;\n customFields: Record<string, unknown> | null;\n balancePaidAmount: string;\n currentPaymentAttemptId: string | null;\n lineItems: Array<{\n id: string;\n productTitle: string;\n productType: string;\n variantTitle: string | null;\n unitPrice: string;\n quantity: number;\n total: string;\n deliveryText: string | null;\n deliverySummary: {\n codes: string[];\n links: Array<{\n label: string;\n value: string;\n /** External URL for non-Shoppex links. Portal-only download URLs are removed. */\n href?: string | null;\n /** Pass this value to `customer.download(orderId, downloadIndex)`. */\n downloadIndex?: number | null;\n }>;\n notes: string[];\n serials: Array<{ value: string; is_replacement: boolean; is_replaced: boolean }>;\n } | null;\n deliveredAt: string | null;\n deliveryStatus: 'PENDING' | 'AWAITING_FULFILLMENT' | 'DELIVERED' | 'FAILED';\n customFields: Record<string, unknown> | null;\n product: {\n uniqid: string;\n slug: string | null;\n serviceText: string | null;\n attachment_imageId: { cloudflareImageId: string | null } | null;\n } | null;\n }>;\n currentPayment: HeadlessCustomerPayment | null;\n payments: HeadlessCustomerPayment[];\n}\n\n/**\n * `code: 'RESPONSE_CONTRACT_VIOLATION'` (status 2xx) on `redeemLoyaltyPoints`\n * means the server completed the call and withheld its answer. Re-read the\n * account (`loyalty()`) and show that; do not report a failure or call again.\n */\nexport class HeadlessCustomerError extends Error {\n constructor(\n public readonly status: number,\n message: string,\n public readonly code?: string | null,\n ) {\n super(message);\n this.name = 'HeadlessCustomerError';\n }\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction parseStoredSession(value: string | null): StoredSession | null {\n if (!value) return null;\n try {\n const parsed: unknown = JSON.parse(value);\n if (\n !isRecord(parsed)\n || typeof parsed.accessToken !== 'string'\n || !parsed.accessToken.startsWith('hcs_')\n || typeof parsed.expiresAt !== 'string'\n || typeof parsed.savedAt !== 'number'\n || !Number.isFinite(parsed.savedAt)\n ) {\n return null;\n }\n const expiresAtMs = Date.parse(parsed.expiresAt);\n if (!Number.isFinite(expiresAtMs) || expiresAtMs <= Date.now()) return null;\n return { accessToken: parsed.accessToken, expiresAt: parsed.expiresAt, savedAt: parsed.savedAt };\n } catch {\n return null;\n }\n}\n\nfunction readFilename(header: string | null): string | null {\n if (!header) return null;\n const utf8Match = header.match(/filename\\*=UTF-8''([^;]+)/i);\n if (utf8Match?.[1]) {\n try {\n return decodeURIComponent(utf8Match[1]);\n } catch {\n return utf8Match[1];\n }\n }\n return header.match(/filename=\"([^\"]+)\"/i)?.[1] ?? null;\n}\n\nfunction readPortalDownloadIndex(href: string | null | undefined): number | null {\n // Only relative URLs are owned by the Shoppex customer portal. An external\n // site may legitimately use the same pathname and must remain an external link.\n if (!href?.startsWith('/api/customer/')) return null;\n try {\n const url = new URL(href, 'https://headless-customer.invalid');\n if (!/^\\/api\\/customer\\/invoice\\/[^/]+\\/download$/.test(url.pathname)) return null;\n const rawIndex = url.searchParams.get('file_index');\n if (rawIndex === null || !/^\\d+$/.test(rawIndex)) return null;\n const index = Number(rawIndex);\n return Number.isSafeInteger(index) ? index : null;\n } catch {\n return null;\n }\n}\n\nfunction readBrowserStorage(name: 'sessionStorage' | 'localStorage'):\n Pick<Storage, 'getItem' | 'setItem' | 'removeItem'> | null {\n try {\n return typeof window === 'undefined' ? null : window[name];\n } catch {\n return null;\n }\n}\n\nexport class HeadlessCustomerClient {\n private readonly base: string;\n private readonly shop: string;\n private readonly publishableKey: string;\n private readonly fetchImpl: typeof fetch;\n private readonly storage: Pick<Storage, 'getItem' | 'setItem' | 'removeItem'> | null;\n private readonly persistentStorage: Pick<Storage, 'getItem' | 'setItem' | 'removeItem'> | null;\n private readonly storageKey: string;\n private memorySession: StoredSession | null = null;\n\n constructor(config: HeadlessCustomerClientConfig) {\n if (!config.shop.trim()) throw new Error('HeadlessCustomerClient requires a shop.');\n if (!config.publishableKey.trim()) {\n throw new Error('HeadlessCustomerClient requires a publishableKey.');\n }\n this.shop = config.shop.trim();\n this.publishableKey = config.publishableKey.trim();\n this.base = (config.apiBaseUrl ?? DEFAULT_API_ORIGIN).replace(/\\/+$/, '');\n this.fetchImpl = config.fetchImpl ?? globalThis.fetch?.bind(globalThis);\n if (!this.fetchImpl) throw new Error('No fetch implementation available; pass fetchImpl.');\n this.storage = config.storage ?? readBrowserStorage('sessionStorage');\n this.persistentStorage = config.persistentStorage ?? readBrowserStorage('localStorage');\n this.storageKey = `${SESSION_STORAGE_PREFIX}${this.shop}`;\n }\n\n getSession(): HeadlessCustomerSession | null {\n const candidates: StoredSession[] = this.memorySession ? [this.memorySession] : [];\n if (this.storage) {\n try {\n const stored = parseStoredSession(this.storage.getItem(storefrontStorageKey(this.storageKey)));\n if (stored) candidates.push(stored);\n } catch {\n // Continue with memory and persistent storage.\n }\n }\n if (this.persistentStorage) {\n try {\n const stored = parseStoredSession(this.persistentStorage.getItem(storefrontStorageKey(this.storageKey)));\n if (stored) candidates.push(stored);\n } catch {\n // Continue with the other available stores.\n }\n }\n\n const stored = candidates.sort((left, right) => right.savedAt - left.savedAt)[0] ?? null;\n\n if (!stored) {\n this.clearSession();\n return null;\n }\n this.memorySession = stored;\n return { accessToken: stored.accessToken, expiresAt: stored.expiresAt };\n }\n\n clearSession(): void {\n this.memorySession = null;\n try {\n this.storage?.removeItem(storefrontStorageKey(this.storageKey));\n } catch {\n // Privacy-restricted browsers may reject storage access. Memory is still cleared.\n }\n try {\n this.persistentStorage?.removeItem(storefrontStorageKey(this.storageKey));\n } catch {\n // The two stores are cleared independently so one rejected access cannot block the other.\n }\n }\n\n private saveSession(session: HeadlessCustomerSession, rememberMe: boolean): void {\n const storedSession: StoredSession = { ...session, savedAt: Date.now() };\n this.memorySession = storedSession;\n const target = rememberMe ? this.persistentStorage : this.storage;\n const other = rememberMe ? this.storage : this.persistentStorage;\n try {\n target?.setItem(storefrontStorageKey(this.storageKey), JSON.stringify(storedSession));\n } catch {\n // Keep the session for this client instance when browser storage is unavailable.\n }\n try {\n other?.removeItem(storefrontStorageKey(this.storageKey));\n } catch {\n // A stale session in the other storage cannot override the in-memory session.\n }\n }\n\n private url(path: string, query: Record<string, string | undefined> = {}): string {\n const url = new URL(`${this.base}/v1/customer${path}`);\n url.searchParams.set('shop', this.shop);\n for (const [key, value] of Object.entries(query)) {\n if (value !== undefined && value !== '') url.searchParams.set(key, value);\n }\n return url.toString();\n }\n\n private async request<T>(\n path: string,\n options: {\n method?: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';\n body?: unknown;\n formData?: FormData;\n authenticated?: boolean;\n schema?: CustomerPayloadSchema<T>;\n query?: Record<string, string | undefined>;\n } = {},\n ): Promise<T> {\n if (options.body !== undefined && options.formData !== undefined) {\n throw new Error('Customer requests cannot send JSON and FormData together.');\n }\n const session = options.authenticated ? this.getSession() : null;\n if (options.authenticated && !session) {\n throw new HeadlessCustomerError(401, 'Customer session is missing or expired.', 'UNAUTHORIZED');\n }\n\n const headers: Record<string, string> = {\n accept: 'application/json',\n 'x-shoppex-publishable-key': this.publishableKey,\n ...(options.body === undefined ? {} : { 'content-type': 'application/json' }),\n ...(session ? { authorization: `Bearer ${session.accessToken}` } : {}),\n };\n const requestBody = options.formData ?? (\n options.body === undefined ? undefined : JSON.stringify(options.body)\n );\n const response = await this.fetchImpl(this.url(path, options.query), {\n method: options.method ?? 'GET',\n headers,\n ...(requestBody === undefined ? {} : { body: requestBody }),\n cache: 'no-store',\n });\n\n let envelope: ApiEnvelope<unknown> | null = null;\n try {\n envelope = await response.json() as ApiEnvelope<unknown>;\n } catch {\n // Report a stable transport error below.\n }\n if (!response.ok || !envelope || envelope.error) {\n if (response.status === 401 && options.authenticated) this.clearSession();\n throw new HeadlessCustomerError(\n response.status,\n envelope?.error ?? `Request failed (${response.status})`,\n envelope?.error_code ?? null,\n );\n }\n\n if (!options.schema) return envelope.data as T;\n const parsed = options.schema.safeParse(envelope.data);\n if (!parsed.success) {\n throw new HeadlessCustomerError(response.status, 'Customer API response did not match the expected contract.');\n }\n return parsed.data;\n }\n\n private async requestFile(\n path: string,\n query: Record<string, string | undefined> = {},\n options: { rejectHtml?: boolean } = {},\n ): Promise<HeadlessCustomerDownload> {\n const session = this.getSession();\n if (!session) {\n throw new HeadlessCustomerError(401, 'Customer session is missing or expired.', 'UNAUTHORIZED');\n }\n\n const response = await this.fetchImpl(this.url(path, query), {\n method: 'GET',\n headers: {\n 'x-shoppex-publishable-key': this.publishableKey,\n authorization: `Bearer ${session.accessToken}`,\n },\n cache: 'no-store',\n });\n if (!response.ok) {\n if (response.status === 401) this.clearSession();\n let message = `Download failed (${response.status})`;\n try {\n const body = await response.json() as ApiEnvelope<unknown>;\n if (body.error) message = body.error;\n } catch {\n // Keep the stable status-based error.\n }\n throw new HeadlessCustomerError(response.status, message);\n }\n\n const contentType = response.headers.get('content-type');\n if (options.rejectHtml && contentType?.toLowerCase().startsWith('text/html')) {\n throw new HeadlessCustomerError(\n 502,\n 'Shoppex returned an unsafe aggregate download response.',\n 'UNSAFE_DOWNLOAD_RESPONSE',\n );\n }\n\n return {\n blob: await response.blob(),\n filename: readFilename(response.headers.get('content-disposition')),\n contentType,\n };\n }\n\n requestOtp(email: string): Promise<{ requested: boolean }> {\n return this.request('/auth/otp/request', {\n method: 'POST',\n body: { shop: this.shop, email },\n });\n }\n\n async verifyOtp(\n email: string,\n otp: string,\n options: HeadlessCustomerVerifyOptions = {},\n ): Promise<HeadlessCustomerSession> {\n const data = await this.request<{ access_token: string; expires_at: string }>('/auth/otp/verify', {\n method: 'POST',\n body: { shop: this.shop, email, otp, remember_me: options.rememberMe ?? false },\n });\n const expiresAtMs = typeof data?.expires_at === 'string' ? Date.parse(data.expires_at) : Number.NaN;\n if (\n typeof data?.access_token !== 'string'\n || !data.access_token.startsWith('hcs_')\n || typeof data.expires_at !== 'string'\n || !Number.isFinite(expiresAtMs)\n || expiresAtMs <= Date.now()\n ) {\n throw new HeadlessCustomerError(200, 'Customer API response did not match the expected contract.');\n }\n const session = { accessToken: data.access_token, expiresAt: data.expires_at };\n this.saveSession(session, options.rememberMe ?? false);\n return session;\n }\n\n async me(): Promise<HeadlessCustomerMe> {\n const data = await this.request<HeadlessCustomerMeWire>('/me', {\n authenticated: true,\n schema: customerPortalMeSchema,\n });\n if (data.token !== null) {\n // A raw BetterAuth token here would bypass the external route allowlist.\n // Reject the response instead of handing that credential to merchant JS.\n throw new HeadlessCustomerError(200, 'Customer API response did not match the expected contract.');\n }\n return { customer: data.customer, shop: data.shop };\n }\n\n async dashboard(): Promise<HeadlessCustomerDashboard> {\n const dashboard = await this.request<CustomerPortalDashboardWire>('/dashboard', {\n authenticated: true,\n schema: customerPortalDashboardSchema,\n });\n return {\n ...dashboard,\n deliverables: dashboard.deliverables.map((deliverable) => {\n const downloadIndex = readPortalDownloadIndex(deliverable.href);\n return downloadIndex === null\n ? deliverable\n : { ...deliverable, href: null, downloadIndex };\n }),\n };\n }\n\n updateProfile(input: { name: string }): Promise<HeadlessCustomerProfileUpdate> {\n return this.request('/profile', {\n method: 'POST',\n authenticated: true,\n body: { name: input.name },\n schema: customerPortalProfileUpdateSchema,\n });\n }\n\n updateAvatar(file: File): Promise<HeadlessCustomerAvatar> {\n const formData = new FormData();\n formData.append('file', file);\n return this.request('/profile/avatar', {\n method: 'POST',\n authenticated: true,\n formData,\n schema: customerPortalAvatarSchema,\n });\n }\n\n removeAvatar(): Promise<HeadlessCustomerAvatar> {\n return this.request('/profile/avatar', {\n method: 'DELETE',\n authenticated: true,\n schema: customerPortalAvatarSchema,\n });\n }\n\n emailPreferences(): Promise<HeadlessCustomerEmailPreferences> {\n return this.request('/email-marketing/preferences', {\n authenticated: true,\n schema: customerPortalEmailPreferencesSchema,\n });\n }\n\n updateEmailPreferences(\n patch: HeadlessCustomerEmailPreferencesPatch,\n ): Promise<HeadlessCustomerEmailPreferencesUpdate> {\n return this.request('/email-marketing/preferences', {\n method: 'PATCH',\n authenticated: true,\n body: {\n ...(patch.globalUnsubscribed === undefined\n ? {}\n : { global_unsubscribed: patch.globalUnsubscribed }),\n list_subscriptions: (patch.listSubscriptions ?? []).map((item) => ({\n list_id: item.listId,\n subscribed: item.subscribed,\n })),\n },\n schema: customerPortalEmailPreferencesUpdateSchema,\n });\n }\n\n notificationPreferences(): Promise<HeadlessCustomerNotificationPreferences> {\n return this.request('/notification-preferences', {\n authenticated: true,\n schema: customerPortalNotificationPreferencesSchema,\n });\n }\n\n updateNotificationPreferences(\n patch: HeadlessCustomerNotificationPreferencesPatch,\n ): Promise<HeadlessCustomerNotificationPreferences> {\n return this.request('/notification-preferences', {\n method: 'PATCH',\n authenticated: true,\n body: {\n ...(patch.orderCreatedEmails === undefined\n ? {}\n : { order_created_emails: patch.orderCreatedEmails }),\n ...(patch.orderCompletedEmails === undefined\n ? {}\n : { order_completed_emails: patch.orderCompletedEmails }),\n ...(patch.paymentIssueEmails === undefined\n ? {}\n : { payment_issue_emails: patch.paymentIssueEmails }),\n },\n schema: customerPortalNotificationPreferencesSchema,\n });\n }\n\n orders(options: HeadlessCustomerOrdersQuery = {}): Promise<HeadlessCustomerOrders> {\n return this.request<HeadlessCustomerOrders>('/invoices', {\n authenticated: true,\n schema: customerPortalPaginatedInvoicesSchema,\n query: {\n page: options.page === undefined ? undefined : String(options.page),\n limit: options.limit === undefined ? undefined : String(options.limit),\n status: options.status,\n q: options.search,\n },\n });\n }\n\n async order(id: string): Promise<HeadlessCustomerOrder> {\n const order = await this.request<HeadlessCustomerOrder>(`/invoice/${encodeURIComponent(id)}`, {\n authenticated: true,\n schema: customerPortalInvoiceDetailSchema,\n });\n return {\n ...order,\n lineItems: order.lineItems.map((lineItem) => ({\n ...lineItem,\n deliverySummary: lineItem.deliverySummary\n ? {\n ...lineItem.deliverySummary,\n links: lineItem.deliverySummary.links.map((link) => {\n const downloadIndex = readPortalDownloadIndex(link.href);\n return downloadIndex === null\n ? link\n : { ...link, href: null, downloadIndex };\n }),\n }\n : null,\n })),\n };\n }\n\n orderReview(orderId: string): Promise<HeadlessCustomerOrderReview> {\n return this.request(`/invoices/${encodeURIComponent(orderId)}/review`, {\n authenticated: true,\n schema: orderReviewSchema,\n });\n }\n\n submitOrderReview(\n orderId: string,\n input: HeadlessCustomerOrderReviewInput,\n ): Promise<HeadlessCustomerOrderReview> {\n return this.request(`/invoices/${encodeURIComponent(orderId)}/review`, {\n method: 'POST',\n authenticated: true,\n body: {\n score: input.score,\n message: input.message,\n ...(input.anonymous === undefined ? {} : { anonymous: input.anonymous }),\n },\n schema: orderReviewSchema,\n });\n }\n\n invoicePdf(orderId: string): Promise<HeadlessCustomerDownload> {\n return this.requestFile(`/invoices/${encodeURIComponent(orderId)}/pdf`);\n }\n\n async download(orderId: string, fileIndex: number): Promise<HeadlessCustomerDownload> {\n if (!Number.isSafeInteger(fileIndex) || fileIndex < 0) {\n throw new HeadlessCustomerError(\n 400,\n 'download requires a non-negative integer fileIndex from order().deliverySummary.links.',\n 'INVALID_FILE_INDEX',\n );\n }\n return this.requestFile(\n `/invoice/${encodeURIComponent(orderId)}/download`,\n { file_index: String(fileIndex) },\n { rejectHtml: true },\n );\n }\n\n resetLicenseHwid(licenseId: string): Promise<HeadlessCustomerLicenseReset> {\n return this.request(`/licenses/${encodeURIComponent(licenseId)}/reset-hwid`, {\n method: 'POST',\n authenticated: true,\n body: {},\n schema: customerPortalLicenseResetSchema,\n });\n }\n\n renewLicense(licenseId: string): Promise<HeadlessCustomerLicenseRenewal> {\n return this.request(`/licenses/${encodeURIComponent(licenseId)}/renew`, {\n method: 'POST',\n authenticated: true,\n // This established route requires shop in the body. The shared headless\n // gate independently verifies the same shop from the query and key.\n body: { shop: this.shop },\n schema: customerPortalLicenseRenewalSchema,\n });\n }\n\n subscriptionBillingHistory(\n subscriptionId: string,\n ): Promise<HeadlessCustomerSubscriptionBillingHistory> {\n return this.request(`/subscriptions/${encodeURIComponent(subscriptionId)}/billing-history`, {\n authenticated: true,\n schema: customerPortalSubscriptionBillingHistorySchema,\n });\n }\n\n cancelSubscription(\n subscriptionId: string,\n options: HeadlessCustomerSubscriptionCancelOptions = {},\n ): Promise<HeadlessCustomerSubscriptionCancel> {\n return this.request(`/subscriptions/${encodeURIComponent(subscriptionId)}/cancel`, {\n method: 'POST',\n authenticated: true,\n body: {\n ...(options.cancelAtPeriodEnd === undefined\n ? {}\n : { cancel_at_period_end: options.cancelAtPeriodEnd }),\n ...(options.reason === undefined ? {} : { reason: options.reason }),\n },\n schema: customerPortalSubscriptionCancelSchema,\n });\n }\n\n /** Pauses from `pause_options.starts_at`; a scheduled pause is called off with `resumeSubscription`. */\n pauseSubscription(\n subscriptionId: string,\n options: HeadlessCustomerSubscriptionPauseOptions = {},\n ): Promise<HeadlessCustomerSubscriptionStatus> {\n return this.request(`/subscriptions/${encodeURIComponent(subscriptionId)}/pause`, {\n method: 'POST',\n authenticated: true,\n body: {\n ...(options.lengthDays === undefined ? {} : { length_days: options.lengthDays }),\n ...(options.reason === undefined ? {} : { reason: options.reason }),\n },\n schema: customerPortalSubscriptionStatusSchema,\n });\n }\n\n resumeSubscription(subscriptionId: string): Promise<HeadlessCustomerSubscriptionStatus> {\n return this.request(`/subscriptions/${encodeURIComponent(subscriptionId)}/resume`, {\n method: 'POST',\n authenticated: true,\n body: {},\n schema: customerPortalSubscriptionStatusSchema,\n });\n }\n\n /** Takes back a cancellation scheduled for the period end (`actions.can_undo_cancel`). */\n undoSubscriptionCancel(subscriptionId: string): Promise<HeadlessCustomerSubscriptionCancel> {\n return this.request(`/subscriptions/${encodeURIComponent(subscriptionId)}/undo-cancel`, {\n method: 'POST',\n authenticated: true,\n body: {},\n schema: customerPortalSubscriptionCancelSchema,\n });\n }\n\n loyalty(): Promise<HeadlessCustomerLoyalty> {\n return this.request('/loyalty', {\n authenticated: true,\n schema: customerLoyaltySchema,\n });\n }\n\n redeemLoyaltyPoints(input: {\n points: number;\n idempotencyKey: string;\n }): Promise<HeadlessCustomerLoyaltyRedeem> {\n return this.request('/loyalty/redeem', {\n method: 'POST',\n authenticated: true,\n body: { points: input.points, idempotency_key: input.idempotencyKey },\n schema: customerLoyaltyRedeemSchema,\n });\n }\n\n warranties(invoiceId?: string): Promise<HeadlessCustomerWarranties> {\n return this.request('/warranties', {\n authenticated: true,\n query: { invoice: invoiceId },\n schema: customerWarrantyListSchema,\n });\n }\n\n claimWarranty(warrantyId: string, message?: string): Promise<HeadlessCustomerWarrantyClaim> {\n return this.request(`/warranties/${encodeURIComponent(warrantyId)}/claim`, {\n method: 'POST',\n authenticated: true,\n body: message ? { message } : {},\n schema: customerWarrantyClaimSchema,\n });\n }\n\n favorites(): Promise<HeadlessCustomerFavorites> {\n return this.request('/favorites', {\n authenticated: true,\n schema: customerPortalFavoritesSchema,\n });\n }\n\n addFavorite(productId: string): Promise<HeadlessCustomerFavoriteMutation> {\n return this.request(`/favorites/${encodeURIComponent(productId)}`, {\n method: 'PUT',\n authenticated: true,\n schema: customerPortalFavoriteMutationSchema,\n });\n }\n\n removeFavorite(productId: string): Promise<HeadlessCustomerFavoriteMutation> {\n return this.request(`/favorites/${encodeURIComponent(productId)}`, {\n method: 'DELETE',\n authenticated: true,\n schema: customerPortalFavoriteMutationSchema,\n });\n }\n\n affiliate(): Promise<HeadlessCustomerAffiliate> {\n return this.request('/affiliate', {\n authenticated: true,\n schema: customerPortalAffiliateSummarySchema,\n });\n }\n\n affiliateStats(input?: { days?: number }): Promise<HeadlessCustomerAffiliateStats> {\n return this.request('/affiliate/stats', {\n authenticated: true,\n schema: customerPortalAffiliateStatsSchema,\n query: input?.days === undefined ? {} : { days: String(input.days) },\n });\n }\n\n createAffiliateLink(\n input: HeadlessCustomerAffiliateLinkInput,\n ): Promise<HeadlessCustomerAffiliateLink> {\n return this.request('/affiliate/links', {\n method: 'POST',\n authenticated: true,\n body: {\n shop: this.shop,\n code: input.code,\n label: input.label,\n ...(input.requestedRevenuePercent === undefined\n ? {}\n : { requested_affiliate_revenue_percent: input.requestedRevenuePercent }),\n ...(input.requestedCustomerDiscountPercent === undefined\n ? {}\n : { requested_affiliate_customer_discount_percent: input.requestedCustomerDiscountPercent }),\n },\n schema: customerPortalAffiliateCreateLinkSchema,\n });\n }\n\n createTicket(input: HeadlessCustomerTicketInput): Promise<HeadlessCustomerTicketCreateResult> {\n return this.request('/tickets', {\n method: 'POST',\n authenticated: true,\n body: {\n ...(input.title === undefined ? {} : { title: input.title }),\n message: input.message,\n ...(input.invoiceId === undefined ? {} : { invoice_id: input.invoiceId }),\n },\n schema: customerPortalSupportCreateSchema,\n });\n }\n\n ticket(ticketId: string): Promise<HeadlessCustomerTicket> {\n return this.request(`/tickets/${encodeURIComponent(ticketId)}`, {\n authenticated: true,\n schema: customerPortalSupportTicketDetailSchema,\n });\n }\n\n async replyToTicket(ticketId: string, message: string): Promise<void> {\n await this.request<null>(`/tickets/${encodeURIComponent(ticketId)}/reply`, {\n method: 'POST',\n authenticated: true,\n body: { message },\n });\n }\n\n reseller(): Promise<HeadlessCustomerReseller> {\n return this.request('/reseller', {\n authenticated: true,\n schema: customerResellerSummarySchema,\n });\n }\n\n applyForReseller(note?: string): Promise<HeadlessCustomerResellerEnrollment> {\n return this.request('/reseller/apply', {\n method: 'POST',\n authenticated: true,\n body: note === undefined ? {} : { note },\n schema: customerResellerEnrollmentSchema,\n });\n }\n\n enrollAsReseller(): Promise<HeadlessCustomerResellerEnrollment> {\n return this.request('/reseller/enroll', {\n method: 'POST',\n authenticated: true,\n body: {},\n schema: customerResellerEnrollmentSchema,\n });\n }\n\n acceptResellerInvite(token: string): Promise<HeadlessCustomerResellerEnrollment> {\n return this.request('/reseller/accept-invite', {\n method: 'POST',\n authenticated: true,\n body: { token },\n schema: customerResellerEnrollmentSchema,\n });\n }\n\n resellerCatalog(\n options: HeadlessCustomerResellerCatalogQuery = {},\n ): Promise<HeadlessCustomerResellerCatalog> {\n return this.request('/reseller/catalog', {\n authenticated: true,\n query: {\n search: options.search,\n page: options.page === undefined ? undefined : String(options.page),\n per_page: options.perPage === undefined ? undefined : String(options.perPage),\n },\n schema: customerResellerCatalogSchema,\n });\n }\n\n quoteResellerOrder(\n items: HeadlessCustomerResellerOrderItem[],\n ): Promise<HeadlessCustomerResellerQuote> {\n return this.request('/reseller/orders/quote', {\n method: 'POST',\n authenticated: true,\n body: {\n items: items.map((item) => ({\n product_id: item.productId,\n ...(item.variantId === undefined ? {} : { variant_id: item.variantId }),\n quantity: item.quantity,\n })),\n },\n schema: customerResellerQuoteSchema,\n });\n }\n\n resellerOrders(\n options: HeadlessCustomerResellerOrdersQuery = {},\n ): Promise<HeadlessCustomerResellerOrders> {\n return this.request('/reseller/orders', {\n authenticated: true,\n query: {\n page: options.page === undefined ? undefined : String(options.page),\n per_page: options.perPage === undefined ? undefined : String(options.perPage),\n },\n schema: customerResellerOrdersSchema,\n });\n }\n\n resellerOrder(orderId: string): Promise<HeadlessCustomerResellerOrder> {\n return this.request(`/reseller/orders/${encodeURIComponent(orderId)}`, {\n authenticated: true,\n schema: customerResellerOrderSchema,\n });\n }\n\n resellerWallet(): Promise<HeadlessCustomerResellerWallet> {\n return this.request('/reseller/wallet', {\n authenticated: true,\n schema: customerResellerWalletSchema,\n });\n }\n\n resellerApiKeys(): Promise<HeadlessCustomerResellerApiKeys> {\n return this.request('/reseller/api-keys', {\n authenticated: true,\n schema: customerResellerApiKeysSchema,\n });\n }\n\n async logout(): Promise<void> {\n if (!this.getSession()) return;\n try {\n await this.request<null>('/auth/logout', { method: 'POST', authenticated: true });\n } catch (error) {\n if (error instanceof HeadlessCustomerError && error.status === 401) {\n // The server already considers the credential invalid. request() also\n // clears it, so logout is complete from the buyer's perspective.\n return;\n }\n // Keep the local token after a transient failure so the caller can retry\n // server-side revocation instead of leaving an unreachable live session.\n throw error;\n }\n this.clearSession();\n }\n}\n\nexport function createCustomerClient(config: HeadlessCustomerClientConfig): HeadlessCustomerClient {\n return new HeadlessCustomerClient(config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA0CA,IAAM,uBAAuB,iBAAE,OAAO,EAAE,SAAS;AAE1C,IAAM,yBAAyB,iBAAE,OAAO;AAAA,EAC7C,UAAU,iBAAE,OAAO;AAAA,IACjB,IAAI;AAAA,IACJ,OAAO,iBAAE,OAAO;AAAA,IAChB,MAAM,iBAAE,OAAO;AAAA,IACf,YAAY;AAAA,IACZ,WAAW;AAAA,EACb,CAAC;AAAA,EACD,MAAM,iBAAE,OAAO;AAAA,IACb,IAAI,iBAAE,OAAO;AAAA,IACb,MAAM,iBAAE,OAAO;AAAA,IACf,MAAM,iBAAE,OAAO;AAAA,IACf,UAAU,iBAAE,OAAO;AAAA,IACnB,UAAU;AAAA,EACZ,CAAC;AAAA,EACD,OAAO,iBAAE,KAAK;AAChB,CAAC;AAEM,IAAM,uCAAuC,iBAAE,OAAO;AAAA,EAC3D,OAAO,iBAAE,OAAO;AAAA,IACd,SAAS,iBAAE,QAAQ;AAAA,IACnB,UAAU,iBAAE,OAAO;AAAA,IACnB,YAAY,iBAAE,OAAO;AAAA,IACrB,YAAY;AAAA,IACZ,aAAa,iBAAE,MAAM,iBAAE,OAAO;AAAA,MAC5B,YAAY,iBAAE,OAAO;AAAA,MACrB,eAAe,iBAAE,OAAO;AAAA,IAC1B,CAAC,CAAC;AAAA,EACJ,CAAC;AACH,CAAC;AAEM,IAAM,wCAAwC,iBAAE,OAAO;AAAA,EAC5D,YAAY,iBAAE,OAAO;AAAA,EACrB,KAAK,iBAAE,OAAO;AAChB,CAAC;AAEM,IAAM,qCAAqC,iBAAE,OAAO;AAAA,EACzD,a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C;AAAA,EACH;AAAA,EAEA,iBAA0D;AACxD,WAAO,KAAK,QAAQ,oBAAoB;AAAA,MACtC,eAAe;AAAA,MACf,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AAAA,EAEA,kBAA4D;AAC1D,WAAO,KAAK,QAAQ,sBAAsB;AAAA,MACxC,eAAe;AAAA,MACf,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,SAAwB;AAC5B,QAAI,CAAC,KAAK,WAAW,EAAG;AACxB,QAAI;AACF,YAAM,KAAK,QAAc,gBAAgB,EAAE,QAAQ,QAAQ,eAAe,KAAK,CAAC;AAAA,IAClF,SAAS,OAAO;AACd,UAAI,iBAAiB,yBAAyB,MAAM,WAAW,KAAK;AAGlE;AAAA,MACF;AAGA,YAAM;AAAA,IACR;AACA,SAAK,aAAa;AAAA,EACpB;AACF;AAEO,SAAS,qBAAqB,QAA8D;AACjG,SAAO,IAAI,uBAAuB,MAAM;AAC1C;","names":["stored"]}
package/dist/index.cjs CHANGED
@@ -2815,8 +2815,10 @@ function priceVariantToProductVariant(variant) {
2815
2815
  cloudflareImageId: variant.cloudflareImageId,
2816
2816
  image_url: variant.image_url,
2817
2817
  imageUrl: variant.imageUrl,
2818
+ is_featured: variant.is_featured,
2818
2819
  visibility: variant.visibility,
2819
- is_private: variant.is_private
2820
+ is_private: variant.is_private,
2821
+ license_period: variant.license_period
2820
2822
  };
2821
2823
  }
2822
2824
  function normalizeProduct(product) {
@@ -24286,6 +24288,23 @@ var customerPortalInvoiceDetailSchema = external_exports.object({
24286
24288
  currency: external_exports.string()
24287
24289
  }),
24288
24290
  currentPaymentAttemptId: nullableStringSchema,
24291
+ /**
24292
+ * The goods went to a gift recipient or wait for a reveal, so a delivered
24293
+ * line without `deliverySummary` was withheld, not empty. Optional so
24294
+ * payloads from before the field parse; absent states nothing.
24295
+ */
24296
+ deliveryWithheld: external_exports.boolean().optional(),
24297
+ /**
24298
+ * What became of money an expired order took: NONE when no payment is
24299
+ * recorded; null unless EXPIRED. Optional so payloads from before the field parse.
24300
+ */
24301
+ expiredPayment: external_exports.enum(["NONE", "IN_REVIEW", "HELD", "SETTLED", "REFUNDED"]).nullable().optional(),
24302
+ /**
24303
+ * When the paying attempt completed; null until one has. Kept on a disputed
24304
+ * or refunded order, so the status decides whether it reads as paid.
24305
+ * Optional so payloads from before the field parse.
24306
+ */
24307
+ paidAt: nullableStringSchema.optional(),
24289
24308
  lineItems: external_exports.array(external_exports.object({
24290
24309
  id: external_exports.string(),
24291
24310
  productTitle: external_exports.string(),
@@ -24566,7 +24585,23 @@ var customerPortalSubscriptionSummarySchema = external_exports.object({
24566
24585
  }).nullable().optional(),
24567
24586
  pause_limit: external_exports.object({ pauses_per_year: external_exports.number(), available_again_at: external_exports.string() }).nullable().optional(),
24568
24587
  // The Discord roles a pause takes ([] none); null when not known. Optional for deploy order.
24569
- pause_access_roles: external_exports.array(external_exports.string()).nullable().optional()
24588
+ pause_access_roles: external_exports.array(external_exports.string()).nullable().optional(),
24589
+ // The running coupon term (`SubscriptionCouponTermView`, loadSubscriptionCouponTermView); null
24590
+ // without one. Amounts are the renewal-pricing function's, in `currency`. Same deploy order.
24591
+ discount: external_exports.object({
24592
+ code: external_exports.string(),
24593
+ discount_type: external_exports.enum(["PERCENTAGE", "FIXED"]),
24594
+ discount_value: external_exports.string(),
24595
+ max_discount: nullableStringSchema,
24596
+ currency: external_exports.string(),
24597
+ duration: external_exports.enum(["ONCE", "REPEATING", "FOREVER"]),
24598
+ payments_total: external_exports.number().nullable(),
24599
+ payments_used: external_exports.number(),
24600
+ discounted_amount: external_exports.string(),
24601
+ full_amount: external_exports.string(),
24602
+ discount_amount: external_exports.string(),
24603
+ next_amount: external_exports.string()
24604
+ }).nullable().optional()
24570
24605
  });
24571
24606
  var customerLoyaltySchema = external_exports.object({
24572
24607
  enabled: external_exports.boolean(),
@@ -24848,6 +24883,7 @@ function orders(options = {}) {
24848
24883
  if (options.page !== void 0) query.set("page", String(options.page));
24849
24884
  if (options.limit !== void 0) query.set("limit", String(options.limit));
24850
24885
  if (options.status) query.set("status", options.status);
24886
+ if (options.statusGroup) query.set("status_group", options.statusGroup);
24851
24887
  if (options.search) query.set("q", options.search);
24852
24888
  const suffix = query.size > 0 ? `?${query.toString()}` : "";
24853
24889
  return requestCustomer(`/invoices${suffix}`, { schema: customerPortalPaginatedInvoicesSchema });