import { LocalStorage } from './local-storage.js'; import type { AdminSession } from './session.js'; /** * Discriminator for a stored store auth session. * * - 'standard': created via `shopify store auth`. * - 'preview': created via `shopify store create preview`; backed by a server-issued Admin API token. * * Stored sessions written before this discriminator existed have no `kind` field and are * read back as 'standard'. */ export type StoredStoreSessionKind = 'standard' | 'preview'; export interface StoredPreviewStoreMetadata { /** Placeholder account UUID returned by the preview-store backend when available. */ placeholderAccountUuid?: string; /** Numeric shop id returned by the preview-store backend. */ shopId: string; /** Store name returned by the preview-store backend. */ name: string; /** ISO country code requested for the store, when provided by the caller. */ country?: string; /** ISO timestamp for when the preview store was created locally. */ createdAt: string; /** Access URL returned by the preview-store backend. */ accessUrl?: string; } export interface StoredStoreAppSession { store: string; clientId: string; userId: string; accessToken: string; refreshToken?: string; scopes: string[]; acquiredAt: string; expiresAt?: string; refreshTokenExpiresAt?: string; associatedUser?: { id: number; email?: string; firstName?: string; lastName?: string; accountOwner?: boolean; }; /** * Discriminator. Optional in storage for back-compat with sessions written before the * field existed; `sessionKind()` resolves missing values to 'standard'. */ kind?: StoredStoreSessionKind; /** Preview-store-only metadata. Set iff `kind === 'preview'`. */ preview?: StoredPreviewStoreMetadata; } interface StoredStoreAppSessionBucket { currentUserId: string; sessionsByUserId: { [userId: string]: StoredStoreAppSession; }; } interface StoreAuthSessionSchema { [key: string]: StoredStoreAppSessionBucket; } /** * Build the local-storage key used for store-auth sessions. * * @param store - The normalized store FQDN. * @returns The store-auth session storage key. */ export declare function storeAuthSessionKey(store: string): string; /** * Project the current session for every store that has locally stored store auth. * * @param storage - Optional storage override for tests. * @returns Current stored store auth sessions. */ export declare function listCurrentStoredStoreAppSessions(storage?: LocalStorage): StoredStoreAppSession[]; /** * Get the current stored store auth session for a store. * * @param store - The store FQDN or URL to load a store-auth session for. * @param storage - Optional storage override for tests. * @returns The current stored store auth session, or undefined when missing or malformed. */ export declare function getCurrentStoredStoreAppSession(store: string, storage?: LocalStorage): StoredStoreAppSession | undefined; /** * Persist a store auth session and mark it as current for its store. * * @param session - The store auth session to persist. * @param storage - Optional storage override for tests. */ export declare function setStoredStoreAppSession(session: StoredStoreAppSession, storage?: LocalStorage): void; /** * Clear stored store auth sessions for a store. * * @param store - The store FQDN or URL to clear sessions for. * @param userIdOrStorage - Optional user ID to clear, or storage override when clearing all users. * @param maybeStorage - Optional storage override when clearing one user. */ export declare function clearStoredStoreAppSession(store: string, userIdOrStorage?: string | LocalStorage, maybeStorage?: LocalStorage): void; /** * Load an Admin API session from the local store-auth cache when one is currently usable. * * @param store - The store FQDN or URL to load a store-auth session for. * @param storage - Optional storage override for tests. * @returns An Admin session, or undefined when no usable session is cached. */ export declare function getStoreAuthAdminSession(store: string, storage?: LocalStorage): AdminSession | undefined; /** * Check whether a stored store auth session is expired, including the refresh margin. * * @param session - The stored store auth session. * @returns True when the session is expired or has an invalid expiry timestamp. */ export declare function isSessionExpired(session: StoredStoreAppSession): boolean; export {};