import { ad as CimplifyClient } from './client-xc2aQSB4.js';
export { K as CacheOptions, ct as ReadRequestOptions, cP as Result } from './client-xc2aQSB4.js';
export { Q as Category, T as CimplifyError, U as Collection, aX as Product, b9 as ProductWithDetails } from './product-DXhjLQ_w.js';
import { JWTVerifyResult } from 'jose';
import './payment-nH9OCUg2.js';

interface ServerClientOptions {
    /**
     * Cimplify API base URL. Defaults to `CIMPLIFY_API_URL`,
     * then `NEXT_PUBLIC_CIMPLIFY_API_URL`, then the local mock at
     * `http://127.0.0.1:8787` for dev.
     */
    apiUrl?: string;
    /**
     * Server-only key. Defaults to `CIMPLIFY_SECRET_KEY`. Falls back to the
     * publishable key (`NEXT_PUBLIC_CIMPLIFY_PUBLIC_KEY`) so the local mock
     * works without forcing consumers to set a fake secret in dev.
     */
    secretKey?: string;
    /** Optional location id used by location-scoped queries. */
    locationId?: string;
    /**
     * Customer OAuth access token. When present, the client attaches
     * `Authorization: Bearer <token>` to every request so lenses scopes
     * responses to the signed-in customer (their orders, their assigned
     * price list, their subscriptions).
     */
    accessToken?: string;
}
/**
 * Returns a `CimplifyClient` configured for server-side execution and
 * memoized **per request** via React's `cache()` — calling this multiple
 * times within a single render tree returns the same instance, so RSC
 * fan-out doesn't create N clients.
 *
 * The returned client is the exact same surface the browser uses — every
 * resource (catalogue, cart, checkout, …) and every method works identically.
 *
 * Caching is Next.js's responsibility. Pass `cacheOptions` per read method
 * (`{ revalidate, tags }`); the SDK forwards them as `next: { revalidate, tags }`
 * on the underlying fetch — Next 16's documented ISR API. Invalidate via the
 * `revalidate*` helpers (also exported from this entry) or the bare
 * `revalidateTag` / `revalidatePath` from `next/cache`.
 *
 * If you have `cacheComponents: true` in `next.config.ts` (Next 16 PPR-style
 * caching), the `'use cache'` + `cacheTag` / `cacheLife` directives work too —
 * but they require a Node-compatible runtime and won't function on Cloudflare
 * Workers. For Workers / WfP storefronts, stay on the ISR (`cacheOptions`) path.
 *
 * Errors continue to flow through `Result<T, CimplifyError>`. Use the SDK's
 * `unwrap()` helper, or `if (!result.ok) notFound()` — whichever is
 * idiomatic for the route.
 *
 * @example
 *   import { getServerClient, tags } from "@cimplify/sdk/server";
 *
 *   export const revalidate = 3600;
 *
 *   async function getProduct(slug: string) {
 *     const r = await getServerClient().catalogue.getProductBySlug(slug, {
 *       cacheOptions: { revalidate: 3600, tags: [tags.product(slug)] },
 *     });
 *     if (!r.ok) throw new Error(r.error.message);
 *     return r.value;
 *   }
 */
declare const getServerClient: (opts?: ServerClientOptions) => CimplifyClient;

/**
 * Cimplify cache-tag scheme.
 *
 * Use these constants/builders to tag fetches and invalidate them. The
 * shape is namespaced (`cimplify:<resource>` and `cimplify:<resource>:<id>`)
 * so consumer cache tags can't accidentally collide. Tag strings should
 * always be constructed via these builders so the scheme stays in one place.
 */
declare const tags: {
    readonly products: () => string;
    readonly product: (id: string) => string;
    readonly categories: () => string;
    readonly category: (id: string) => string;
    readonly categoryProducts: (id: string) => string;
    readonly collections: () => string;
    readonly collection: (id: string) => string;
    readonly collectionProducts: (id: string) => string;
    readonly business: () => string;
    readonly brand: () => string;
    readonly locations: () => string;
    readonly location: (id: string) => string;
    readonly locale: () => string;
    readonly pricing: () => string;
    readonly tag: (name: string) => string;
    readonly addons: () => string;
    readonly addon: (id: string) => string;
    readonly subscriptions: () => string;
    readonly subscription: (id: string) => string;
    readonly stock: () => string;
    readonly stockFor: (productId: string) => string;
    readonly orders: (customerId: string) => string;
    readonly order: (id: string) => string;
};

/**
 * Cimplify's opinionated cacheLife profiles for storefront server caches.
 *
 * Pass either of these to Next 16's `cacheLife(...)` inside a `'use cache'`
 * server function. They're typed-literal exports so a typo fails at the SDK
 * import site, not silently at runtime (Next's own `cacheLife(profile: string)`
 * overload would accept anything and look it up as a custom profile).
 *
 * @example
 * ```ts
 * import { cacheLife } from "next/cache";
 * import { CACHE_LIFE_DEFAULT, CACHE_LIFE_PROBE, tags } from "@cimplify/sdk/server";
 *
 * async function getProducts() {
 *   "use cache";
 *   cacheTag(tags.products());
 *   const r = await getServerClient().catalogue.getProducts();
 *   // Don't lock in empties / failures — a transient bad render would
 *   // otherwise sit cached for the full "max" window.
 *   if (!r.ok || r.value.items.length === 0) {
 *     cacheLife(CACHE_LIFE_PROBE);
 *     return r;
 *   }
 *   cacheLife(CACHE_LIFE_DEFAULT);
 *   return r;
 * }
 * ```
 */
/**
 * The default cacheLife for cached storefront reads. Resolves to `"max"`,
 * which is Next 16's longest built-in profile (stale 5min, revalidate 30d,
 * never expires). Safe because Cimplify's tag-cache + CF cache-purge wiring
 * invalidates on-demand within ~1s of a merchant edit — there's no benefit
 * to short timer-based expirations on data Cimplify owns.
 */
declare const CACHE_LIFE_DEFAULT: "max";
/**
 * Short-lived cacheLife for "probe" results — empty arrays, errors, 404s,
 * anything that *might* be a transient bad render. Resolves to `"seconds"`
 * (stale 30s, revalidate 1s, expires 1min). Use this when the fetch returned
 * no usable data so a momentary backend blip can't get locked into the cache
 * for `CACHE_LIFE_DEFAULT`'s entire window.
 *
 * The tag still gets attached, so a real `revalidateTag(...)` from Cimplify
 * will refresh the entry the moment the underlying data changes.
 */
declare const CACHE_LIFE_PROBE: "seconds";
/** The TS type of {@link CACHE_LIFE_DEFAULT} — the `"max"` literal. */
type CacheLifeDefault = typeof CACHE_LIFE_DEFAULT;
/** The TS type of {@link CACHE_LIFE_PROBE} — the `"seconds"` literal. */
type CacheLifeProbe = typeof CACHE_LIFE_PROBE;

/** Next 16 cacheLife profile — a built-in name (`'max'`/`'hours'`/…) or `{expire: secs}`. */
type RevalidateProfile = string | {
    expire: number;
};
declare function revalidateProducts(profile?: RevalidateProfile): Promise<void>;
declare function revalidateProduct(id: string, profile?: RevalidateProfile): Promise<void>;
declare function revalidateCategories(profile?: RevalidateProfile): Promise<void>;
declare function revalidateCategory(id: string, profile?: RevalidateProfile): Promise<void>;
declare function revalidateCollections(profile?: RevalidateProfile): Promise<void>;
declare function revalidateCollection(id: string, profile?: RevalidateProfile): Promise<void>;
declare function revalidateBusiness(profile?: RevalidateProfile): Promise<void>;
declare function revalidateBrand(profile?: RevalidateProfile): Promise<void>;
declare function revalidateLocations(profile?: RevalidateProfile): Promise<void>;
declare function revalidateLocation(id: string, profile?: RevalidateProfile): Promise<void>;
declare function revalidatePricing(profile?: RevalidateProfile): Promise<void>;
declare function revalidateAddOns(profile?: RevalidateProfile): Promise<void>;
declare function revalidateAddOn(id: string, profile?: RevalidateProfile): Promise<void>;
declare function revalidateSubscriptions(profile?: RevalidateProfile): Promise<void>;
declare function revalidateSubscription(id: string, profile?: RevalidateProfile): Promise<void>;
declare function revalidateStock(productId?: string, profile?: RevalidateProfile): Promise<void>;
declare function revalidateByTag(tag: string, profile?: RevalidateProfile): Promise<void>;

declare function updateProducts(): Promise<void>;
declare function updateProduct(id: string): Promise<void>;
declare function updateCategories(): Promise<void>;
declare function updateCategory(id: string): Promise<void>;
declare function updateCollections(): Promise<void>;
declare function updateCollection(id: string): Promise<void>;
declare function updateBusiness(): Promise<void>;
declare function updateBrand(): Promise<void>;
declare function updateLocations(): Promise<void>;
declare function updateLocation(id: string): Promise<void>;
declare function updatePricing(): Promise<void>;
declare function updateAddOns(): Promise<void>;
declare function updateAddOn(id: string): Promise<void>;
declare function updateSubscriptions(): Promise<void>;
declare function updateSubscription(id: string): Promise<void>;
declare function updateStock(productId?: string): Promise<void>;
declare function updateByTag(tag: string): Promise<void>;
declare function refreshPage(): Promise<void>;

interface OidcConfig {
    /** OIDC issuer — the discovery anchor. Every endpoint is read from its
     *  /.well-known/openid-configuration. Defaults to https://api.cimplify.io. */
    issuer?: string;
    /** @deprecated Use `issuer`. Kept as an alias for one release. */
    authUrl?: string;
    clientId: string;
    cookieName?: string;
    cookieDomain?: string;
    accessTokenCookieName?: string;
    refreshTokenCookieName?: string;
}
interface CimplifySession {
    sub: string;
    name?: string;
    email?: string;
    emailVerified?: boolean;
    phoneNumber?: string;
    phoneNumberVerified?: boolean;
    exp: number;
    iat: number;
}
interface CodeExchangeOptions extends OidcConfig {
    code: string;
    codeVerifier: string;
    redirectUri: string;
}
interface CodeExchangeResult {
    accessToken: string;
    idToken?: string;
    refreshToken?: string;
    expiresIn: number;
    scope: string;
}
declare function exchangeCode(opts: CodeExchangeOptions): Promise<CodeExchangeResult>;
declare function verifyIdToken(cfg: OidcConfig, idToken: string): Promise<JWTVerifyResult>;
declare function buildSessionCookie(cfg: OidcConfig, idToken: string, maxAgeSeconds: number): string;
declare function buildSignoutCookie(cfg: OidcConfig): string;
declare function buildAccessTokenCookie(cfg: OidcConfig, accessToken: string, maxAgeSeconds: number): string;
declare function buildRefreshTokenCookie(cfg: OidcConfig, refreshToken: string, maxAgeSeconds: number): string;
declare function buildSignoutCookies(cfg: OidcConfig): string[];
declare function getRefreshTokenFromCookieHeader(cfg: OidcConfig, cookieHeader: string | null | undefined): string | null;
declare function getAccessTokenFromCookieHeader(cfg: OidcConfig, cookieHeader: string | null | undefined): string | null;
interface CallbackHandlerOptions extends OidcConfig {
    redirectUri: string;
}
declare function handleOidcCallback(req: Request, opts: CallbackHandlerOptions): Promise<Response>;
interface RedirectCallbackOptions extends OidcConfig {
    redirectUri: string;
    defaultReturnTo?: string;
}
/**
 * Completes the redirect sign-in flow. The browser lands here (a top-level GET
 * to the storefront's registered redirect_uri) carrying ?code&state; the PKCE
 * verifier rides along in the first-party cimplify_pkce cookie. Exchanges the
 * code server-side, sets the session cookies, and 302s back to returnTo.
 */
declare function handleRedirectCallback(req: Request, opts: RedirectCallbackOptions): Promise<Response>;
declare function handleSessionRequest(req: Request, cfg: OidcConfig): Promise<Response>;
declare function getSessionFromCookieHeader(cfg: OidcConfig, cookieHeader: string | null | undefined): Promise<CimplifySession | null>;
declare function refreshTokens(cfg: OidcConfig, refreshToken: string): Promise<CodeExchangeResult>;
interface TokenRefreshResult {
    outcome: "noop" | "refreshed" | "cleared";
    /** Set-Cookie header values for the browser. */
    setCookies: string[];
    /** Forwarded onto the current request so this render sees the rotated tokens. */
    cookies: {
        name: string;
        value: string;
    }[];
}
declare function handleTokenRefresh(req: Request, cfg: OidcConfig): Promise<TokenRefreshResult>;

export { CACHE_LIFE_DEFAULT, CACHE_LIFE_PROBE, type CacheLifeDefault, type CacheLifeProbe, type CallbackHandlerOptions, CimplifyClient, type CimplifySession, type CodeExchangeOptions, type CodeExchangeResult, type OidcConfig, type RedirectCallbackOptions, type RevalidateProfile, type ServerClientOptions, type TokenRefreshResult, buildAccessTokenCookie, buildRefreshTokenCookie, buildSessionCookie, buildSignoutCookie, buildSignoutCookies, exchangeCode, getAccessTokenFromCookieHeader, getRefreshTokenFromCookieHeader, getServerClient, getSessionFromCookieHeader, handleOidcCallback, handleRedirectCallback, handleSessionRequest, handleTokenRefresh, refreshPage, refreshTokens, revalidateAddOn, revalidateAddOns, revalidateBrand, revalidateBusiness, revalidateByTag, revalidateCategories, revalidateCategory, revalidateCollection, revalidateCollections, revalidateLocation, revalidateLocations, revalidatePricing, revalidateProduct, revalidateProducts, revalidateStock, revalidateSubscription, revalidateSubscriptions, tags, updateAddOn, updateAddOns, updateBrand, updateBusiness, updateByTag, updateCategories, updateCategory, updateCollection, updateCollections, updateLocation, updateLocations, updatePricing, updateProduct, updateProducts, updateStock, updateSubscription, updateSubscriptions, verifyIdToken };
