'use strict';

var chunkIQLJJW2H_js = require('./chunk-IQLJJW2H.js');
var chunkL5GKVQVJ_js = require('./chunk-L5GKVQVJ.js');
var chunkGFM5JW45_js = require('./chunk-GFM5JW45.js');
var chunkHPN5R3K2_js = require('./chunk-HPN5R3K2.js');
var chunk7Y2O3E4D_js = require('./chunk-7Y2O3E4D.js');
var chunkXA3ZNR75_js = require('./chunk-XA3ZNR75.js');
require('./chunk-OWW5GUSB.js');

// src/silent-sign-in.ts
var DEFAULT_SCOPE = "openid email phone profile";
var DEFAULT_TIMEOUT_MS = 12e3;
var RESPONSE_TYPE_CODE = "code";
var RESPONSE_MODE_WEB_MESSAGE = "web_message";
var PROMPT_NONE = "none";
var AUTHORIZATION_RESPONSE_MESSAGE_TYPE = "authorization_response";
var ERROR_LOGIN_REQUIRED = "login_required";
async function signInSilent(opts) {
  const sessionUri = opts.sessionUri ?? "/auth/session";
  try {
    const sess = await fetch(sessionUri, { credentials: "include" });
    if (sess.ok) {
      const body = await sess.json().catch(() => null);
      if (body?.sub) return { ok: true, reason: "already_signed_in" };
    }
  } catch {
  }
  const callbackUri = opts.callbackUri ?? "/auth/callback";
  const authorizeEndpoint = opts.authUrl ? `${opts.authUrl.replace(/\/$/, "")}/oauth/authorize` : await chunkHPN5R3K2_js.getAuthorizationEndpoint(opts.issuer ?? chunkHPN5R3K2_js.DEFAULT_ISSUER);
  const pkce = await chunkHPN5R3K2_js.generatePkce();
  const state = chunkHPN5R3K2_js.generateState();
  const params = new URLSearchParams({
    response_type: RESPONSE_TYPE_CODE,
    response_mode: RESPONSE_MODE_WEB_MESSAGE,
    prompt: PROMPT_NONE,
    client_id: opts.clientId,
    redirect_uri: opts.redirectUri,
    scope: opts.scope ?? DEFAULT_SCOPE,
    state,
    code_challenge: pkce.challenge,
    code_challenge_method: pkce.method
  });
  const src = `${authorizeEndpoint}?${params.toString()}`;
  const expectedOrigin = new URL(authorizeEndpoint).origin;
  const iframe = document.createElement("iframe");
  iframe.style.display = "none";
  iframe.setAttribute("aria-hidden", "true");
  iframe.setAttribute("sandbox", "allow-scripts allow-same-origin");
  iframe.src = src;
  document.body.appendChild(iframe);
  const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
  return new Promise((resolve) => {
    let settled = false;
    const cleanup = () => {
      window.removeEventListener("message", handler);
      iframe.remove();
      clearTimeout(timer);
    };
    const finish = (result) => {
      if (settled) return;
      settled = true;
      cleanup();
      resolve(result);
    };
    const timer = setTimeout(() => finish({ ok: false, reason: "timeout" }), timeoutMs);
    const handler = async (event) => {
      if (event.origin !== expectedOrigin) return;
      const data = event.data;
      if (!data || typeof data !== "object" || data.type !== AUTHORIZATION_RESPONSE_MESSAGE_TYPE) return;
      const response = data.response;
      if (response.error === ERROR_LOGIN_REQUIRED) {
        finish({ ok: false, reason: ERROR_LOGIN_REQUIRED });
        return;
      }
      if (response.error || !response.code) {
        finish({ ok: false, reason: ERROR_LOGIN_REQUIRED });
        return;
      }
      if (response.state !== state) {
        finish({ ok: false, reason: "state_mismatch" });
        return;
      }
      try {
        const res = await fetch(callbackUri, {
          method: "POST",
          credentials: "include",
          headers: { "Content-Type": "application/json" },
          body: JSON.stringify({ code: response.code, codeVerifier: pkce.verifier, state })
        });
        finish(res.ok ? { ok: true } : { ok: false, reason: "callback_failed" });
      } catch {
        finish({ ok: false, reason: "exception" });
      }
    };
    window.addEventListener("message", handler);
  });
}

Object.defineProperty(exports, "CIMPLIFY_CDN_HOSTS", {
  enumerable: true,
  get: function () { return chunkIQLJJW2H_js.CIMPLIFY_CDN_HOSTS; }
});
Object.defineProperty(exports, "DEFAULT_CDN_BASE_URL", {
  enumerable: true,
  get: function () { return chunkIQLJJW2H_js.DEFAULT_CDN_BASE_URL; }
});
Object.defineProperty(exports, "DURATION_UNIT", {
  enumerable: true,
  get: function () { return chunkIQLJJW2H_js.DURATION_UNIT; }
});
Object.defineProperty(exports, "INPUT_FIELD_TYPE", {
  enumerable: true,
  get: function () { return chunkIQLJJW2H_js.INPUT_FIELD_TYPE; }
});
Object.defineProperty(exports, "PRODUCT_TYPE", {
  enumerable: true,
  get: function () { return chunkIQLJJW2H_js.PRODUCT_TYPE; }
});
Object.defineProperty(exports, "RENDER_HINT", {
  enumerable: true,
  get: function () { return chunkIQLJJW2H_js.RENDER_HINT; }
});
Object.defineProperty(exports, "allGalleryImages", {
  enumerable: true,
  get: function () { return chunkIQLJJW2H_js.allGalleryImages; }
});
Object.defineProperty(exports, "assetUrl", {
  enumerable: true,
  get: function () { return chunkIQLJJW2H_js.assetUrl; }
});
Object.defineProperty(exports, "getVariantDisplayName", {
  enumerable: true,
  get: function () { return chunkIQLJJW2H_js.getVariantDisplayName; }
});
Object.defineProperty(exports, "isCimplifyAsset", {
  enumerable: true,
  get: function () { return chunkIQLJJW2H_js.isCimplifyAsset; }
});
Object.defineProperty(exports, "resolveGallery", {
  enumerable: true,
  get: function () { return chunkIQLJJW2H_js.resolveGallery; }
});
Object.defineProperty(exports, "isValidPhoneForContext", {
  enumerable: true,
  get: function () { return chunkL5GKVQVJ_js.isValidPhoneForContext; }
});
Object.defineProperty(exports, "normalizePhoneToE164", {
  enumerable: true,
  get: function () { return chunkL5GKVQVJ_js.normalizePhoneToE164; }
});
Object.defineProperty(exports, "resolvePhoneCountryCode", {
  enumerable: true,
  get: function () { return chunkL5GKVQVJ_js.resolvePhoneCountryCode; }
});
Object.defineProperty(exports, "ActivityService", {
  enumerable: true,
  get: function () { return chunkGFM5JW45_js.ActivityService; }
});
Object.defineProperty(exports, "CimplifyClient", {
  enumerable: true,
  get: function () { return chunkGFM5JW45_js.CimplifyClient; }
});
Object.defineProperty(exports, "DeliveryService", {
  enumerable: true,
  get: function () { return chunkGFM5JW45_js.DeliveryService; }
});
Object.defineProperty(exports, "PlacesService", {
  enumerable: true,
  get: function () { return chunkGFM5JW45_js.PlacesService; }
});
Object.defineProperty(exports, "StoreCreditQueries", {
  enumerable: true,
  get: function () { return chunkGFM5JW45_js.StoreCreditQueries; }
});
Object.defineProperty(exports, "SubscriptionService", {
  enumerable: true,
  get: function () { return chunkGFM5JW45_js.SubscriptionService; }
});
Object.defineProperty(exports, "SupportService", {
  enumerable: true,
  get: function () { return chunkGFM5JW45_js.SupportService; }
});
Object.defineProperty(exports, "UploadService", {
  enumerable: true,
  get: function () { return chunkGFM5JW45_js.UploadService; }
});
Object.defineProperty(exports, "createCimplifyClient", {
  enumerable: true,
  get: function () { return chunkGFM5JW45_js.createCimplifyClient; }
});
Object.defineProperty(exports, "AUTHORIZATION_TYPE", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.AUTHORIZATION_TYPE; }
});
Object.defineProperty(exports, "AUTH_MUTATION", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.AUTH_MUTATION; }
});
Object.defineProperty(exports, "AuthService", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.AuthService; }
});
Object.defineProperty(exports, "BusinessService", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.BusinessService; }
});
Object.defineProperty(exports, "CHECKOUT_MODE", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.CHECKOUT_MODE; }
});
Object.defineProperty(exports, "CHECKOUT_MUTATION", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.CHECKOUT_MUTATION; }
});
Object.defineProperty(exports, "CHECKOUT_STEP", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.CHECKOUT_STEP; }
});
Object.defineProperty(exports, "CONTACT_TYPE", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.CONTACT_TYPE; }
});
Object.defineProperty(exports, "CartOperations", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.CartOperations; }
});
Object.defineProperty(exports, "CatalogueQueries", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.CatalogueQueries; }
});
Object.defineProperty(exports, "CheckoutOperations", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.CheckoutService; }
});
Object.defineProperty(exports, "CheckoutService", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.CheckoutService; }
});
Object.defineProperty(exports, "CimplifyElement", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.CimplifyElement; }
});
Object.defineProperty(exports, "CimplifyElements", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.CimplifyElements; }
});
Object.defineProperty(exports, "DEFAULT_COUNTRY", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.DEFAULT_COUNTRY; }
});
Object.defineProperty(exports, "DEFAULT_CURRENCY", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.DEFAULT_CURRENCY; }
});
Object.defineProperty(exports, "DEVICE_TYPE", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.DEVICE_TYPE; }
});
Object.defineProperty(exports, "ELEMENTS_AUTH_CONTACT_TYPES", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.ELEMENTS_AUTH_CONTACT_TYPES; }
});
Object.defineProperty(exports, "ELEMENTS_AUTH_MODES", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.ELEMENTS_AUTH_MODES; }
});
Object.defineProperty(exports, "ELEMENTS_AUTH_PROMPTS", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.ELEMENTS_AUTH_PROMPTS; }
});
Object.defineProperty(exports, "ELEMENT_TYPES", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.ELEMENT_TYPES; }
});
Object.defineProperty(exports, "EVENT_TYPES", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.EVENT_TYPES; }
});
Object.defineProperty(exports, "FxService", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.FxService; }
});
Object.defineProperty(exports, "InventoryService", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.InventoryService; }
});
Object.defineProperty(exports, "LINK_MUTATION", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.LINK_MUTATION; }
});
Object.defineProperty(exports, "LINK_QUERY", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.LINK_QUERY; }
});
Object.defineProperty(exports, "LinkService", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.LinkService; }
});
Object.defineProperty(exports, "LiteService", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.LiteService; }
});
Object.defineProperty(exports, "MESSAGE_TYPES", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.MESSAGE_TYPES; }
});
Object.defineProperty(exports, "MOBILE_MONEY_PROVIDER", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.MOBILE_MONEY_PROVIDER; }
});
Object.defineProperty(exports, "ORDER_MUTATION", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.ORDER_MUTATION; }
});
Object.defineProperty(exports, "ORDER_TYPE", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.ORDER_TYPE; }
});
Object.defineProperty(exports, "OrderQueries", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.OrderQueries; }
});
Object.defineProperty(exports, "PAYMENT_METHOD", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.PAYMENT_METHOD; }
});
Object.defineProperty(exports, "PAYMENT_MUTATION", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.PAYMENT_MUTATION; }
});
Object.defineProperty(exports, "PAYMENT_STATE", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.PAYMENT_STATE; }
});
Object.defineProperty(exports, "PICKUP_TIME_TYPE", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.PICKUP_TIME_TYPE; }
});
Object.defineProperty(exports, "SchedulingService", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.SchedulingService; }
});
Object.defineProperty(exports, "combine", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.combine; }
});
Object.defineProperty(exports, "combineObject", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.combineObject; }
});
Object.defineProperty(exports, "createElements", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.createElements; }
});
Object.defineProperty(exports, "err", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.err; }
});
Object.defineProperty(exports, "flatMap", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.flatMap; }
});
Object.defineProperty(exports, "fromPromise", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.fromPromise; }
});
Object.defineProperty(exports, "generateIdempotencyKey", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.generateIdempotencyKey; }
});
Object.defineProperty(exports, "getOrElse", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.getOrElse; }
});
Object.defineProperty(exports, "isErr", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.isErr; }
});
Object.defineProperty(exports, "isOk", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.isOk; }
});
Object.defineProperty(exports, "mapError", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.mapError; }
});
Object.defineProperty(exports, "mapResult", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.mapResult; }
});
Object.defineProperty(exports, "ok", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.ok; }
});
Object.defineProperty(exports, "startSignIn", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.startSignIn; }
});
Object.defineProperty(exports, "toNullable", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.toNullable; }
});
Object.defineProperty(exports, "tryCatch", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.tryCatch; }
});
Object.defineProperty(exports, "unwrap", {
  enumerable: true,
  get: function () { return chunkHPN5R3K2_js.unwrap; }
});
Object.defineProperty(exports, "CURRENCY_SYMBOLS", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.CURRENCY_SYMBOLS; }
});
Object.defineProperty(exports, "MOBILE_MONEY_PROVIDERS", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.MOBILE_MONEY_PROVIDERS; }
});
Object.defineProperty(exports, "categorizePaymentError", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.categorizePaymentError; }
});
Object.defineProperty(exports, "detectMobileMoneyProvider", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.detectMobileMoneyProvider; }
});
Object.defineProperty(exports, "formatMoney", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.formatMoney; }
});
Object.defineProperty(exports, "formatNumberCompact", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.formatNumberCompact; }
});
Object.defineProperty(exports, "formatPrice", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.formatPrice; }
});
Object.defineProperty(exports, "formatPriceAdjustment", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.formatPriceAdjustment; }
});
Object.defineProperty(exports, "formatPriceCompact", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.formatPriceCompact; }
});
Object.defineProperty(exports, "formatPriceRange", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.formatPriceRange; }
});
Object.defineProperty(exports, "formatPriceWithTax", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.formatPriceWithTax; }
});
Object.defineProperty(exports, "formatProductPrice", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.formatProductPrice; }
});
Object.defineProperty(exports, "getBasePrice", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.getBasePrice; }
});
Object.defineProperty(exports, "getCurrencySymbol", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.getCurrencySymbol; }
});
Object.defineProperty(exports, "getDiscountPercentage", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.getDiscountPercentage; }
});
Object.defineProperty(exports, "getDisplayPrice", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.getDisplayPrice; }
});
Object.defineProperty(exports, "getMarkupPercentage", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.getMarkupPercentage; }
});
Object.defineProperty(exports, "getPriceRange", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.getPriceRange; }
});
Object.defineProperty(exports, "getProductCurrency", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.getProductCurrency; }
});
Object.defineProperty(exports, "getTaxAmount", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.getTaxAmount; }
});
Object.defineProperty(exports, "getUnitPriceAtQuantity", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.getUnitPriceAtQuantity; }
});
Object.defineProperty(exports, "hasTaxInfo", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.hasTaxInfo; }
});
Object.defineProperty(exports, "isOnSale", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.isOnSale; }
});
Object.defineProperty(exports, "isPaymentStatusFailure", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.isPaymentStatusFailure; }
});
Object.defineProperty(exports, "isPaymentStatusRequiresAction", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.isPaymentStatusRequiresAction; }
});
Object.defineProperty(exports, "isPaymentStatusSuccess", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.isPaymentStatusSuccess; }
});
Object.defineProperty(exports, "isTaxInclusive", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.isTaxInclusive; }
});
Object.defineProperty(exports, "normalizePaymentResponse", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.normalizePaymentResponse; }
});
Object.defineProperty(exports, "normalizeStatusResponse", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.normalizeStatusResponse; }
});
Object.defineProperty(exports, "parsePrice", {
  enumerable: true,
  get: function () { return chunk7Y2O3E4D_js.parsePrice; }
});
Object.defineProperty(exports, "CimplifyError", {
  enumerable: true,
  get: function () { return chunkXA3ZNR75_js.CimplifyError; }
});
Object.defineProperty(exports, "ERROR_HINTS", {
  enumerable: true,
  get: function () { return chunkXA3ZNR75_js.ERROR_HINTS; }
});
Object.defineProperty(exports, "ErrorCode", {
  enumerable: true,
  get: function () { return chunkXA3ZNR75_js.ErrorCode; }
});
Object.defineProperty(exports, "IdempotencyMismatchError", {
  enumerable: true,
  get: function () { return chunkXA3ZNR75_js.IdempotencyMismatchError; }
});
Object.defineProperty(exports, "ZERO", {
  enumerable: true,
  get: function () { return chunkXA3ZNR75_js.ZERO; }
});
Object.defineProperty(exports, "currencyCode", {
  enumerable: true,
  get: function () { return chunkXA3ZNR75_js.currencyCode; }
});
Object.defineProperty(exports, "enrichError", {
  enumerable: true,
  get: function () { return chunkXA3ZNR75_js.enrichError; }
});
Object.defineProperty(exports, "getErrorHint", {
  enumerable: true,
  get: function () { return chunkXA3ZNR75_js.getErrorHint; }
});
Object.defineProperty(exports, "isCimplifyError", {
  enumerable: true,
  get: function () { return chunkXA3ZNR75_js.isCimplifyError; }
});
Object.defineProperty(exports, "isIdempotencyMismatchError", {
  enumerable: true,
  get: function () { return chunkXA3ZNR75_js.isIdempotencyMismatchError; }
});
Object.defineProperty(exports, "isQuoteConflictRequiringConsent", {
  enumerable: true,
  get: function () { return chunkXA3ZNR75_js.isQuoteConflictRequiringConsent; }
});
Object.defineProperty(exports, "isQuoteError", {
  enumerable: true,
  get: function () { return chunkXA3ZNR75_js.isQuoteError; }
});
Object.defineProperty(exports, "isRetryableError", {
  enumerable: true,
  get: function () { return chunkXA3ZNR75_js.isRetryableError; }
});
Object.defineProperty(exports, "isSupportedCurrency", {
  enumerable: true,
  get: function () { return chunkXA3ZNR75_js.isSupportedCurrency; }
});
Object.defineProperty(exports, "money", {
  enumerable: true,
  get: function () { return chunkXA3ZNR75_js.money; }
});
Object.defineProperty(exports, "moneyFromNumber", {
  enumerable: true,
  get: function () { return chunkXA3ZNR75_js.moneyFromNumber; }
});
exports.signInSilent = signInSilent;
