import { RxReplicationPullStreamItem, RxReplicationWriteToMasterRow, RxJsonSchema } from 'rxdb'; import { Observable } from 'rxjs'; import * as react_jsx_runtime from 'react/jsx-runtime'; import { ReactNode } from 'react'; /** * Product traits — the stable interface that UI components program against. * * Each connector implements these accessors to extract standard product data * from its own schema shape. Components call these instead of reaching into * the raw document, so they work identically across WooCommerce, Medusa, * Vendure, Shopify, etc. * * The generic `Doc` type is the connector's raw RxDB document type. */ interface ProductTraits { /** Product display name */ getName: (doc: Doc) => string; /** SKU / stock keeping unit */ getSku: (doc: Doc) => string | undefined; /** Current selling price as a string (connector-native format) */ getPrice: (doc: Doc) => string | undefined; /** Regular (non-sale) price */ getRegularPrice: (doc: Doc) => string | undefined; /** Sale price, if on sale */ getSalePrice: (doc: Doc) => string | undefined; /** Whether the product is currently on sale */ isOnSale: (doc: Doc) => boolean; /** Primary image URL */ getImageUrl: (doc: Doc) => string | undefined; /** All image URLs */ getImageUrls: (doc: Doc) => string[]; /** Short description / excerpt */ getDescription: (doc: Doc) => string | undefined; /** Stock status */ getStockStatus: (doc: Doc) => 'instock' | 'outofstock' | 'onbackorder' | 'unknown'; /** Stock quantity (null if not tracked) */ getStockQuantity: (doc: Doc) => number | null; /** Whether this product has variants/variations */ hasVariants: (doc: Doc) => boolean; /** Product type (simple, variable, etc. — connector-specific but useful for UI hints) */ getType: (doc: Doc) => string; /** Barcode / UPC / EAN */ getBarcode: (doc: Doc) => string | undefined; /** Categories as simple label strings */ getCategoryNames: (doc: Doc) => string[]; /** The connector-specific unique ID (as string for consistency) */ getId: (doc: Doc) => string; } /** * Customer traits — the stable interface that UI components program against. * * Each connector implements these to extract standard customer data * from its own schema shape. */ interface CustomerTraits { /** Customer display name (first + last or company) */ getName: (doc: Doc) => string; /** Email address */ getEmail: (doc: Doc) => string | undefined; /** Phone number */ getPhone: (doc: Doc) => string | undefined; /** One-line address summary (e.g., "123 Main St, Springfield") */ getAddressSummary: (doc: Doc) => string | undefined; /** The connector-specific unique ID (as string for consistency) */ getId: (doc: Doc) => string; } /** * Replication adapter interface for a single collection. * * Each connector implements this to provide pull/push handlers * compatible with RxDB's replicateRxCollection protocol. * * CheckpointType is connector-specific (cursor, offset+timestamp, etc). */ interface ReplicationAdapter { pull: { /** * Fetch documents changed since the last checkpoint. * Return an empty documents array when fully caught up. */ handler: (lastCheckpoint: CheckpointType | undefined, batchSize: number, context: SyncContext) => Promise<{ documents: Array; checkpoint: CheckpointType; }>; /** * Optional real-time event stream. * Emit { documents, checkpoint } for live updates, * or 'RESYNC' to trigger a full pull cycle. */ stream$?: Observable>; }; push?: { /** * Push local changes to the remote API. * Return an array of conflict documents (server's version wins). * Return empty array if no conflicts. */ handler: (changeRows: RxReplicationWriteToMasterRow[], context: SyncContext) => Promise>; /** Max documents per push batch. Defaults to 100. */ batchSize?: number; }; } /** * Authentication configuration for a connector. * Each API has wildly different auth — JWT, API keys, OAuth, etc. * The connector declares what it needs and how to use it. */ interface ConnectorAuth { /** Human-readable auth type for UI display */ type: string; /** Fields required from the user to authenticate */ fields: AuthField[]; /** Build request headers from stored credentials */ getHeaders: (credentials: Record) => Record; /** Optional: validate that credentials work (e.g., test API call) */ validate?: (credentials: Record) => Promise; } interface AuthField { key: string; label: string; type: 'text' | 'password' | 'url'; placeholder?: string; required?: boolean; } /** * Sync configuration for a collection. * Defines how to fetch data from the remote API and push changes back. * * @deprecated Use ReplicationAdapter instead. This interface will be removed * once all connectors have migrated to the RxDB replication protocol. */ interface CollectionSync { /** Fetch all remote IDs (for diffing against local) */ fetchAllIds: (context: SyncContext) => Promise; /** Fetch documents by IDs */ fetchByIds: (ids: string[], context: SyncContext) => Promise; /** Fetch documents modified after a given date */ fetchModifiedAfter?: (date: string, context: SyncContext) => Promise; /** Push a local change to the remote */ push?: (doc: T, context: SyncContext) => Promise; /** Create a new document on the remote */ create?: (doc: Partial, context: SyncContext) => Promise; /** Delete a document on the remote */ delete?: (id: string, context: SyncContext) => Promise; } interface RemoteIdEntry { id: string; dateModified?: string; } interface SyncContext { /** Unique connector identifier (used as replication namespace) */ connectorId: string; /** Base URL for the API */ baseUrl: string; /** Authenticated headers */ headers: Record; /** Optional abort signal */ signal?: AbortSignal; } /** * Schema definitions for a connector. * Each connector provides its own RxDB schemas that mirror its API shape. */ interface ConnectorSchemas { products: RxJsonSchema; [key: string]: RxJsonSchema; } /** * Trait implementations for a connector. * These are the accessor functions that components program against. */ interface ConnectorTraits { product: ProductTraits; customer?: CustomerTraits; } /** * The main connector interface. * Each backend (WooCommerce, Medusa, Vendure, etc.) implements this. */ interface TallyConnector { /** Unique identifier for this connector */ id: string; /** Human-readable name */ name: string; /** Description of the backend this connects to */ description: string; /** Icon or logo URL */ icon?: string; /** Authentication configuration */ auth: ConnectorAuth; /** RxDB schemas for each collection */ schemas: ConnectorSchemas; /** Trait implementations — how to extract standard data from connector-specific docs */ traits: ConnectorTraits; /** * @deprecated Use `replication` instead. * Sync configuration for each collection (legacy pull-based sync). */ sync: { products: CollectionSync; [key: string]: CollectionSync; }; /** Replication adapters for each collection (RxDB replication protocol) */ replication?: { products?: ReplicationAdapter; [key: string]: ReplicationAdapter | undefined; }; } interface ConnectorProviderProps { connector: TallyConnector; children: ReactNode; } declare function ConnectorProvider({ connector, children }: ConnectorProviderProps): react_jsx_runtime.JSX.Element; /** * Access the active connector. Throws if used outside a ConnectorProvider. */ declare function useConnector(): TallyConnector; /** * Convenience hook: grab just the product traits from the active connector. */ declare function useProductTraits(): ProductTraits; /** * Convenience hook: grab just the customer traits from the active connector. * Returns undefined if the connector doesn't implement customer traits. */ declare function useCustomerTraits(): CustomerTraits | undefined; export { type AuthField, type CollectionSync, type ConnectorAuth, ConnectorProvider, type ConnectorProviderProps, type ConnectorSchemas, type ConnectorTraits, type CustomerTraits, type ProductTraits, type RemoteIdEntry, type ReplicationAdapter, type SyncContext, type TallyConnector, useConnector, useCustomerTraits, useProductTraits };